FastPrepFirst Non-Repeating Character
Problems/First Non-Repeating Character

First Non-Repeating Character

Amazon logoAmazon● EasyNEW GRADINTERNOAONSITE INTERVIEW
QuestionExamples

Problem statement

Source note: Reported in an Amazon new-grad onsite interview as finding the first non-repeating character. The source omits whether to return a character or index and gives no absent-result, character-domain, case, or size rule; this practice version returns the character, uses the empty string when absent, compares case-sensitive printable ASCII, and limits input length to 100,000. Problem match confidence: approximately 88%.

Given a non-empty string s, return the first character whose total frequency in the string is exactly one.

The problem statement continues
Pro

Examples

Example 1

s = "swiss"return = "w"

The first s repeats, while w occurs once.

02 · Example 2
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Amazon hiring insights
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week