Uploaded Test.java with collapseDuplicates and test cases