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.

Author: BattleMage_

To answer queries for the K_ith 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: O(SN\log{N}+Q), where S is the length of the longest string.


Comments

There are no comments at the moment.