![]() |
VOOZH | about |
Given an input string and a pattern, check if characters in the input string appear in the same order as in the pattern. Assume the pattern has no duplicate characters. For Examples:
Input: s = "engineers rock", pattern = "er"
Output: true
Explanation: All 'e' in the input string are before all 'r'.
Let's explore different methods to check order of character in string using OrderedDict().
This method stores the first occurrence index of each unique character using OrderedDict and then checks whether the pattern’s characters appear in increasing index order within the string.
True
Explanation:
OrderedDict preserves the order of characters while removing duplicates. You can use it to check if the letters of a pattern appear in the correct order in a string.
True
Explanation:
In this method, characters are manually inserted into an OrderedDict while keeping their order intact. The pattern is then checked sequentially against the ordered keys to verify if its characters appear in the same order as in the string.
True
Explanation: