๐ Day 2 โ Teacher's Day Challenge | FizzBuzz Logic & Conditionals


๐๏ธ Date: July 26, 2025
๐ข Problems Solved Today: 1
๐ฏ Focus Topic: Loops, Conditional Logic, Strings
๐ป Platform: Leetcode
๐ Table of Contents
Daily Summary
๐งฉ Problem 1 โ FizzBuzz
๐ LeetCode Link โ FizzBuzz #412
๐ Difficulty: Easy
๐ง Concepts: Modulo, Conditional Logic, String Arrays
๐ Problem Statement (Summary):
Given an integer n
, return a string array (1-indexed) such that:
"FizzBuzz"
if divisible by both 3 and 5"Fizz"
if divisible by 3"Buzz"
if divisible by 5Else, the number itself as a string
๐ก Approach:
Initialize a vector of size
n
Loop from 1 to
n
Check divisibility by 3 and 5 using
%
Assign appropriate string at index
i-1
(1-indexed logic)
๐งช Code (C++):
class Solution {
public:
vector<string> fizzBuzz(int n) {
vector<string> result(n);
for (int i = 1; i <= n; i++) {
if (i % 3 == 0 && i % 5 == 0)
result[i - 1] = "FizzBuzz";
else if (i % 3 == 0)
result[i - 1] = "Fizz";
else if (i % 5 == 0)
result[i - 1] = "Buzz";
else
result[i - 1] = to_string(i);
}
return result;
}
};
๐ธ Submission Screenshot:
โ Key Takeaways:
Condition ordering matters: check for
3 & 5
first%
operator helps easily detect multiplesString conversion using
to_string()
for fallback caseIndexing starts from
i - 1
because result is 0-indexed
๐ Daily Summary
Metric | Value |
Problems Solved | 1 |
Topics Covered | Modulo, Strings, Loops |
Tools Used | C++ |
Next Focus | String Manipulation, Sliding Window |
Day | 2 / 30 |
๐ท๏ธ Tags:#leetcode
#43DaysChallenge
#fizzbuzz
#cpp
#strings
#loops
#conditionals
#dsa
Subscribe to my newsletter
Read articles from Tanishi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
