Skip to main content

← Hash maps

First letter that appears once

easy

Read a word. Print the 0-based position of the first letter that appears only once in it, or -1 if there is none.

Example 1: input

leetcode

Output

0

Example 2: input

loveleetcode

Output

2

Plus 2 hidden tests when you check your answer.

Your solution

Read from standard input and print the answer. Run it on the examples as often as you like, then check it against every test.

Stuck?

Open hints one at a time. The write-up explains a full solution.

Discussion

Ask a question or share a tip. Please don’t post full solutions. Posts appear once a moderator approves them.

No posts yet.