All problems
0315EasyArrayMath

Even-Length Part Codes

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1295Find Numbers with Even Number of Digits

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def count_even_length(codes: list[int]) -> int:
Java
public int countEvenLength(int[] codes)
September 7
Apply