incognitosj
BAN USERactually in case the integers are negative, it should use the minimum absolute value.
Eg: -10, -90, -9, -56, -32
answer should be (-9)*(-10)*(-32) and not (-90)*(-56)*(-32)
@bhupendra: One more case needs to be taken care of, where all the integers are less than 0. Then some more modification is needed.
- incognitosj July 18, 2012@bhupendra : Can you plz explain it. How will you solve it further to get the answer??
- incognitosj July 18, 20121. Sort the array
2. If minimum integers is greater than 0, product of maximum 3 integers is the answer.
3. If there exist at least 2 integers less than 0, find the product of mimimum 2 integers and 1 max integers. Compare it with the product of 3 maximum integers. Greater of the two is the answer.
Eg:
Given array : 10, 67, 28, 0, -1, -30, -20
sorted form : -30, -20. -1, 0, 10, 28, 67
product of 3 max integers : 10*28*67 = 18760
product of 2 min integers and 1 max int = (-30)*(-20)*67 = 40200
Answer : 40200
Find the lowest common ancestor for the two given numbers. After that count the number of nodes between lowest common ancestor node & a and lowest common ancestor node & b.
answer = number of nodes to reach a+ number of nodes to reach b + 2
Eg.
Suppose the tree is as given below. a= 8. b= 26.
The lowest common ancestor would be:10
- incognitosj July 26, 2012number of nodes to reach a=8 : 1
number of nodes to reach b=26 : 1
answer = 1+1 +2 = 4