Skip to content
We areTOP 1%
DSA · Beginner · Pattern 10 of 11

Math & Implementation

16 problems.
Your progress0%
1st Visit
0/16
2nd Visit
0/16
Revise
0/16

About this pattern

Implementation problems test whether you can translate a precise statement into correct code: simulate the process, handle every edge case, and choose types that do not overflow. Many also hide a short mathematical observation, such as a closed formula, a divisibility argument or a prime factorisation, that replaces a slow simulation.

Read the constraints first: values up to 10^9 or 10^18 call for long long and usually for an O(1) or O(log n) formula rather than a loop. Useful tools include integer ceiling division, modular arithmetic, digit extraction and repeatedly dividing out small prime factors. Test boundary inputs such as 1, 2 and the maximum allowed value.

// Ceiling division for positive integers, without floating point.
long long ceilDiv(long long a, long long b) { return (a + b - 1) / b; }

// Count how many times p divides n, removing those factors.
int strip(long long& n, long long p) {
    int k = 0;
    while (n % p == 0) { n /= p; ++k; }
    return k;
}

// Visit the decimal digits of x, last digit first.
for (long long t = x; t > 0; t /= 10) use(t % 10);

Problems

Math & Implementation questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1WatermelonCodeforcesEasy 800Solve Watermelon on Codeforces (opens in a new tab)
2Fizz BuzzLeetCodeEasy Solve Fizz Buzz on LeetCode (opens in a new tab)
3ElephantCodeforcesEasy 800Solve Elephant on Codeforces (opens in a new tab)
4Soldier and BananasCodeforcesEasy 800Solve Soldier and Bananas on Codeforces (opens in a new tab)
5Divisibility ProblemCodeforcesEasy 800Solve Divisibility Problem on Codeforces (opens in a new tab)
6Palindrome NumberLeetCodeEasy Solve Palindrome Number on LeetCode (opens in a new tab)
7Plus OneLeetCodeEasy Solve Plus One on LeetCode (opens in a new tab)
8Happy NumberLeetCodeEasy Solve Happy Number on LeetCode (opens in a new tab)
9Multiply by 2, divide by 6CodeforcesEasy 900Solve Multiply by 2, divide by 6 on Codeforces (opens in a new tab)
10Even OddsCodeforcesEasy 900Solve Even Odds on Codeforces (opens in a new tab)
11Odd DivisorCodeforcesEasy 900Solve Odd Divisor on Codeforces (opens in a new tab)
12Almost PrimeCodeforcesEasy 900Solve Almost Prime on Codeforces (opens in a new tab)
13Theatre SquareCodeforcesEasy 1000Solve Theatre Square on Codeforces (opens in a new tab)
14K-th Not Divisible by nCodeforcesEasy 1200Solve K-th Not Divisible by n on Codeforces (opens in a new tab)
15Count PrimesLeetCodeMedium Solve Count Primes on LeetCode (opens in a new tab)
16Next PermutationLeetCodeMedium Solve Next Permutation on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account