Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Count Distinct Digits in a Number

Basic Acceptance 91.32% Points 10.00

You are given a non-negative integer n. Your task is to return the number of distinct digits it contains.

A digit is counted only once, regardless of how many times it appears in the number.

Examples
Example 1

Input: n = 1122334
Output: 4
Explanation: The distinct digits are 1, 2, 3, and 4, so the count is 4.

Example 2

Input: n = 111
Output: 1
Explanation: Only the digit 1 is present, so the number contains one distinct digit.

Example 3

Input: n = 1234567890
Output: 10
Explanation: Every digit from 0 to 9 appears, giving a total of 10 distinct digits.

Constraints
  • 0 = n = 10¹8
Companies
Apple Samsung Flipkart
Topics
Data Structures Basics Basics
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