CS Theory
Count Primes
Find the number of prime numbers less than N where N is greater than or equal to zero. Uses the Sieve of Eratosthenes algorithm with optimization starting from i*i to avoid redundant marking.
February 5, 2026
Counting Bits Fast
Two approaches to solve the counting bits problem efficiently. The first uses pattern recognition with grouping by powers of two. The second applies dynamic programming with bit manipulation for O(n) time complexity.
February 5, 2026
Counting Non-Empty Subsequences with Repeated Characters
Given a string with repeated characters, count all possible non-empty subsequences. The solution uses backtracking to generate unique permutations by avoiding duplicate character selections through careful traversal of sorted input.
February 5, 2026
Counting Trailing Zeros in Factorials
The number of trailing zeros in n factorial equals the count of factor 5 in the numbers from 1 to n. Since factors of 2 always exceed factors of 5 we only need to count multiples of 5 recursively.
February 5, 2026
Decode Ways: From Simple to Complex
Learn how to solve the classic Decode Ways problem and its variant with wildcards. We start with basic digit-to-letter mapping and build up to handling asterisk patterns using dynamic programming.
February 5, 2026
Divisor Game Solution
A dynamic programming approach to solve the divisor game problem where players take turns choosing divisors and subtracting them from a number until no moves remain.
February 5, 2026
Fast Division Without Multiplication
How to implement integer division efficiently using bit shifting and doubling techniques. This approach avoids multiplication operations while handling edge cases like overflow and negative numbers.
February 5, 2026
Find First and Last Position of Element in Sorted Array
Binary search solution for finding the starting and ending positions of a target element in a sorted array. The key insight is how to locate both endpoints efficiently using two modified binary searches.
February 5, 2026
Find Peak Element
Two approaches to find peak element indices in arrays: linear O(N) and binary search O(logN). The binary search method uses the insight that comparing mid elements with their neighbors guides us toward a peak.
February 5, 2026
Find the Kth Largest Element in an Array
Three approaches to find the Kth largest element: sorting, quickselect with average O(n) time, and heap-based solutions for large datasets. The quickselect method partitions like quicksort but processes only one side, making it efficient for this specific problem.
February 5, 2026