Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

First Non-repeating Character (easy)
Table of Contents

Problem Statement

Try it yourself

Problem Statement

Given a string, identify the position of the first character that appears only once in the string. If no such character exists, return -1.

Examples

  1. Example 1:

    • Input: "apple"
    • Expected Output: 0
    • Justification: The first character 'a' appears only once in the string and is the first character.
  2. Example 2:

    • Input: "abcab"
    • Expected Output: 2
    • Justification: The first character that appears only once is 'c' and its position is 2.
  3. Example 3:

    • Input: "abab"
    • Expected Output: -1
    • Justification: There is no character in the string that appears only once.

Constraints:

  • 1 <= s.length <= 10<sup>5</sup>
  • s consists of only lowercase English letters.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .
Mark as Completed

Table of Contents

Problem Statement

Try it yourself