Episode 7 — DSA with JavaScript / 7.1 — Conditional Statements
7.1.a — Understanding Conditional Statements
What are conditional statements?
Conditional statements allow a program to choose different paths of execution
based on whether a condition evaluates to true or false. They are the
foundation of decision-making in every programming language.
┌──────────────┐
│ Condition? │
└──┬───────┬───┘
│ true │ false
▼ ▼
┌──────┐ ┌──────┐
│ Path │ │ Path │
│ A │ │ B │
└──────┘ └──────┘
Without conditionals a program would execute every line top-to-bottom with no branching — it could never react to user input, validate data, or handle errors.
Truthy and falsy values
Before we look at if, we must understand what JavaScript and C++ consider
"true" or "false" when a non-boolean value is tested.
JavaScript truthy / falsy
| Falsy values | Truthy (everything else) |
|---|---|
false | true |
0, -0 | any non-zero number |
0n (BigInt) | any non-zero BigInt |
"" (empty) | any non-empty string |
null | objects, arrays |
undefined | functions |
NaN | Infinity |
// Quick demo
if ("hello") console.log("truthy"); // prints
if (0) console.log("falsy"); // skipped
if ([]) console.log("truthy"); // prints — empty array is truthy!
C++ truthy / falsy
In C++ any numeric expression that is non-zero is truthy, and zero is falsy. Pointers are truthy when non-null.
#include <iostream>
using namespace std;
int main() {
int x = 42;
if (x) cout << "truthy" << endl; // prints
int* p = nullptr;
if (p) cout << "ptr truthy" << endl; // skipped
return 0;
}
The if statement
Syntax
if (condition) {
// executed when condition is truthy
}
JavaScript
function checkPositive(n) {
if (n > 0) {
console.log(`${n} is positive`);
}
}
checkPositive(5); // "5 is positive"
checkPositive(-3); // nothing printed
C++
#include <iostream>
using namespace std;
void checkPositive(int n) {
if (n > 0) {
cout << n << " is positive" << endl;
}
}
int main() {
checkPositive(5); // "5 is positive"
checkPositive(-3); // nothing printed
return 0;
}
Dry-run trace
Input: n = 5
Step 1: evaluate (5 > 0) → true
Step 2: enter block → print "5 is positive"
Input: n = -3
Step 1: evaluate (-3 > 0) → false
Step 2: skip block
The if-else statement
When the condition is false, the else block executes instead.
┌──────────────┐
│ n > 0 ? │
└──┬───────┬───┘
│ yes │ no
▼ ▼
print print
"pos" "non-pos"
JavaScript
function classifySign(n) {
if (n > 0) {
return "positive";
} else {
return "non-positive";
}
}
console.log(classifySign(10)); // "positive"
console.log(classifySign(-4)); // "non-positive"
console.log(classifySign(0)); // "non-positive"
C++
#include <iostream>
#include <string>
using namespace std;
string classifySign(int n) {
if (n > 0) {
return "positive";
} else {
return "non-positive";
}
}
int main() {
cout << classifySign(10) << endl; // "positive"
cout << classifySign(-4) << endl; // "non-positive"
cout << classifySign(0) << endl; // "non-positive"
return 0;
}
The if — else if — else ladder
When there are more than two outcomes, chain conditions with else if.
Flow diagram
┌─────────────┐
│ score >= 90? │──yes──▶ "A"
└──────┬──────┘
│ no
┌─────────────┐
│ score >= 80? │──yes──▶ "B"
└──────┬──────┘
│ no
┌─────────────┐
│ score >= 70? │──yes──▶ "C"
└──────┬──────┘
│ no
"F"
JavaScript
function grade(score) {
if (score >= 90) {
return "A";
} else if (score >= 80) {
return "B";
} else if (score >= 70) {
return "C";
} else if (score >= 60) {
return "D";
} else {
return "F";
}
}
console.log(grade(95)); // "A"
console.log(grade(82)); // "B"
console.log(grade(55)); // "F"
C++
#include <iostream>
#include <string>
using namespace std;
string grade(int score) {
if (score >= 90) return "A";
else if (score >= 80) return "B";
else if (score >= 70) return "C";
else if (score >= 60) return "D";
else return "F";
}
int main() {
cout << grade(95) << endl; // A
cout << grade(82) << endl; // B
cout << grade(55) << endl; // F
return 0;
}
Dry-run: score = 82
Step 1: (82 >= 90) → false → skip
Step 2: (82 >= 80) → true → return "B"
Key insight: Order matters. If we tested
>= 70first, a score of 82 would wrongly get "C". Always test the most restrictive condition first.
The switch statement
switch compares a single expression against many constant values. It is
cleaner than a long if-else if chain when you are matching discrete values
(not ranges).
Flow diagram
┌──────────────┐
│ expression │
└──┬──┬──┬──┬──┘
│ │ │ │
"a" "b" "c" default
│ │ │ │
▼ ▼ ▼ ▼
blk blk blk blk
JavaScript
function dayName(num) {
switch (num) {
case 1: return "Monday";
case 2: return "Tuesday";
case 3: return "Wednesday";
case 4: return "Thursday";
case 5: return "Friday";
case 6: return "Saturday";
case 7: return "Sunday";
default: return "Invalid day";
}
}
console.log(dayName(3)); // "Wednesday"
console.log(dayName(9)); // "Invalid day"
C++
#include <iostream>
#include <string>
using namespace std;
string dayName(int num) {
switch (num) {
case 1: return "Monday";
case 2: return "Tuesday";
case 3: return "Wednesday";
case 4: return "Thursday";
case 5: return "Friday";
case 6: return "Saturday";
case 7: return "Sunday";
default: return "Invalid day";
}
}
int main() {
cout << dayName(3) << endl; // Wednesday
cout << dayName(9) << endl; // Invalid day
return 0;
}
Fall-through behavior
Without break or return, execution "falls through" to the next case.
function season(month) {
switch (month) {
case 12: case 1: case 2:
return "Winter";
case 3: case 4: case 5:
return "Spring";
case 6: case 7: case 8:
return "Summer";
case 9: case 10: case 11:
return "Autumn";
default:
return "Unknown";
}
}
Ternary operator
The ternary condition ? exprTrue : exprFalse is a compact if-else for
expressions (not statements).
JavaScript
const status = age >= 18 ? "adult" : "minor";
// Nested (use sparingly)
const category =
age < 13 ? "child" :
age < 18 ? "teen" :
"adult";
C++
string status = (age >= 18) ? "adult" : "minor";
Best practice: Don't nest ternaries more than one level deep — it hurts readability. Use
if-elseinstead.
Logical operators in conditions
| Operator | JS | C++ | Meaning |
|---|---|---|---|
| AND | && | && | both must be true |
| OR | || | || | at least one true |
| NOT | ! | ! | invert |
Short-circuit evaluation
// If `user` is null, `user.name` is never evaluated → no crash
if (user && user.name) {
console.log(user.name);
}
// Same idea in C++
if (ptr && ptr->val > 0) {
cout << ptr->val << endl;
}
Combining conditions — example
function canVote(age, isCitizen) {
if (age >= 18 && isCitizen) {
return true;
}
return false;
}
bool canVote(int age, bool isCitizen) {
return age >= 18 && isCitizen;
}
Nullish coalescing and optional chaining (JS only)
These modern JS operators reduce boilerplate conditional checks.
// ?? returns right side only when left is null/undefined
const name = user.name ?? "Anonymous";
// ?. short-circuits to undefined if any link is null/undefined
const city = user?.address?.city;
// Combining both
const zip = user?.address?.zip ?? "00000";
Common pitfalls
1. Assignment instead of comparison
// BUG — assigns 5 to x, always truthy
if (x = 5) { ... }
// FIX
if (x === 5) { ... }
2. == vs === in JavaScript
0 == "" // true (type coercion)
0 === "" // false (strict — no coercion)
null == undefined // true
null === undefined // false
Rule: Always use
===and!==in JavaScript.
3. Missing break in switch
switch (x) {
case 1:
console.log("one");
// falls through!
case 2:
console.log("two");
break;
}
// If x=1, prints "one" AND "two"
4. Dangling else
if (a > 0)
if (b > 0)
cout << "both positive";
else
cout << "a is not positive"; // WRONG — this else belongs to inner if
Always use braces {} to avoid ambiguity.
Real-world applications
1. Form validation
function validateEmail(email) {
if (!email) {
return { valid: false, error: "Email is required" };
}
if (!email.includes("@")) {
return { valid: false, error: "Invalid email format" };
}
if (email.length > 254) {
return { valid: false, error: "Email too long" };
}
return { valid: true, error: null };
}
2. HTTP status handling
function handleResponse(status) {
if (status >= 200 && status < 300) {
return "Success";
} else if (status === 400) {
return "Bad Request";
} else if (status === 401) {
return "Unauthorized";
} else if (status === 404) {
return "Not Found";
} else if (status >= 500) {
return "Server Error";
} else {
return "Unknown status";
}
}
3. Interactive menu
#include <iostream>
using namespace std;
int main() {
int choice;
cout << "1. Add 2. Delete 3. View 4. Exit" << endl;
cin >> choice;
switch (choice) {
case 1: cout << "Adding..." << endl; break;
case 2: cout << "Deleting..." << endl; break;
case 3: cout << "Viewing..." << endl; break;
case 4: cout << "Goodbye!" << endl; break;
default: cout << "Invalid choice" << endl;
}
return 0;
}
Comparison: if-else vs switch vs ternary
| Feature | if-else | switch | ternary |
|---|---|---|---|
| Range checks | Yes | No | Yes |
| Multiple values | Verbose | Clean | No |
| Expressions | Statements | Statements | Expression |
| Readability | Good for 2–3 branches | Good for many discrete values | Good for simple binary |
| Fall-through | N/A | Yes (intentional or bug) | N/A |
Practice problems (basic → advanced)
Problem 1 — Absolute value
Given an integer, return its absolute value without using Math.abs.
function myAbs(n) {
if (n < 0) return -n;
return n;
}
int myAbs(int n) {
if (n < 0) return -n;
return n;
}
Problem 2 — Leap year
A year is a leap year if:
- divisible by 4 AND
- (not divisible by 100 OR divisible by 400)
Decision tree:
┌─── divisible by 400? ──yes──▶ LEAP
│ │ no
│ divisible by 100? ──yes──▶ NOT LEAP
│ │ no
divisible by 4? ───yes──┘
│ no
NOT LEAP
function isLeapYear(y) {
if ((y % 4 === 0 && y % 100 !== 0) || y % 400 === 0) {
return true;
}
return false;
}
console.log(isLeapYear(2024)); // true
console.log(isLeapYear(1900)); // false
console.log(isLeapYear(2000)); // true
bool isLeapYear(int y) {
return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
}
Problem 3 — FizzBuzz (classic)
function fizzBuzz(n) {
if (n % 15 === 0) return "FizzBuzz";
if (n % 3 === 0) return "Fizz";
if (n % 5 === 0) return "Buzz";
return String(n);
}
string fizzBuzz(int n) {
if (n % 15 == 0) return "FizzBuzz";
if (n % 3 == 0) return "Fizz";
if (n % 5 == 0) return "Buzz";
return to_string(n);
}
Problem 4 — Triangle type classifier
function triangleType(a, b, c) {
// Check valid triangle first
if (a + b <= c || a + c <= b || b + c <= a) {
return "Not a triangle";
}
if (a === b && b === c) return "Equilateral";
if (a === b || b === c || a === c) return "Isosceles";
return "Scalene";
}
string triangleType(int a, int b, int c) {
if (a + b <= c || a + c <= b || b + c <= a)
return "Not a triangle";
if (a == b && b == c) return "Equilateral";
if (a == b || b == c || a == c) return "Isosceles";
return "Scalene";
}
Problem 5 — Simple calculator with switch
function calc(a, op, b) {
switch (op) {
case "+": return a + b;
case "-": return a - b;
case "*": return a * b;
case "/":
if (b === 0) throw new Error("Division by zero");
return a / b;
default:
throw new Error(`Unknown operator: ${op}`);
}
}
double calc(double a, char op, double b) {
switch (op) {
case '+': return a + b;
case '-': return a - b;
case '*': return a * b;
case '/':
if (b == 0) throw runtime_error("Division by zero");
return a / b;
default:
throw runtime_error("Unknown operator");
}
}
Advanced: guard clauses and early returns
Instead of deep nesting, return early for invalid cases.
// BAD — deeply nested
function process(user) {
if (user) {
if (user.isActive) {
if (user.hasPermission) {
// do work
}
}
}
}
// GOOD — guard clauses
function process(user) {
if (!user) return;
if (!user.isActive) return;
if (!user.hasPermission) return;
// do work
}
Scenario bank (conditionals)
7.1-001 — Check if a number is even or odd
- Level: Beginner
- Approach: Use modulo: n % 2 === 0
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: negative numbers, zero
- JS one-liner hint:
use modulo - C++ note: Use same logic; remember
==not===.
7.1-002 — Find the maximum of two numbers
- Level: Beginner
- Approach: Single comparison: a > b ? a : b
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: equal values
- JS one-liner hint:
single comparison - C++ note: Use same logic; remember
==not===.
7.1-003 — Find the maximum of three numbers
- Level: Beginner
- Approach: Chain comparisons or use Math.max
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: all equal, two equal
- JS one-liner hint:
chain comparisons or use math.max - C++ note: Use same logic; remember
==not===.
7.1-004 — Check if a character is a vowel
- Level: Beginner
- Approach: Switch on lowercase char
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: uppercase input, non-alpha
- JS one-liner hint:
switch on lowercase char - C++ note: Use same logic; remember
==not===.
7.1-005 — Determine the quadrant of a point (x,y)
- Level: Beginner
- Approach: Check signs of x and y
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: on axis (x=0 or y=0)
- JS one-liner hint:
check signs of x and y - C++ note: Use same logic; remember
==not===.
7.1-006 — Convert temperature C to F with range check
- Level: Beginner
- Approach: Validate input then multiply 9/5 + 32
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: absolute zero, overflow
- JS one-liner hint:
validate input then multiply 9/5 + 32 - C++ note: Use same logic; remember
==not===.
7.1-007 — Check if a year is a century year
- Level: Beginner
- Approach: year % 100 === 0
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: year 0
- JS one-liner hint:
year % 100 === 0 - C++ note: Use same logic; remember
==not===.
7.1-008 — Classify BMI into categories
- Level: Beginner
- Approach: if-else-if ladder on ranges
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: negative weight/height
- JS one-liner hint:
if-else-if ladder on ranges - C++ note: Use same logic; remember
==not===.
7.1-009 — Determine ticket price by age group
- Level: Beginner
- Approach: child/adult/senior thresholds
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary ages
- JS one-liner hint:
child/adult/senior thresholds - C++ note: Use same logic; remember
==not===.
7.1-010 — Return the sign of a number (-1, 0, +1)
- Level: Beginner
- Approach: Two comparisons
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: zero, MIN_INT
- JS one-liner hint:
two comparisons - C++ note: Use same logic; remember
==not===.
7.1-011 — Check if a string is empty or whitespace
- Level: Beginner
- Approach: Trim then check length
- Time complexity: O(n)
- Space complexity: O(1)
- Edge cases: null/undefined input
- JS one-liner hint:
trim then check length - C++ note: Use same logic; remember
==not===.
7.1-012 — Validate a percentage (0-100)
- Level: Beginner
- Approach: Range check with boundaries
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: floating point, negative
- JS one-liner hint:
range check with boundaries - C++ note: Use same logic; remember
==not===.
7.1-013 — Map HTTP status code to category
- Level: Beginner
- Approach: Switch with ranges in if-else
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: non-standard codes
- JS one-liner hint:
switch with ranges in if-else - C++ note: Use same logic; remember
==not===.
7.1-014 — Determine if a number is within a range [lo, hi]
- Level: Beginner
- Approach: lo <= n && n <= hi
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: lo > hi
- JS one-liner hint:
lo <= n && n <= hi - C++ note: Use same logic; remember
==not===.
7.1-015 — Check if three sides form a valid triangle
- Level: Beginner
- Approach: Sum of any two > third
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: zero-length sides
- JS one-liner hint:
sum of any two > third - C++ note: Use same logic; remember
==not===.
7.1-016 — Determine if a point is inside a rectangle
- Level: Intermediate
- Approach: Compare x,y with rect bounds
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: on the boundary
- JS one-liner hint:
compare x,y with rect bounds - C++ note: Use same logic; remember
==not===.
7.1-017 — Convert 24h time to 12h format
- Level: Intermediate
- Approach: if h >= 12 then PM
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: midnight (0), noon (12)
- JS one-liner hint:
if h >= 12 then pm - C++ note: Use same logic; remember
==not===.
7.1-018 — Classify a character as digit/letter/special
- Level: Intermediate
- Approach: Range checks on char code
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: space, newline
- JS one-liner hint:
range checks on char code - C++ note: Use same logic; remember
==not===.
7.1-019 — Simple login: check username and password
- Level: Intermediate
- Approach: String comparison with &&
- Time complexity: O(n)
- Space complexity: O(1)
- Edge cases: case sensitivity
- JS one-liner hint:
string comparison with && - C++ note: Use same logic; remember
==not===.
7.1-020 — Rock-Paper-Scissors outcome
- Level: Intermediate
- Approach: Switch on pair of choices
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: invalid input
- JS one-liner hint:
switch on pair of choices - C++ note: Use same logic; remember
==not===.
7.1-021 — Determine tax bracket from income
- Level: Intermediate
- Approach: if-else-if ladder on thresholds
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: negative income, zero
- JS one-liner hint:
if-else-if ladder on thresholds - C++ note: Use same logic; remember
==not===.
7.1-022 — Check if a date is valid (day/month/year)
- Level: Intermediate
- Approach: Month-specific day limits + leap year
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: Feb 29, month 13
- JS one-liner hint:
month-specific day limits + leap year - C++ note: Use same logic; remember
==not===.
7.1-023 — Convert letter grade to GPA
- Level: Intermediate
- Approach: Switch A->4, B->3, etc.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: plus/minus grades
- JS one-liner hint:
switch a->4, b->3, etc. - C++ note: Use same logic; remember
==not===.
7.1-024 — Determine shipping cost by weight tiers
- Level: Intermediate
- Approach: if-else-if on weight ranges
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: zero weight, negative
- JS one-liner hint:
if-else-if on weight ranges - C++ note: Use same logic; remember
==not===.
7.1-025 — Validate a credit card number length
- Level: Intermediate
- Approach: Check length is 13, 15, or 16
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: non-digit characters
- JS one-liner hint:
check length is 13, 15, or 16 - C++ note: Use same logic; remember
==not===.
7.1-026 — Check if two rectangles overlap
- Level: Intermediate
- Approach: Negate non-overlap conditions
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: touching edges, contained
- JS one-liner hint:
negate non-overlap conditions - C++ note: Use same logic; remember
==not===.
7.1-027 — Determine day of week from number using switch
- Level: Intermediate
- Approach: 1=Mon..7=Sun
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: 0 or 8
- JS one-liner hint:
1=mon..7=sun - C++ note: Use same logic; remember
==not===.
7.1-028 — Classify angle: acute/right/obtuse/straight/reflex
- Level: Intermediate
- Approach: if-else-if on degree ranges
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: exactly 0, 180, 360
- JS one-liner hint:
if-else-if on degree ranges - C++ note: Use same logic; remember
==not===.
7.1-029 — ATM withdrawal: check balance and withdrawal limit
- Level: Intermediate
- Approach: Multiple conditions with &&
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: exact balance
- JS one-liner hint:
multiple conditions with && - C++ note: Use same logic; remember
==not===.
7.1-030 — Password strength checker
- Level: Intermediate
- Approach: Check length, has uppercase, has digit, has special
- Time complexity: O(n)
- Space complexity: O(1)
- Edge cases: empty string, unicode
- JS one-liner hint:
check length, has uppercase, has digit, has special - C++ note: Use same logic; remember
==not===.
7.1-031 — Determine electricity bill with slab rates
- Level: Intermediate
- Approach: Cumulative calculation with if-else
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: zero units, negative
- JS one-liner hint:
cumulative calculation with if-else - C++ note: Use same logic; remember
==not===.
7.1-032 — Check if three numbers are in ascending order
- Level: Intermediate
- Approach: a < b && b < c
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: equal values
- JS one-liner hint:
a < b && b < c - C++ note: Use same logic; remember
==not===.
7.1-033 — Find the middle value of three numbers
- Level: Intermediate
- Approach: Eliminate max and min
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: all equal
- JS one-liner hint:
eliminate max and min - C++ note: Use same logic; remember
==not===.
7.1-034 — Determine if a number is a power of 2
- Level: Intermediate
- Approach: n > 0 && (n & (n-1)) === 0
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: 0, negative, 1
- JS one-liner hint:
n > 0 && (n & (n-1)) === 0 - C++ note: Use same logic; remember
==not===.
7.1-035 — Validate an email (basic check)
- Level: Intermediate
- Approach: Must have @, dot after @, no spaces
- Time complexity: O(n)
- Space complexity: O(1)
- Edge cases: multiple @, empty local part
- JS one-liner hint:
must have @, dot after @, no spaces - C++ note: Use same logic; remember
==not===.
7.1-036 — Determine the season from a month number
- Level: Advanced
- Approach: Switch with grouped cases
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: southern hemisphere note
- JS one-liner hint:
switch with grouped cases - C++ note: Use same logic; remember
==not===.
7.1-037 — Check if a character is uppercase or lowercase
- Level: Advanced
- Approach: Range check A-Z vs a-z
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: non-alpha characters
- JS one-liner hint:
range check a-z vs a-z - C++ note: Use same logic; remember
==not===.
7.1-038 — Return the ordinal suffix (st, nd, rd, th)
- Level: Advanced
- Approach: Special cases for 11,12,13 then mod 10
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: negative numbers
- JS one-liner hint:
special cases for 11,12,13 then mod 10 - C++ note: Use same logic; remember
==not===.
7.1-039 — Check if a year is in the 21st century
- Level: Advanced
- Approach: year >= 2001 && year <= 2100
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: year 2000
- JS one-liner hint:
year >= 2001 && year <= 2100 - C++ note: Use same logic; remember
==not===.
7.1-040 — Determine blood group compatibility
- Level: Advanced
- Approach: Switch on donor-recipient pair
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: invalid blood group
- JS one-liner hint:
switch on donor-recipient pair - C++ note: Use same logic; remember
==not===.
7.1-041 — Calculate discount based on membership tier
- Level: Advanced
- Approach: Switch: bronze/silver/gold/platinum
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: unknown tier
- JS one-liner hint:
switch - C++ note: Use same logic; remember
==not===.
7.1-042 — Check if a number is a perfect square
- Level: Advanced
- Approach: sqrt then check floor
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: large numbers, precision
- JS one-liner hint:
sqrt then check floor - C++ note: Use same logic; remember
==not===.
7.1-043 — Validate time input (HH:MM)
- Level: Advanced
- Approach: 0<=h<=23, 0<=m<=59
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: single digit, 24:00
- JS one-liner hint:
0<=h<=23, 0<=m<=59 - C++ note: Use same logic; remember
==not===.
7.1-044 — Determine coin denomination breakdown
- Level: Advanced
- Approach: Greedy from largest
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: zero amount
- JS one-liner hint:
greedy from largest - C++ note: Use same logic; remember
==not===.
7.1-045 — Check if a string starts with a vowel
- Level: Advanced
- Approach: Switch on first char
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: empty string
- JS one-liner hint:
switch on first char - C++ note: Use same logic; remember
==not===.
7.1-046 — Map number to Roman numeral (1-10)
- Level: Advanced
- Approach: Switch or if-else chain
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: 0, negative
- JS one-liner hint:
switch or if-else chain - C++ note: Use same logic; remember
==not===.
7.1-047 — Determine the type of a JS value
- Level: Advanced
- Approach: typeof + null check
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: null gives 'object'
- JS one-liner hint:
typeof + null check - C++ note: Use same logic; remember
==not===.
7.1-048 — Check if coordinates are in unit circle
- Level: Advanced
- Approach: xx + yy <= 1
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: on boundary
- JS one-liner hint:
x*x + y*y <= 1 - C++ note: Use same logic; remember
==not===.
7.1-049 — Classify a triangle by angles
- Level: Advanced
- Approach: Check for 90, >90, <90
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: sum != 180
- JS one-liner hint:
check for 90, >90, <90 - C++ note: Use same logic; remember
==not===.
7.1-050 — Determine if a meeting time conflicts
- Level: Advanced
- Approach: !(end1 <= start2 || end2 <= start1)
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: same start
- JS one-liner hint:
!(end1 <= start2 || end2 <= start1) - C++ note: Use same logic; remember
==not===.
7.1-051 — Check divisibility by 3 and 5 simultaneously
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-052 — Return the larger of two strings by length
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-053 — Validate a hexadecimal color code
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-054 — Determine if a character is alphanumeric
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-055 — Check if a number fits in a byte (0-255)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-056 — Determine insurance premium based on age and smoker status
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-057 — Classify a pH value (acidic/neutral/basic)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-058 — Check if two circles intersect
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-059 — Validate a date range (start <= end)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-060 — Determine file type from extension using switch
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-061 — Return the number of days in a given month
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-062 — Check if a password meets complexity requirements
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-063 — Classify network latency (low/medium/high)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-064 — Determine priority queue tier from urgency level
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-065 — Validate geographic coordinates (lat/lon)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-066 — Determine if a chess move is valid for a pawn
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-067 — Check if a string is a palindrome (basic)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-068 — Classify CPU usage level (idle/normal/high/critical)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-069 — Determine if a hand in cards is a pair
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-070 — Validate IPv4 address format
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-071 — Check if a matrix position is within bounds
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-072 — Determine the zodiac sign from month and day
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-073 — Classify wind speed (calm/breeze/gale/storm)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-074 — Determine if a number is harshad (divisible by digit sum)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-075 — Validate a phone number length by country code
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-076 — Check if two ranges overlap
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-077 — Classify memory usage tier
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-078 — Determine discount eligibility based on loyalty points
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-079 — Validate a binary string (only 0s and 1s)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-080 — Check if a temperature is in danger zone for food safety
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-081 — Determine the century from a year
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-082 — Classify an HTTP method (safe/idempotent/unsafe)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-083 — Check if a Unicode code point is in BMP
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-084 — Determine the next traffic light color
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-085 — Validate student grade input (A-F only)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-086 — Classify a sound level in decibels
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-087 — Determine loan eligibility from credit score
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-088 — Check if a color is a primary RGB color
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-089 — Classify an earthquake magnitude (Richter scale)
- Level: Intermediate
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-090 — Determine platform from user agent string (basic)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-091 — Check if a number is a Fibonacci number
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-092 — Classify a drink temperature (cold/warm/hot)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-093 — Validate a currency amount (non-negative, max 2 decimals)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-094 — Determine if a packet should be filtered (firewall rule)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-095 — Check if a year has 53 ISO weeks
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-096 — Classify API response time (fast/acceptable/slow)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-097 — Determine if a chess square is black or white
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-098 — Validate a cron expression hour field
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-099 — Classify an angle in radians to quadrant
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-100 — Determine if a vehicle passes emissions test
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-101 — Check if two colors contrast enough (simplified)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-102 — Classify a battery level (critical/low/medium/full)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-103 — Determine tax filing status from inputs
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-104 — Validate an ISBN-10 check digit
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-105 — Check if a triangle is right-angled (Pythagorean)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-106 — Classify a star by temperature (spectral type)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-107 — Determine if daylight saving is active
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-108 — Validate a semantic version string format
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-109 — Check if a matrix is square
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-110 — Classify an OS from platform string
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-111 — Determine if a transaction is suspicious
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-112 — Validate a subnet mask
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-113 — Check if a year is a prime year
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-114 — Classify network packet priority
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-115 — Determine if a flight is on time, delayed, or cancelled
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-116 — Validate a URL protocol (http or https)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-117 — Check if a number is automorphic
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-118 — Classify a message as spam based on keywords
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-119 — Determine if a hand wins in simplified poker
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-120 — Validate a hex string
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-121 — Check if a point is above or below a line
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-122 — Classify a student's attendance percentage
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-123 — Determine road condition from sensor data
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-124 — Validate a MAC address format
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-125 — Check if a number is abundant, deficient, or perfect
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-126 — Classify API rate limit status
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-127 — Determine the next state in a state machine
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-128 — Validate a base64 character
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-129 — Check if coordinates are in a given timezone
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-130 — Classify a loan risk level
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-131 — Determine if an item is on sale
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-132 — Validate a username (length, chars, no spaces)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-133 — Check if a number is a narcissistic number
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-134 — Classify a review sentiment from rating
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-135 — Determine the grade from weighted scores
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-136 — Validate RGB values (0-255 each)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-137 — Check if a meeting fits in a calendar slot
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-138 — Classify a song BPM as genre hint
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-139 — Determine if an elevator should stop at a floor
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-140 — Validate a postal code format
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-141 — Check if two time intervals overlap
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-142 — Classify document size (small/medium/large)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-143 — Determine if a coupon code is valid and not expired
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-144 — Validate a date of birth (not in future)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-145 — Check if a word is a reserved keyword in JS
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-146 — Classify server health from metrics
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-147 — Determine if a pixel is transparent
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-148 — Validate a port number (1-65535)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-149 — Check if a string can be a valid variable name
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-150 — Classify an animation frame rate (choppy/smooth)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-151 — Determine if a move is legal in tic-tac-toe
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-152 — Validate a JSON key (no spaces, not empty)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-153 — Check if a temperature conversion is needed
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-154 — Classify a Wi-Fi signal strength
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-155 — Determine if a cache entry is stale
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-156 — Validate a slug (lowercase, hyphens, no spaces)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-157 — Check if a date is a weekend
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-158 — Classify a video resolution (SD/HD/FHD/4K)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-159 — Determine if a font size is accessible
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-160 — Validate a color name against a known list
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-161 — Check if two versions are compatible (semver major)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-162 — Classify an image file by extension
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-163 — Determine if a feature flag is enabled for a user
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-164 — Validate a locale string format
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-165 — Check if a number is a spy number
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-166 — Classify disk usage level
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-167 — Determine if a task is overdue
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-168 — Validate a timezone offset (-12 to +14)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-169 — Check if a string is a valid enum value
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-170 — Classify a connection type (2G/3G/4G/5G/WiFi)
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.
7.1-171 — Determine the water state from temperature
- Level: Advanced
- Approach: Apply appropriate conditional logic.
- Time complexity: O(1)
- Space complexity: O(1)
- Edge cases: boundary values, invalid input, null/undefined.
- Interview tip: State the condition clearly, handle all branches, test edge cases.