Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether All Digits Are Distinct

Basic Acceptance 79.18% Points 10.00

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 = 10¹8
Companies
Samsung J.P. Morgan DE Shaw
Topics
Data Structures Basics String Searching Algorithms
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions