CS Theory

3Sum: Finding Triplets That Sum to Zero

How to solve the classic 3Sum problem using two pointers technique. Given an array, find all unique triplets that sum to zero by sorting the array and using pointer manipulation for efficient searching.

February 5, 2026

Adding Integers Without Plus or Minus

How to add two integers without using the plus or minus operators. We explore bitwise operations that can perform addition through XOR and AND operations with bit shifting for carries.

February 5, 2026

Arithmetic Slices: From Slow to Fast Solutions

Two approaches to solve the arithmetic slices problem. The first uses slow brute force with 2D DP. The better solution uses 1D DP where dp[i] counts arithmetic subarrays ending at A[i], achieving O(n) time complexity.

February 5, 2026

Balanced Binary Tree

Check if a binary tree is balanced by ensuring the height difference between left and right subtrees never exceeds one. Two approaches: simple recursion with multiple traversals or single traversal using post-order bottom-up processing.

February 5, 2026

Binary Prefix Divisible By 5

Solve the problem of checking whether each binary prefix in an array of 0s and 1s is divisible by 5 using modular arithmetic to avoid overflow issues.

February 5, 2026

Bit Counter: Finding Single Numbers with XOR Magic

Learn how to find unique numbers in arrays using bitwise operations and XOR magic. This guide covers implementing bit counters that reset after k occurrences and solving classic single number problems efficiently.

February 5, 2026

Bitwise AND of Numbers Range

Given two integers m and n, find the bitwise AND result of all numbers in their range. The key insight is that when numbers differ, their range contains both odd and even numbers, making certain bits zero.

February 5, 2026

Candy Distribution Algorithm

A greedy algorithm solution for distributing candies to children based on their ratings. The approach ensures each child gets at least one candy while satisfying neighbor constraints through two passes.

February 5, 2026

Combination Sum Series

A deep dive into backtracking algorithms through the classic Combination Sum problems. Learn how recursive selection and backtracking work together to solve combinatorial search challenges efficiently.

February 5, 2026

Connecting Nodes at the Same Level

Two approaches to populate next pointers in binary trees connecting nodes at the same level. The first handles perfect binary trees with constant space complexity, the second works with arbitrary binary trees using helper functions to navigate sibling connections.

February 5, 2026