A facility issues every employee a numeric badge code -- a positive integer with no leading zero -- and uses those codes to log entries. For a compliance audit, the security office needs an anonymized view of the badge log: for every badge code, it deletes each digit '0' from the code's decimal representation, sliding the remaining digits together while keeping their original left-to-right order, to produce that employee's audit code. (Since a badge code never starts with '0', at least its leading digit survives, so an audit code is never empty.) Two employees whose badge codes turn into the same audit code become indistinguishable in the anonymized log, even if their original badge codes had completely different lengths. Given the badge codes of all employees who logged in during the audit window, determine how many distinct audit codes appear.
n, the number of badge codes.n space-separated integers, the badge codes.A single integer: the number of distinct audit codes produced after deleting every '0' digit from each badge code.
Example 1
Input
5 1002 100000000 12 1000200030 21
Expected
4
Explanation
Stripping every '0': 1002 -> "12"; 100000000 -> "1"; 12 -> "12" (unchanged, no zeros); 1000200030 -> "123"; 21 -> "21" (unchanged, no zeros). The audit codes are {"12", "1", "12", "123", "21"}. "1002" and "12" both produce "12", so they collapse into one; the distinct audit codes are "1", "12", "123", and "21" -- 4 in total. Note "21" and "12" are different because digit order is preserved.
Example 2
Input
3 7 70 700
Expected
1
Explanation
Stripping every '0': 7 -> "7"; 70 -> "7"; 700 -> "7". All three badge codes collapse to the single audit code "7", so the answer is 1.
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 →