A vault manufacturer prints short numeric access codes and, before shipping, runs a self-consistency audit on each one. A code of length n (digits read left to right at 0-indexed positions 0 through n-1) passes the audit if and only if, for every position i, the digit written at position i equals exactly the number of times the digit i appears anywhere in the whole code. Given one code, determine whether it passes the audit.
n decimal digit characters (leading zeros are allowed).Print YES if the code passes the audit, otherwise print NO.
0-9.Example 1
Input
2020
Expected
YES
Explanation
Position 0 holds digit 2, and the digit '0' appears exactly twice in "2020" (positions 1 and 3); position 1 holds digit 0, and digit '1' never appears; position 2 holds digit 2, and digit '2' appears exactly twice (positions 0 and 2); position 3 holds digit 0, and digit '3' never appears. Every position matches its required count, so the code passes and the answer is YES.
Example 2
Input
4321
Expected
NO
Explanation
Position 0 holds digit 4, which would require the digit '0' to appear exactly 4 times in "4321" -- but it does not appear at all. The audit already fails at the very first position, so the answer is NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →