Duplicate Diamonds
Optional NodeScenario
After getting rid of the duplicate addresses on each street in Zumbania, you notice there are tons of duplicate addresses on the avenues! Sometimes the duplicates are near each other but often they're far apart. There's rumor that the king hid diamonds by the duplicate numbers that are furthest from each other. Can you find that number on each avenue?
Challenge
You will be given a list of numbers containing duplicates. The distance between two duplicate numbers is the number of elements between them in the list. Find the pair of duplicates with the maximum distance between them and print their value.
(See the Input/Output below for examples.)
Bonus
Can you solve this challenge with only 1 loop? (But with the use of another data structure.)
Challenge
Find and print the duplicate numbers that are the furthest apart.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
Bolke
Jul 30, 1:12 PMAgain, I wish there was an answer somewhere....else, how do I learn from these exercises?
Bolke
Jul 30, 1:31 PMBut....with only one loop? I'd really like to know how to do that.
Learneroo
Jul 31, 11:06 PMActually it should have been clarified - the one loop solution uses another data structure such as a hash map.