Math & Number Theory

Integer manipulation, modular arithmetic, and number-theoretic problem solving.

11 Problems1-2 hours5 Easy5 Medium1 Hard

Overview

Math problems test working with numbers directly. Key ideas include digit manipulation, overflow detection, fast exponentiation, and cycle detection.

Complexity Summary

Time Complexity

Digit operations O(log n) · Fast power O(log n)

Space Complexity

Usually O(1)

Key Patterns & Techniques

Learn the core patterns in this topic. Each block explains when to use the pattern, the intuition behind it, and a compact code example.

1

Digit Extraction

Concept

n % 10 gets last digit, n / 10 removes it

Practice questions for this pattern
2

Overflow

Concept

check bounds before multiplying

Practice questions for this pattern
3

Fast Power

Concept

binary exponentiation O(log n)

Practice questions for this pattern
4

Cycle Detection

Concept

mathematical sequences often cycle (Happy Number)

Practice questions for this pattern
5

GCD

Concept

Euclidean algorithm: gcd(a, b) = gcd(b, a % b)

Practice questions for this pattern
6

Prime Sieve

Concept

Sieve of Eratosthenes for all primes up to n

Practice questions for this pattern
DSA Practice Online - 150+ Coding Interview Questions | LeetCode Alternative | InstaMock - AI Mock Interview