Episode 7 — DSA with JavaScript / 7.7 — Math Problems and Algorithms
7.7.a — Math Operations & Algorithms
Mathematical operations in programming
Math operations are fundamental building blocks for DSA problems. Understanding how to work with numbers efficiently is essential.
Power (Exponentiation)
Naive: O(n)
function power(base, exp) {
let result = 1;
for (let i = 0; i < exp; i++) result *= base;
return result;
}
Fast exponentiation: O(log n)
2^10 = (2^5)^2
2^5 = 2 * (2^2)^2
2^2 = (2^1)^2
2^1 = 2 * (2^0)^2
2^0 = 1
Only 4 multiplications instead of 10!
function fastPow(base, exp) {
if (exp === 0) return 1;
if (exp % 2 === 0) {
const half = fastPow(base, exp / 2);
return half * half;
}
return base * fastPow(base, exp - 1);
}
long long fastPow(long long base, int exp) {
if (exp == 0) return 1;
if (exp % 2 == 0) {
long long half = fastPow(base, exp / 2);
return half * half;
}
return base * fastPow(base, exp - 1);
}
Square root
Newton's method (Babylonian)
function sqrt(n) {
if (n < 0) return NaN;
if (n === 0) return 0;
let guess = n;
while (Math.abs(guess * guess - n) > 0.0001) {
guess = (guess + n / guess) / 2;
}
return guess;
}
Integer square root (binary search)
function intSqrt(n) {
if (n < 2) return n;
let lo = 1, hi = Math.floor(n / 2);
while (lo <= hi) {
const mid = Math.floor((lo + hi) / 2);
if (mid * mid === n) return mid;
if (mid * mid < n) { lo = mid + 1; }
else { hi = mid - 1; }
}
return hi;
}
int intSqrt(int n) {
if (n < 2) return n;
int lo = 1, hi = n / 2, ans = 0;
while (lo <= hi) {
long long mid = lo + (hi - lo) / 2;
if (mid * mid == n) return mid;
if (mid * mid < n) { ans = mid; lo = mid + 1; }
else hi = mid - 1;
}
return ans;
}
GCD — Euclidean algorithm
GCD(48, 18):
48 % 18 = 12
18 % 12 = 6
12 % 6 = 0
→ GCD = 6
Visualization:
gcd(48, 18)
→ gcd(18, 12)
→ gcd(12, 6)
→ gcd(6, 0) → return 6
function gcd(a, b) {
while (b !== 0) {
[a, b] = [b, a % b];
}
return a;
}
int gcd(int a, int b) {
while (b) { int t = b; b = a % b; a = t; }
return a;
}
Time: O(log(min(a,b)))
LCM
function lcm(a, b) {
return (a * b) / gcd(a, b);
}
Prime checking
Is 29 prime?
√29 ≈ 5.38 → check divisors 2, 3, 5
29 % 2 = 1 ✓
29 % 3 = 2 ✓
29 % 5 = 4 ✓
→ 29 is prime!
function isPrime(n) {
if (n < 2) return false;
if (n === 2) return true;
if (n % 2 === 0) return false;
for (let i = 3; i * i <= n; i += 2) {
if (n % i === 0) return false;
}
return true;
}
bool isPrime(int n) {
if (n < 2) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (int i = 3; (long long)i * i <= n; i += 2)
if (n % i == 0) return false;
return true;
}
Time: O(√n)
Sieve of Eratosthenes
Find all primes up to N.
Mark composites:
2: mark 4,6,8,10,...
3: mark 9,12,15,...
5: mark 25,30,...
...
Sieve for N=20:
[_, _, 2, 3, _, 5, _, 7, _, _, _, 11, _, 13, _, _, _, 17, _, 19, _]
function sieve(n) {
const isPrime = new Array(n + 1).fill(true);
isPrime[0] = isPrime[1] = false;
for (let i = 2; i * i <= n; i++) {
if (isPrime[i]) {
for (let j = i * i; j <= n; j += i) {
isPrime[j] = false;
}
}
}
return isPrime.reduce((acc, v, i) => v ? [...acc, i] : acc, []);
}
console.log(sieve(30));
// [2,3,5,7,11,13,17,19,23,29]
vector<int> sieve(int n) {
vector<bool> is_prime(n + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= n; i++)
if (is_prime[i])
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
vector<int> primes;
for (int i = 2; i <= n; i++)
if (is_prime[i]) primes.push_back(i);
return primes;
}
Time: O(n log log n) | Space: O(n)
Factorial, permutations, combinations
function factorial(n) {
let r = 1;
for (let i = 2; i <= n; i++) r *= i;
return r;
}
function nPr(n, r) { return factorial(n) / factorial(n - r); }
function nCr(n, r) { return factorial(n) / (factorial(r) * factorial(n - r)); }
Efficient nCr (avoid overflow)
function nCr(n, r) {
if (r > n - r) r = n - r;
let result = 1;
for (let i = 0; i < r; i++) {
result *= (n - i);
result /= (i + 1);
}
return result;
}
Armstrong numbers
A number where the sum of its digits raised to the power of the digit count equals the number itself.
153 → 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 ✓
function isArmstrong(n) {
const digits = String(n).split("").map(Number);
const power = digits.length;
const sum = digits.reduce((s, d) => s + Math.pow(d, power), 0);
return sum === n;
}
Palindrome number
function isPalindromeNum(n) {
if (n < 0) return false;
let rev = 0, orig = n;
while (n > 0) {
rev = rev * 10 + n % 10;
n = Math.floor(n / 10);
}
return rev === orig;
}
Digit manipulation
function sumOfDigits(n) {
let sum = 0;
n = Math.abs(n);
while (n > 0) { sum += n % 10; n = Math.floor(n / 10); }
return sum;
}
function countDigits(n) {
if (n === 0) return 1;
return Math.floor(Math.log10(Math.abs(n))) + 1;
}
function reverseNumber(n) {
let rev = 0, neg = n < 0;
n = Math.abs(n);
while (n > 0) { rev = rev * 10 + n % 10; n = Math.floor(n / 10); }
return neg ? -rev : rev;
}
Modular arithmetic
// (a + b) % m = ((a % m) + (b % m)) % m
// (a * b) % m = ((a % m) * (b % m)) % m
function modPow(base, exp, mod) {
let result = 1;
base %= mod;
while (exp > 0) {
if (exp % 2 === 1) result = (result * base) % mod;
exp = Math.floor(exp / 2);
base = (base * base) % mod;
}
return result;
}
long long modPow(long long base, long long exp, long long mod) {
long long result = 1;
base %= mod;
while (exp > 0) {
if (exp & 1) result = result * base % mod;
exp >>= 1;
base = base * base % mod;
}
return result;
}
Scenario bank (math)
7.7a-001 — GCD of multiple numbers (v1)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-002 — Prime factorization (v2)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-003 — Count trailing zeros in factorial (v3)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-004 — Check perfect number (v4)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-005 — Find nth Fibonacci using matrix exponentiation (v5)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-006 — Compute nCr mod p (v6)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-007 — Check if number is power of 2 (v7)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-008 — Find all divisors of N (v8)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-009 — Convert decimal to any base (v9)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-010 — Euler's totient function (v10)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-011 — Check Harshad number (v11)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-012 — Compute modular inverse (v12)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-013 — Count primes in a range (v13)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-014 — Digital root computation (v14)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-015 — Find GCD of array (v15)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-016 — Happy number check (v16)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-017 — Josephus problem (v17)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-018 — Catalan number computation (v18)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-019 — Count set bits (v19)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-020 — Find next prime after N (v20)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-021 — GCD of multiple numbers (v21)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-022 — Prime factorization (v22)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-023 — Count trailing zeros in factorial (v23)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-024 — Check perfect number (v24)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-025 — Find nth Fibonacci using matrix exponentiation (v25)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-026 — Compute nCr mod p (v26)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-027 — Check if number is power of 2 (v27)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-028 — Find all divisors of N (v28)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-029 — Convert decimal to any base (v29)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-030 — Euler's totient function (v30)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-031 — Check Harshad number (v31)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-032 — Compute modular inverse (v32)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-033 — Count primes in a range (v33)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-034 — Digital root computation (v34)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-035 — Find GCD of array (v35)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-036 — Happy number check (v36)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-037 — Josephus problem (v37)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-038 — Catalan number computation (v38)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-039 — Count set bits (v39)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-040 — Find next prime after N (v40)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-041 — GCD of multiple numbers (v41)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-042 — Prime factorization (v42)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-043 — Count trailing zeros in factorial (v43)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-044 — Check perfect number (v44)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-045 — Find nth Fibonacci using matrix exponentiation (v45)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-046 — Compute nCr mod p (v46)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-047 — Check if number is power of 2 (v47)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-048 — Find all divisors of N (v48)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-049 — Convert decimal to any base (v49)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-050 — Euler's totient function (v50)
- Level: Beginner
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-051 — Check Harshad number (v51)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-052 — Compute modular inverse (v52)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-053 — Count primes in a range (v53)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-054 — Digital root computation (v54)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-055 — Find GCD of array (v55)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-056 — Happy number check (v56)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-057 — Josephus problem (v57)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-058 — Catalan number computation (v58)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-059 — Count set bits (v59)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-060 — Find next prime after N (v60)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-061 — GCD of multiple numbers (v61)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-062 — Prime factorization (v62)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-063 — Count trailing zeros in factorial (v63)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-064 — Check perfect number (v64)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-065 — Find nth Fibonacci using matrix exponentiation (v65)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-066 — Compute nCr mod p (v66)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-067 — Check if number is power of 2 (v67)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-068 — Find all divisors of N (v68)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-069 — Convert decimal to any base (v69)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-070 — Euler's totient function (v70)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-071 — Check Harshad number (v71)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-072 — Compute modular inverse (v72)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-073 — Count primes in a range (v73)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-074 — Digital root computation (v74)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-075 — Find GCD of array (v75)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-076 — Happy number check (v76)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-077 — Josephus problem (v77)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-078 — Catalan number computation (v78)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-079 — Count set bits (v79)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-080 — Find next prime after N (v80)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-081 — GCD of multiple numbers (v81)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-082 — Prime factorization (v82)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-083 — Count trailing zeros in factorial (v83)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-084 — Check perfect number (v84)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-085 — Find nth Fibonacci using matrix exponentiation (v85)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-086 — Compute nCr mod p (v86)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-087 — Check if number is power of 2 (v87)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-088 — Find all divisors of N (v88)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-089 — Convert decimal to any base (v89)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-090 — Euler's totient function (v90)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-091 — Check Harshad number (v91)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-092 — Compute modular inverse (v92)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-093 — Count primes in a range (v93)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-094 — Digital root computation (v94)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-095 — Find GCD of array (v95)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-096 — Happy number check (v96)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-097 — Josephus problem (v97)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-098 — Catalan number computation (v98)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-099 — Count set bits (v99)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-100 — Find next prime after N (v100)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-101 — GCD of multiple numbers (v101)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-102 — Prime factorization (v102)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-103 — Count trailing zeros in factorial (v103)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-104 — Check perfect number (v104)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-105 — Find nth Fibonacci using matrix exponentiation (v105)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-106 — Compute nCr mod p (v106)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-107 — Check if number is power of 2 (v107)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-108 — Find all divisors of N (v108)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-109 — Convert decimal to any base (v109)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-110 — Euler's totient function (v110)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-111 — Check Harshad number (v111)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-112 — Compute modular inverse (v112)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-113 — Count primes in a range (v113)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-114 — Digital root computation (v114)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-115 — Find GCD of array (v115)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-116 — Happy number check (v116)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-117 — Josephus problem (v117)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-118 — Catalan number computation (v118)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-119 — Count set bits (v119)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-120 — Find next prime after N (v120)
- Level: Intermediate
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-121 — GCD of multiple numbers (v121)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-122 — Prime factorization (v122)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-123 — Count trailing zeros in factorial (v123)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-124 — Check perfect number (v124)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-125 — Find nth Fibonacci using matrix exponentiation (v125)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-126 — Compute nCr mod p (v126)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-127 — Check if number is power of 2 (v127)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-128 — Find all divisors of N (v128)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-129 — Convert decimal to any base (v129)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-130 — Euler's totient function (v130)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-131 — Check Harshad number (v131)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-132 — Compute modular inverse (v132)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-133 — Count primes in a range (v133)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-134 — Digital root computation (v134)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-135 — Find GCD of array (v135)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-136 — Happy number check (v136)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-137 — Josephus problem (v137)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-138 — Catalan number computation (v138)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-139 — Count set bits (v139)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-140 — Find next prime after N (v140)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-141 — GCD of multiple numbers (v141)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-142 — Prime factorization (v142)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-143 — Count trailing zeros in factorial (v143)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-144 — Check perfect number (v144)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-145 — Find nth Fibonacci using matrix exponentiation (v145)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-146 — Compute nCr mod p (v146)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-147 — Check if number is power of 2 (v147)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-148 — Find all divisors of N (v148)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-149 — Convert decimal to any base (v149)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-150 — Euler's totient function (v150)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-151 — Check Harshad number (v151)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-152 — Compute modular inverse (v152)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-153 — Count primes in a range (v153)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-154 — Digital root computation (v154)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-155 — Find GCD of array (v155)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-156 — Happy number check (v156)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-157 — Josephus problem (v157)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-158 — Catalan number computation (v158)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-159 — Count set bits (v159)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-160 — Find next prime after N (v160)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-161 — GCD of multiple numbers (v161)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-162 — Prime factorization (v162)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-163 — Count trailing zeros in factorial (v163)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-164 — Check perfect number (v164)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-165 — Find nth Fibonacci using matrix exponentiation (v165)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-166 — Compute nCr mod p (v166)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-167 — Check if number is power of 2 (v167)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-168 — Find all divisors of N (v168)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-169 — Convert decimal to any base (v169)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.
7.7a-170 — Euler's totient function (v170)
- Level: Advanced
- Approach: Apply appropriate technique.
- Time: Analyze.
- Space: Identify.
- Edge cases: empty, single, boundary.
- JS & C++: Both.