In a word game, lowercase letter tiles are arranged in a row. You want to take one continuous group of tiles and use its letters to form a given word.
Find the shortest continuous group containing enough letters to form the word after rearranging them.
WordTileFinder
String findShortestTileGroup(String tileRow, String targetWord)
tileRow: The letters on the tiles from left to right.targetWord: The word that must be formed.Return the shortest continuous part of tileRow containing all letters required to form targetWord.
Return an empty string if no such group exists. If multiple shortest groups exist, return the one starting at the lowest index.
tileRow.targetWord must be available in the selected group.1 ≤ tileRow.length() ≤ 100,0001 ≤ targetWord.length() ≤ 100,000tileRow and targetWord contain only lowercase English letters. findShortestTileGroup( tileRow = "xbroawdc", targetWord = "word")
Output: "roawd"
The letters in "roawd" include 'w', 'o', 'r', and 'd'. They can be rearranged to form "word".
findShortestTileGroup( tileRow = "aoboklobo", targetWord = "book")
Output: "obok"
The group contains one 'b', two 'o' letters, and one 'k'.
findShortestTileGroup( tileRow = "garden", targetWord = "green")
Output: ""
The word requires two 'e' letters, but the tile row contains only one.
findShortestTileGroup( tileRow = "cabxxabc", targetWord = "abc")
Output: "cab"
Both "cab" and "abc" are shortest valid groups. Since "cab" starts first, it is returned.