Problem · Math

FizzBuzz Problem

Learn this problem
EasyCisco logoCiscoNEW GRADOA
See Cisco hiring insights

Problem statement

When given a number N, for each integer i in the range from 1 to N inclusive, print one value per line as follows:

  • If i is a multiple of both 3 and 5, print "FizzBuzz".
  • If i is a multiple of 3 but not 5, print "Fizz".
  • If i is a multiple of 5 but not 3, print "Buzz".
  • If i is not a multiple of 3 or 5, print the value of i.
  • Write an algorithm which follows the given instructions and prints the required output.

    Problem-solving restrictions: 0 < N < 2*10^6

    Input description: The input consists of an integer - inputNum, representing the given number (N).

    Output description: Print a line-separated output based on the given instructions for each value i in the set {1, 2, ... N} in ascending order.

    Function

    fizzBuzz(inputNum: int) → String[]

    Examples

    Example 1

    inputNum = 5return = ["1", "2", "Fizz", "4", "Buzz"]
    Explanation should be very intuitive to us. Ace and Cheers~~ 🍻

    Constraints

    0 < N < 2*10^6

    More Cisco problems

    drafts saved locally
    public String[] fizzBuzz(int inputNum) {
      // write your code here
    }
    
    inputNum5
    expected["1", "2", "Fizz", "4", "Buzz"]
    checking account