FizzBuzz
Updated
Problem statement
For every whole number i from 1 to n, produce one string:
"FizzBuzz"ifiis divisible by both 3 and 5;"Fizz"ifiis divisible by 3 but not by 5;"Buzz"ifiis divisible by 5 but not by 3;- the decimal digits of
iotherwise.
Return the n strings in order, starting with the one for 1.
Function
fizzBuzz(n: int) → List<String>Examples
Example 1
n = 20return = ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz","16","17","Fizz","19","Buzz"]Nine of the twenty entries turn into words. "Fizz" sits at 3, 6, 9, 12 and 18, "Buzz" at 5, 10 and 20, and 15, which both 3 and 5 divide, gets "FizzBuzz". The other eleven entries stay as plain numbers.
Example 2
n = 4return = ["1","2","Fizz","4"]Only 3 is divisible by 3, so it is the one word. The list ends before 5, so there is no "Buzz" yet.
Example 3
n = 9return = ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz"]The list stops at 9, well before 15, the first number divisible by 15, so no "FizzBuzz" appears.
Constraints
1 <= n <= 3000
More Capital One Online Assessment questions
- Rank Football TeamsOA · Seen Oct 2026
- Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
- Arithmetic Triplets After QueriesOA · Seen Oct 2026
- Branch with the Most FilesOA · Seen Oct 2026
- Count One-Swap Number PairsOA · Seen Oct 2026
- Distinct Values on Maximum-Sum FramesOA · Seen Oct 2026
- Earliest Meeting Time for All EmployeesOA · Seen Oct 2026
- Earn the Most 🐝OA · Seen Oct 2026
- Sort Adjacent PairsOA · Seen Oct 2026
- Bouncing Diagonal WeightsOA · Seen Oct 2026
Similar questions at other companies
- Get Max DeletionsJP Morgan Chase · OAJP Morgan Chase interview questions
- FizzBuzzIndeed · OAIndeed interview questions
- Robot Path That Repeats ForeverOpenAI · OAOpenAI interview questions
- Find Last CharacterGoogle · OAGoogle interview questions
- Count Prioritized Binary-Run OperationsZipRecruiter · OAZipRecruiter interview questions
- Flip Rows and Columns, Count ZerosNutanix · OANutanix interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Add Two Integers Given as StringsJane Street · PHONE SCREENJane Street interview questions
- Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences