Find Numbers with Even Number of Digits
Real-world version: Even-Length Part CodesThe statement here is our own: the same inputs, outputs and technique.
A hardware shop stocks parts identified by positive whole-number codes, listed in codes. The stock system prints a code onto a two-column label, which only lines up when the code has an even number of digits.
Return how many of the codes in codes have an even number of digits. Codes never carry leading zeros, and the same code may appear more than once in the list, in which case each appearance counts separately.
Examples
Example 1
- Input
- codes = [7, 42, 903, 1250, 10000]
- Output
- 2
The codes have 1, 2, 3, 4 and 5 digits. Only 42 and 1250 have an even digit count.
Example 2
- Input
- codes = [9, 99, 999, 9999]
- Output
- 2
The digit counts are 1, 2, 3 and 4, so 99 and 9999 qualify.
Example 3
- Input
- codes = [100000]
- Output
- 1
The largest code the constraints allow has 6 digits, which is even.
Example 4
- Input
- codes = [42, 42, 903]
- Output
- 2
Both copies of 42 are counted, and 903 has 3 digits.
Example 5
- Input
- codes = [1]
- Output
- 0
A single-digit code has an odd digit count.
Constraints
- 1 <= codes.length <= 500
- 1 <= codes[i] <= 10^5
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def count_even_length(codes: list[int]) -> int:public int countEvenLength(int[] codes)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 5 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's