FizzBuzz | InterviewBit | LeetCode | Solution in Python3, C++
FizzBuzz is a simple Interview problem. I present the solutions in Python3 and C++. IB Problem Link. LC Problem Link.
class Solution: def fizzBuzz(self, A): ans = [] for x in range(1, A+1): temp = "" if x % 3 == 0: temp += "Fizz" if x % 5 == 0: temp += "Buzz" if not len(temp): temp = str(x) ans.append(temp) return ans
vector<string> Solution::fizzBuzz(int A) { vector <string> ans; for (int i = 1; i <= A; i++) { string temp = ""; if (i % 3 == 0) temp += "Fizz"; if (i % 5 == 0) temp += "Buzz"; if (!temp.length()) temp = to_string(i); ans.push_back(temp); } return ans; }
Recommended Posts
Gas Station | InterviewBit | Solution Explained
June 13, 2022
Majority Element | InterviewBit | Solution Explained
June 13, 2022
Please write the proof.
This solution need an amendment for 2 digit number.
Please write a Proof for this