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.
At most the dollar amount can be 10,000. And mathematically we know that it must be a sum of TWO integers.
Lets say M is "6":
1+5
2+4
3+3
4+2
1+5
It repeats, so we only need to test M/2 cases. Great! Than,
int index1 = Arrays.asList(array).indexOf(lo);
int index2 = Arrays.asList(array).indexOf(hi);
if both != -1: success.
The stupid thing is though that you have to print the lowest index first... this should have been provided.
My algorithm at most took .16 seconds.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
This is what I came up with:
At most the dollar amount can be 10,000. And mathematically we know that it must be a sum of TWO integers. Lets say M is "6": 1+5 2+4 3+3 4+2 1+5
It repeats, so we only need to test M/2 cases. Great! Than, int index1 = Arrays.asList(array).indexOf(lo); int index2 = Arrays.asList(array).indexOf(hi);
if both != -1: success.
The stupid thing is though that you have to print the lowest index first... this should have been provided.
My algorithm at most took .16 seconds.