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
★☆★ VIEW THE BLOG POST: ★☆★
I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 400+ videos.
★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★
★☆★ Send us mail at: ★☆★
Email: thecodingsimplified@gmail.com
0 Comments