Katkat

Implement two string utility functions

xAIData Engineer · Technical Screen

Last 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:

  1. number_of_character(string, char)
  • Return the number of times character char appears in string.
  • Matching should be case-sensitive.
  • Example: number_of_character("Today is Tuesday", "t") should return 2.
  1. unique_string(msg1, msg2)
  • Split each input message into words using spaces.
  • Return the words that appear in msg1 but not in msg2, followed by the words that appear in msg2 but not in msg1.
  • 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"]