First non-repeating character in a request id

Python data engineering interview problem. Difficulty: intermediate. Pattern: Hashing. About 15 minutes. Part of the Pro drill bank.

Request ids are short strings. An incident tool wants the first character that never repeats, which is a cheap fingerprint for 'this id looks unique'.

Request ids are strings, and a debugging tool wants the first character that appears only once. Return the first character of the string that appears exactly once. If every character repeats (or the string is empty), return None. Write first_unique_char(s). In 'aabbc' only c appears once, so the answer is 'c'. In 'aabb' every character repeats, so the answer is None. The starter file already has the function name and its print lines. Keep them and fill in the body.

Requirements

  • Find characters that appear exactly once.
  • Return the first one in the string order.
  • Return None if there is none.

Constraints

  • s is a string and can be empty.
  • Case matters: A and a are different.

Examples

Input: first_unique_char('aabbc') Output: 'c' This input follows the stated rules and produces this output.

Topics: lakebench, python, hash-based-problems.

More Python interview questions · All interview problems · Learn data engineering

intermediate

First non-repeating character in a request id

Interview-style drill: Return the first character in a string that does not repeat elsewhere in it.

Return the first non-repeating character in a request id.