Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/69b58ce40693f140c84c855a.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

122 lines
2.6 KiB
Markdown

---
id: 69b58ce40693f140c84c855a
title: "Challenge 241: FizzBuzz Validator"
challengeType: 29
dashedName: challenge-241
---
# --description--
Given an array of sequential integers, with multiples of 3 and 5 replaced, determine if it's a valid FizzBuzz sequence.
In a valid FizzBuzz sequence:
- Multiples of 3 are replaced with "Fizz".
- Multiples of 5 are replaced with "Buzz".
- Multiples of both 3 and 5 are replaced with "FizzBuzz".
- All other numbers remain as integers.
# --hints--
`is_fizz_buzz([1, 2, "Fizz", 4, "Buzz"])` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, "Fizz", 4, "Buzz"]), True)`)
}})
```
`is_fizz_buzz([13, 14, "FizzBuzz", 16, 17])` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([13, 14, "FizzBuzz", 16, 17]), True)`)
}})
```
`is_fizz_buzz([1, 2, "Fizz", 4, 5])` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, "Fizz", 4, 5]), False)`)
}})
```
`is_fizz_buzz(["FizzBuzz", 16, 17, "Fizz", 19, "Buzz"])` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz(["FizzBuzz", 16, 17, "Fizz", 19, "Buzz"]), True)`)
}})
```
`is_fizz_buzz([1, 2, "Fizz", "Buzz", 5])` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([1, 2, "Fizz", "Buzz", 5]), False)`)
}})
```
`is_fizz_buzz([97, 98, "Buzz", "Fizz", 101, "Fizz", 103])` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz([97, 98, "Buzz", "Fizz", 101, "Fizz", 103]), False)`)
}})
```
`is_fizz_buzz(["Fizz", "Buzz", 101, "Fizz", 103, 104, "FizzBuzz"])` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_fizz_buzz(["Fizz", "Buzz", 101, "Fizz", 103, 104, "FizzBuzz"]), True)`)
}})
```
# --seed--
## --seed-contents--
```py
def is_fizz_buzz(arr):
return arr
```
# --solutions--
```py
def is_fizz_buzz(arr):
start = None
for i, val in enumerate(arr):
if isinstance(val, int):
start = val - i
break
if start is None:
return False
for i in range(len(arr)):
n = start + i
if n % 15 == 0:
expected = "FizzBuzz"
elif n % 3 == 0:
expected = "Fizz"
elif n % 5 == 0:
expected = "Buzz"
else:
expected = n
if arr[i] != expected:
return False
return True
```