DSA Partner Challenge | Week 1: Language Basics + Maths for DSA
##notes : https://drive.google.com/file/d/1v3HDmEBw5-Mc1zVyB6-mgiBOqnMcBiTG/view?usp=sharing
Loops & Conditional Statements — keeping it light, making it stick
Conditionals decide what to do. Loops decide how many times to do it. Together they power almost every algorithm you'll ever write.
| Language | Resource |
|---|---|
| ☕ Java | Loops & Conditionals — Tutorial |
| 🐍 Python | Same concepts — find equivalent in CampusX 100 Days of Python |
| ⚙️ C++ | Same concepts — Love Babbar / Striver playlist |
if / else if / else
- Checks a boolean condition — only ONE branch runs
- Java/C++:
if (condition) {}| Python:if condition: - Common mistake:
=is assignment,==is comparison
Ternary Operator
- One-line if-else:
int max = (a > b) ? a : b; - Python:
max_val = a if a > b else b - Use for simple conditions only — don't nest ternaries
switch Statement (Java & C++)
- Cleaner than long if-else chains for exact value matching
- Always add
break— without it, execution falls through to the next case - Python has no switch — use
if-elifor a dictionary
for loop — use when you know the count
for (int i = 0; i < 5; i++) { } // Java / C++for i in range(5): # 0–4
for i in range(1, 6): # 1–5
for i in range(0, 10, 2): # 0,2,4,6,8while loop — use when you don't know the count
while (condition) { } // Java / C++while condition: # Python- Always ensure the condition eventually becomes false — or you get an infinite loop
do-while — runs body at least once, then checks condition
do { } while (condition); // Java & C++ only- Python has no do-while — simulate with
while True: ... if cond: break
break and continue
| Keyword | What it does |
|---|---|
break |
Immediately exits the loop |
continue |
Skips current iteration, goes to next |
Nested Loops
- A loop inside a loop
- Two nested loops = O(n²) — be aware of this in DSA
Solve in Java (or your language). Push solutions to your fork.
1. Area of Circle
Formula: π × r² (use Math.PI in Java)
2. Area of Triangle
Formula: ½ × base × height
3. Area of Rectangle
Formula: length × breadth
4. Area of Isosceles Triangle
Formula: ½ × base × height
5. Area of Parallelogram
Formula: base × height
6. Area of Rhombus
Formula: ½ × d1 × d2 (d1 and d2 are the diagonals)
7. Area of Equilateral Triangle
Formula: (√3 / 4) × side²
8. Perimeter of Circle (Circumference)
Formula: 2 × π × r
9. Perimeter of Equilateral Triangle
Formula: 3 × side
10. Perimeter of Parallelogram
Formula: 2 × (a + b) (a and b are adjacent sides)
💡 For all questions: take input from the user, calculate, and print the result rounded to 2 decimal places.
- I understand how if / else if / else flows
- I know the difference between
=and== - I can write a ternary operator
- I know when to use switch vs if-else
- I know the for loop structure: init ; condition ; update
- I understand while vs do-while
- I know what
breakandcontinuedo - Solved at least 6 of the 10 practice questions
Stuck on any formula or syntax? Drop it in the community.
Solved all 10? Drop a 🔥 in the community.
Next up → Day 4: Functions, Methods & Introduction to Recursion