Problem solving question : find the min distance between the duplicate element present in the array.
Anonymous
I told the answer that i will be using a set to store the elements of an array one by one as set contains unique element and when i will do set.add(element) if it returns false it means i found the duplicate element Now inorder to find the distance between both i should have a map with key as element and value will be index so once the duplicate element is found i will do map.get(element) and then from the current index i will subtract the previous index which will be the distance between two duplicate elements.
Check out your Company Bowl for anonymous work chats.