Editorial for LCC '21 Contest 1 J2 - Spooky Words
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
To answer queries for the th shortest word easily, we will sort the array and then use it as a lookup table.
For this problem, the lengths of the strings must be prioritized over their lexicographical ordering. In most languages, we can achieve this by implementing a custom comparator function for sorting the array.
Alternatively, if the sorting algorithm is stable, we can just sort the strings twice: first in lexicographical order and then by length. This will guarantee that strings with the same length are sorted lexicographically.
Time Complexity: , where is the length of the longest string.
Comments