You are given two string lists: wordsContainer and wordsQuery.
For every word in wordsQuery, we need to find one word from wordsContainer that matches the longest suffix of the query word.
If multiple words share the same longest matching suffix:
Choose the word that has the shortest length.
If still tied, choose the one that appears earliest in wordsContainer.
Return an array where each element is the index of the selected word from wordsContainer.
Input: wordsContainer = ["king", "ring", "bring", "sing"] wordsQuery = ["ing", "zing", "ring"]
Output: [1,1,1]
Explanation:
All words end with "ing", smallest length among matching is "ring" at index 1.
Input: wordsContainer = ["hello", "cello", "yellow"] wordsQuery = ["llo", "ello"]
Output: [0,1]
Explanation:
• For "llo": all match, smallest length is "hello" → index 0. • For "ello": matches "hello" and "cello", shortest is "cello" → index 1.
Accepted:
Submission: