We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Step I. get the 3 array and reverse them, create a new array out of an existing array with each element is sum of all the previous elements.
eg: [3,2,1,1,1] -> [1,1,1,2,3] -> [1,2,3,5,8]
So the 3 new array formed would be
[1,2,3,5,8]
[2,5,9]
[1,5,6,7]
Step II. Again reverse the array
[8,5,3,2,1]
[9,5,2]
[7,6,5,1]
Step III. Take the smallest array i.e. [9,5,2]
traverse the smallest array and search element in the other 2 array - if the element is existing in other 2 array, STOP there and return the number.
Eg. Here I start with elem - 9 : Which is not existing in other 2 array.
Next I start with elem - 5 : it is existing in other 2 array.
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
How about this logic:
Step I. get the 3 array and reverse them, create a new array out of an existing array with each element is sum of all the previous elements. eg: [3,2,1,1,1] -> [1,1,1,2,3] -> [1,2,3,5,8]
So the 3 new array formed would be [1,2,3,5,8] [2,5,9] [1,5,6,7]
Step II. Again reverse the array [8,5,3,2,1] [9,5,2] [7,6,5,1]
Step III. Take the smallest array i.e. [9,5,2] traverse the smallest array and search element in the other 2 array - if the element is existing in other 2 array, STOP there and return the number.
Eg. Here I start with elem - 9 : Which is not existing in other 2 array. Next I start with elem - 5 : it is existing in other 2 array.
Wolla! 5 is my NUMBER!