FizzBuzz Problem
Updated
Problem statement
Given an integer inputNum, return a list of strings answer with one entry for each integer i from 1 to inputNum, in increasing order (answer[i - 1] describes i):
"FizzBuzz"ifiis a multiple of both 3 and 5."Fizz"ifiis a multiple of 3 but not 5."Buzz"ifiis a multiple of 5 but not 3.- Otherwise,
iwritten as a decimal string.
Function
fizzBuzz(inputNum: int) → List<String>Examples
Example 1
inputNum = 5return = ["1", "2", "Fizz", "4", "Buzz"]1, 2 and 4 are not multiples of 3 or 5, so they stay as numbers. 3 is a multiple of 3, so it becomes "Fizz". 5 is a multiple of 5, so it becomes "Buzz".
Example 2
inputNum = 15return = ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]Multiples of 3 (3, 6, 9, 12) become "Fizz", multiples of 5 (5, 10) become "Buzz", and 15 is a multiple of both, so it becomes "FizzBuzz".
Constraints
1 <= inputNum <= 4000
More Cisco interview questions
- Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
- Find Unique ElementsPHONE SCREEN · Seen Nov 2026
- First Letter to Appear TwicePHONE SCREEN · Seen Nov 2026
- Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a StringPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
- Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
- Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- Costliest ChocolateRippling · OARippling interview questions
- Distinct Chapters Missed During a Cyclic AbsenceVisa · OAVisa interview questions
- Count Palindromic Base RepresentationsSEDEMAC · OA
- Reduce a Number to One DigitAccenture · OAAccenture interview questions
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Calculate the Half SpreadMillennium · OAMillennium interview questions
- Plus Mult ArrayIBM · OAIBM interview questions
- Product Minus Sum of DigitsTikTok · OATikTok interview questions