I won’t insist on relative ordering among the shortest.
Idea 1() — Start with longest abbreviation i.e. the original string S, assuming 5 characters.
- populate the smallHM with the original word
- copy every char except the first. save into bigHM, then print/process this abbrevation.
- copy every char except the 2nd and print
- copy every char except the last. Now we have 5 strings in bigHM (a Level-4 hashmap), each length S-1=4
- make smallHM point to bigHM object; point bigHM to an empty hm
- now take a string from smallHM (Level-4 collection) and generate 4 shorter strings and save them in bigHM (a Level-3 collection), each length S-2=3
- now take 2nd string from Level-4 …
- After we finish Level-4, we have generated 20 strings in Level-3, but there are only 10 distinct items! so we need a L3 hashmap.