Trains the technique from
LeetCode 3093Longest Common Suffix QueriesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A catalogue is given as wordsContainer and a list of lookups as wordsQuery, both lists of lowercase words.
For each lookup, find the catalogue entry sharing the longest ending with it, where an ending means a run of characters at the very end of both words; sharing no ending at all counts as a shared ending of length zero. Break a tie on that length by taking the shorter catalogue entry, and break a remaining tie by taking the one listed earliest.
Return the position in the catalogue of the entry chosen for each lookup, in the order the lookups are given.
Example 1
The lookup "slate" shares the ending "late" with both "plate" and "late", and the shorter of those wins. The lookup "ornate" shares only "ate", which the same three entries offer, so the shortest one wins again. The lookup "crate" shares all five characters with the entry at position 0.
Example 2
The lookup "dd" shares no ending with anything, so the tie-break falls back to the shortest entry and then the earliest, giving position 0. The lookup "aa" matches the entry at position 0 outright.
Example 3
All three entries share the whole word and are the same length, so the earliest one is chosen.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def string_indices(wordsContainer: list[str], wordsQuery: list[str]) -> list[int]:public int[] stringIndices(String[] wordsContainer, String[] wordsQuery)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.