Topics/DSA & Algorithms

DSA & Algorithms

248 articles

Algorithm Paradigms & Problem-Solving Patterns

Algorithmic patterns are reusable problem-solving blueprints. Mastering fundamental paradigms allows you to systematically decompose complex engineering problems.

Level: Intermediate to Advanced
9 Core Subtopics

Track Curriculum

Subtopics & Modules

9 Modules Available
Module 01
3 Q&A
Beginner

Two Pointers Technique

Opposite direction pointers, fast & slow pointers, 3Sum, and palindrome validation.

15 min readStart Guide
Module 02
3 Q&A
Intermediate

Sliding Window Pattern

Fixed vs variable length windows, maximum subarray sum, and longest substring problems.

18 min readStart Guide
Module 03
3 Q&A
Advanced

Dynamic Programming

Memoization (top-down), tabulation (bottom-up), knapsack variations, and state transitions.

35 min readStart Guide
Module 04
3 Q&A
Intermediate

Greedy Algorithms

Local optimal choice, activity selection, Huffman coding, and fractional knapsack.

20 min readStart Guide
Module 05
3 Q&A
Advanced

Backtracking & Recursion

State space trees, N-Queens, Sudoku solver, subsets, permutations, and pruning.

28 min readStart Guide
Module 06
3 Q&A
Beginner

Sorting & Searching Algorithms

QuickSort, MergeSort, HeapSort, Counting Sort, and Binary Search variants.

24 min readStart Guide
Module 07
3 Q&A
Intermediate

Binary Search & Search Spaces

Binary search on answers, lower/upper bounds, rotated sorted arrays, and search space reduction.

22 min readStart Guide
Module 08
3 Q&A
Intermediate

Bit Manipulation

AND, OR, XOR, NOT operations, bitwise masks, Single Number problem, and power of two checks.

18 min readStart Guide
Module 09
3 Q&A
Advanced

Advanced Graph Algorithms

Dijkstra's shortest path, Bellman-Ford, Kruskal's & Prim's MST, and Floyd-Warshall.

32 min readStart Guide
Track Question Bank
27 Questions Across Modules

Interview Questions by Module Topic

Select a module to view its related questions, or explore all modules organized by seniority level

Filter by Module Topic:
01
Module Topic•3 Questions under this topic

Two Pointers Technique

Full Guide & Mechanics

How does the Two Pointers technique solve Two-Sum on a sorted array in O(n) time and O(1) space, and why does it strictly require sorted input?

In-Depth Technical Answer

On an unsorted array, finding two numbers that sum to target requires either nested loops ($O(n^2)$) or a hash set ($O(n)$ space). However, if the array is **already sorted**, the **Two Pointers Converging Pattern** solves the problem in strict **O(n) time and O(1) auxiliary space**: 1. Initialize `left = 0` (smallest element) and `right = n - 1` (largest element). 2. Calculate current sum: `currentSum = arr[left] + arr[right]`. 3. **Decision Logic**: - If `currentSum == target`: Solution found! - If `currentSum < target`: The sum is too small. Because `arr` is sorted, incrementing `left` (`left++`) increases the sum towards the target. - If `currentSum > target`: The sum is too large. Decrementing `right` (`right--`) decreases the sum towards the target. Because the pointers only move toward each other, each step eliminates an entire row or column of potential pairs without inspection, inspecting at most N elements total.

Practical Code Exampletwo_sum_sorted.ts
TypeScript
export function twoSumSorted(numbers: number[], target: number): [number, number] | null {
  let left = 0;
  let right = numbers.length - 1;

  while (left < right) {
    const sum = numbers[left] + numbers[right];
    if (sum === target) {
      return [left + 1, right + 1]; // 1-indexed return
    } else if (sum < target) {
      left++;
    } else {
      right--;
    }
  }
  return null;
}

🔍 Code Mechanics (TypeScript): Monotonicity allows the algorithm to safely discard half of remaining search candidates on every single comparison.

Senior Architectural TakeawayTwo-pointer convergence eliminates one search boundary on every comparison, reducing sorted search pairs from O(n²) to linear O(n) time with O(1) space.

How do you solve the 3Sum problem in O(n²) time while strictly eliminating duplicate triplets without allocating a Hash Set?

How does the 'Trapping Rain Water' two-pointer algorithm achieve O(n) time and O(1) space by tracking max-left and max-right boundaries simultaneously?

02
Module Topic•3 Questions under this topic

Sliding Window Pattern

Full Guide & Mechanics

What is the operational difference between a Fixed-Size Window and a Variable-Size Dynamic Window, and why does Sliding Window transform O(k · n) loops into O(n)?

How do you solve 'Minimum Window Substring' (Hard) in O(n) time using an expansion/contraction sliding window and frequency map?

How do you implement the 'Sliding Window Maximum' algorithm in strict O(n) time using a Monotonic Double-Ended Queue (Deque)?

03
Module Topic•3 Questions under this topic

Dynamic Programming

Full Guide & Mechanics

What are Overlapping Subproblems and Optimal Substructure, and what are the practical trade-offs between Top-Down Memoization and Bottom-Up Tabulation?

How do you solve the 0/1 Knapsack problem versus the Unbounded Coin Change problem, and how do you optimize the DP table from 2D O(N·W) down to 1D O(W) space?

How do you solve the Longest Increasing Subsequence (LIS) problem in O(n log n) time using Patience Sorting and Binary Search instead of standard O(n²) DP?

04
Module Topic•3 Questions under this topic

Greedy Algorithms

Full Guide & Mechanics

What is the Greedy Choice Property, and why does the Greedy heuristic fail for 0/1 Knapsack while working perfectly for Fractional Knapsack?

Why must intervals be sorted by Finish Time rather than Start Time or Duration in the Interval Scheduling Maximization problem?

How does Huffman Coding construct an optimal prefix-free binary encoding tree in O(n log n) time using a Min-Heap, and how does it guarantee zero ambiguity?

05
Module Topic•3 Questions under this topic

Backtracking & Recursion

Full Guide & Mechanics

What is the universal 'Choose -> Explore -> Unchoose' Backtracking template, and how does backtracking differ from simple brute-force recursion?

How do you solve the N-Queens problem with recursive backtracking, and how do you optimize diagonal conflict checks in O(1) time using bitwise masks?

How do you implement a high-performance Sudoku Solver using Constraint Satisfaction (CSP) and the Minimum Remaining Values (MRV) heuristic to solve hard grids in under 10ms?

06
Module Topic•3 Questions under this topic

Sorting & Searching Algorithms

Full Guide & Mechanics

What is the difference between a Stable and an Unstable sorting algorithm, and why does MergeSort guarantee stability while standard QuickSort does not?

Why does standard QuickSort degrade to O(n²) on already-sorted arrays or arrays with many duplicate keys, and how does Dijkstra's 3-Way Partitioning fix this?

How does TimSort (the standard sort in Python, Java, and V8) achieve O(n) best-case and O(n log n) worst-case performance by detecting natural runs?

07
Module Topic•3 Questions under this topic

Binary Search & Search Spaces

Full Guide & Mechanics

Why is mid = low + (high - low) / 2 mathematically preferred over mid = (low + high) / 2, and what integer overflow disaster does it prevent?

How do you search for a target value in a Rotated Sorted Array in O(log n) time by determining which half is strictly sorted on each iteration?

How do you solve 'Binary Search on the Answer Space' (e.g. Koko Eating Bananas, Capacity to Ship Packages) by evaluating monotonic feasibility functions in O(n log(max - min)) time?

08
Module Topic•3 Questions under this topic

Bit Manipulation

Full Guide & Mechanics

What are the core algebraic properties of the XOR (^) operator, and how does it find the single unique number in an array where every other element appears twice in O(n) time and O(1) space?

Why does Brian Kernighan's algorithm (n & (n - 1)) clear the lowest set bit in an integer, and how does it count set bits (Hamming Weight) in O(k) time where k is the number of 1-bits?

How do you generate all Subsets (the Power Set) of an array in O(n · 2ⁿ) time using Bitwise Integer Masks from 0 to 2ⁿ - 1 with zero recursion or call-stack overhead?

09
Module Topic•3 Questions under this topic

Advanced Graph Algorithms

Full Guide & Mechanics

Why does Breadth-First Search (BFS) guarantee the shortest path in an unweighted graph, whereas Depth-First Search (DFS) does not?

How does Dijkstra's algorithm find the single-source shortest path using a min-heap, and why does it fail on graphs with negative edge weights?

How does the Bellman-Ford algorithm detect negative weight cycles in distributed routing and currency arbitrage, and how does SPFA optimize it?