Entrata India interview question

Write a Java program to read 10 records in the format roll-score, store only the highest score for each roll number using a HashMap, and print the records sorted in descending order of score.

Interview Answer

Anonymous

1 Jul 2026

I used Java HashMap to store the highest score for each roll number. Then I converted the HashMap entries into an ArrayList, sorted them in descending order using Collections.sort() with a custom comparator, and printed the final output.