Fizz and Buzz Words From 1 to n
Updated
Problem statement
You are given a whole number n. Write one word for each number from 1 up to n, in order:
- A number that is a multiple of both 3 and 5 becomes
"FizzBuzz". - A number that is a multiple of 3 but not 5 becomes
"Fizz". - A number that is a multiple of 5 but not 3 becomes
"Buzz". - Any other number is written as its decimal digits, so 11 becomes
"11".
Return the n words as an array of strings. The first word is for 1.
Function
fizzBuzzWords(n: int) → String[]Examples
Example 1
n = 6return = ["1","2","Fizz","4","Buzz","Fizz"]1, 2 and 4 are written as numbers. 3 and 6 are multiples of 3, so they become "Fizz". 5 is a multiple of 5, so it becomes "Buzz".
Example 2
n = 15return = ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]3, 6, 9 and 12 become "Fizz", and 5 and 10 become "Buzz". 15 is a multiple of both 3 and 5, so it becomes "FizzBuzz". Every other number is written as itself.
Example 3
n = 2return = ["1","2"]Neither 1 nor 2 is a multiple of 3 or 5, so both are written as numbers.
Constraints
1 <= n <= 1500
More DocuSign Phone Screen questions
- Symmetric Binary TreePHONE SCREEN · Seen Oct 2026
- Union Area of Two RectanglesPHONE SCREEN · Seen Oct 2026
- Execute Cursor-Based Text Editor OperationsPHONE SCREEN · Seen Sep 2026
- Minimize Array Sum After K Halving OperationsPHONE SCREEN · Seen Sep 2026
- Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Rain Kept Between WallsPHONE SCREEN · Seen Mar 2026
- Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Rebuild a Trip From Flight TicketsPHONE SCREEN · Seen Apr 2019
- Find the Words for Each PrefixPHONE SCREEN · Seen Sep 2018
Similar questions at other companies
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Fizz BuzzBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Double-Base PalindromesxAI · PHONE SCREENxAI interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Per-Segment SpeedingOnePay · PHONE SCREENOnePay interview questions
- Add Decimal Strings ExactlyMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Format a Centered Pagination BarMixpanel · PHONE SCREENMixpanel interview questions
- Get Max DeletionsJP Morgan Chase · OAJP Morgan Chase interview questions
- Add Two Numeric Strings with CarryZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions