Array - 25: Find max multiplication of any two numbers in array

Опубликовано: 28 Сентябрь 2024
на канале: Coding Simplified
5,392
72

Source Code:https://thecodingsimplified.com/get-t...
Solution - 1: Using two for loop
- initialize a max variable
- check with every number with other number if multiplication of two number is greater than max

Time Complexity: O(n^2)
Space Complexity: O(1)

Solution - 2: Using Sorting
- Sort the array
- Now multiply starting two numbers & last two numbers & whichever is maximum, return that number

Time Complexity: O(nlog(n))
Space Complexity: O(1)

Solution - 3: Using one loop
- We initialize smallest, secondSmallest, greatest & secondGreatest
- Now we iterate on loop & keep on updating above value as per current value
- Multiple smallest * secondSmallest, greatest * secondGreatest
- Whichever is maximum, return that

Time Complexity: O(n)
Space Complexity: O(1)

Do Watch video for more info

CHECK OUT CODING SIMPLIFIED
   / codingsimplified  

★☆★ VIEW THE BLOG POST: ★☆★
http://thecodingsimplified.com

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 400+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★
https://www.youtube.com/codingsimplif...

★☆★ Send us mail at: ★☆★
Email: [email protected]