Skip to content

Instantly share code, notes, and snippets.

@nara-l
Created May 7, 2026 00:24
Show Gist options
  • Select an option

  • Save nara-l/236bdd6628a1abac25a90473880c422a to your computer and use it in GitHub Desktop.

Select an option

Save nara-l/236bdd6628a1abac25a90473880c422a to your computer and use it in GitHub Desktop.
Odd zero counter practice

Odd Zero Pattern

Pattern: digit/string scan

Move: Convert number to string → count "0" → if count is odd, increment answer.

Mistake to avoid: Do not overthink. This is just scan/count/rule.

Code

def odd_zero_counter(input_array):    
  count = 0    
  for num in input_array:        
      odd_zero = str(num).count("0")        
      if odd_zero % 2 == 1:            
      count += 1    
return count

input_array = [20, 11, 10, 10070, 7]
odd_zero = odd_zero_counter(input_array)
print(f"odd zero count: {odd_zero}")

Expected Output
odd zero count: 3
Pattern
Digit/string scan:

Convert each number to a string.

Count "0".

If the zero count is odd, increment the result.

Tests: [20, 11, 10, 10070, 7] -> 3 [100, 5, 70] -> 1 [] -> 0

Image: odd_zero_cheatsheet for memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment