Check if Number Has Equal Digit Count and Digit Value

You are given a 0-indexed string num of length n consisting of digits.

Return true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false.

Example 1
Inputnum = "1210"
Outputtrue
The digit 0 occurs once, 1 occurs twice, 2 occurs once, and 3 occurs zero times, matching each corresponding character in num.
Example 2
Inputnum = "030"
Outputfalse
The indices 0 and 1 both violate the condition, so return false.

Constraints

  • n == num.length
  • 1 <= n <= 10
  • num consists of digits.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate