Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Check if all characters in a string are unique

Determine whether a string contains all unique characters using frequency checking.

Python practice8 minStrings – Sliding Window & FrequencyBeginnerLast updated March 25, 2026

Problem statement

Given a string s, return True if all characters in s are unique (no repeats), otherwise return False. An empty string should be considered to have all unique characters (return True).

Task

Return True if every character in the input string appears only once; otherwise return False. Aim for O(n) time and O(1) extra space (character set dependent).

Examples

All unique

Input

s = "abcdef"

Output

True

No character repeats in the string.

Input format

Function all_unique(s: str) -> bool

Output format

Return True if all characters are unique, otherwise False.

Constraints

0 <= len(s) <= 10^5. Use O(n) time.

Samples

Sample 1

Input

s = "aabc"

Output

False

'a' appears more than once.