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.
How are duplicates not a concern? If you have an array of [1, 2, 5, 2] and the sum is 4, then answer answer indexes are 1 and 4. When you search for the elements, you will always find the first element, and end up returning 1 and 1 instead. In otherwords, the index of the first occurence of one of the answers.
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 →
How are duplicates not a concern? If you have an array of
[1, 2, 5, 2]
and the sum is 4, then answer answer indexes are1
and 4. When you search for the elements, you will always find the first element, and end up returning1
and1
instead. In otherwords, the index of the first occurence of one of the answers.