Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether All Digits Are Distinct

Basic Acceptance 79.18% Points 10

You are given a non-negative integer n. Your task is to determine whether all its digits are distinct.

If every digit appears exactly once, return Yes. If any digit appears more than once, return No.

Examples
Example 1

Input: n = 1234
Output: Yes
Explanation: Every digit appears exactly once, so all digits are distinct.

Example 2

Input: n = 1223
Output: No
Explanation: The digit 2 appears twice, so the digits are not all distinct.

Example 3

Input: n = 7
Output: Yes
Explanation: A single-digit number has no repeated digits, so all its digits are distinct.

Constraints
  • 0 <= n <= 1018
Topics
Data Structures Basics String Searching Algorithms
Companies
Samsung J.P. Morgan DE Shaw
Added 31 Oct 2026 79.18% acceptance
Ln 1, Col 1Sign in to save your code
Sample inputs for this problem are shown in the examples.