Loading CodePulse
CodePulse
Home
Today
Courses
Projects
Practice
Roadmaps
Search...
⌘K
47 lessons
Sign In
Problems
0/5
Playground
3 tasks
MCQ Drill
0/4
All
Easy
Medium
Hard
1.
FizzBuzz
Easy
· Loops
2.
Reverse a String
Easy
· Strings
3.
Two Sum
Medium
· Arrays
4.
Valid Parentheses
Medium
· Stacks
5.
Maximum Subarray
Hard
· Dynamic Programming
0 / 5 solved
Description
Solution
FizzBuzz
Easy
Loops
2 seconds
Read an integer n and print the values from 1 through n on one line. Replace multiples of 3 with Fizz, multiples of 5 with Buzz, and multiples of both with FizzBuzz. Separate values with one space.
Examples
Input:
15
Output:
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
Input:
5
Output:
1 2 Fizz 4 Buzz
Constraints
•
1 <= n <= 10000
•
Print no leading or trailing spaces
loops
conditionals
math
Java
Python
JavaScript
TypeScript
C++
Editor
Console ▲
Reset
Run Code
Submit