Loading...
Loading...
Loading...
A product code is a string of letters. Find the first character in it that appears exactly once, and print it. If every character repeats, print NONE.
NONE.Example 1
Input
swiss
Output
w
s appears 3 times; w appears once and comes first among the single ones.
Example 2
Input
aabbcc
Output
NONE
Every character repeats.
Try the problem first. Open one hint at a time.
Pass 1: count every character. Pass 2: walk the string again and stop at the first character whose count is 1.
A LinkedHashMap keeps the characters in order of first appearance, so the first entry with count 1 is the answer.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor