Implement two string utility functions
xAIData Engineer · Technical ScreenLast updated
This question evaluates proficiency in string manipulation and text processing, including character counting, tokenization by spaces, case-sensitive comparisons, and preserving original word order.
Implement the following Python functions:
number_of_character(string, char)
- Return the number of times character
charappears instring. - Matching should be case-sensitive.
- Example:
number_of_character("Today is Tuesday", "t")should return2.
unique_string(msg1, msg2)
- Split each input message into words using spaces.
- Return the words that appear in
msg1but not inmsg2, followed by the words that appear inmsg2but not inmsg1. - Preserve original order.
- Use case-sensitive comparison.
- Example:
msg1 = "This is the first message"msg2 = "Hello this is the second message"- Output:
["This", "first", "Hello", "this", "second"]
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.