I was asked this question by Google for SWE inteview.
Part 1:
Input string can contain some repeated characters, for example 'helllooo'
If a string has three or more continuous repeated characters, then that means its has an extension. Return the start and end of all such extensions in a string.
Example:
String: 'helllooo'
Output: I created a class and returned list of that class.
class Extension {
int start;
int end;
}so output is: List of Extension class and empty/null if there are no extensions.
Part 2:
Using the input string, output of the first part and a dictionary of valid words, return if the input word can be converted to one of the valid words by removing some extensions (cannot delete the char).
Example:
Input: 'helllooo'
Dictionary: {'hello', 'car', 'bat' }
Since we can convert the word: 'helllooo' by removing 1 extension of 'l' and 2 extension of 'o' to 'hello', so return true.
Note: it was given that any valid word will not have 3 or more repeated chars.
I was able to code the part 1 and discuss some approaches for solving part 2 but couldnt finish the code.
Can anyone suggest good approach to solve part 2 ?