I think there should be mention of TreeMap as an alternative solution to solve this problem. It is much simpler to implement and has same time/space complexity.
Type your question above this line.
Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/5028748841713664