Company-problems

25 articles

dsa6 min read

Alien Dictionary — Google Topological Sort Interview Question

LeetCode 269 Alien Dictionary is a Google premium classic that derives a character ordering from a sorted word list. We model it as a directed graph and run Kahn topological sort BFS to detect cycles and emit a valid order in O(C) time.

Read →
dsa6 min read

Amazon — Number of Islands II (Dynamic Union-Find)

Count the number of islands after each addLand operation using incremental Union-Find with path compression. Amazon tests this to evaluate dynamic graph connectivity and disjoint set data structures.

Read →
dsa5 min read

Amazon — Task Scheduler (Greedy + Frequency Heap)

Find the minimum CPU intervals to finish all tasks with a cooldown constraint. Amazon tests this greedy heap problem to evaluate CPU scheduling knowledge and frequency-based optimization.

Read →
dsa5 min read

Amazon — Merge K Sorted Lists (Min-Heap)

Merge k sorted linked lists into one sorted list using a min-heap for O(N log k) efficiency. Amazon uses this to test heap-based k-way merge, a critical pattern in distributed data systems.

Read →
dsa6 min read

Google — Count Inversions (Modified Merge Sort)

Count the number of inversions in an array using a modified merge sort that counts cross-inversions during the merge step. Google tests this to evaluate divide-and-conquer mastery and algorithmic optimization under O(N log N) constraints.

Read →
dsa5 min read

Meta — Subarray Sum Equals K (Prefix Sum + HashMap)

Count contiguous subarrays whose elements sum to k using prefix sums and a frequency hashmap. Meta asks this to test prefix sum mastery and O(N) optimization over brute-force O(N^2) solutions.

Read →
dsa5 min read

Amazon — Top K Frequent Elements (Bucket Sort or Heap)

Find the k most frequent elements in an array using a min-heap or bucket sort. Amazon asks this to test frequency counting, heap manipulation, and O(N) bucket sort optimization for bounded frequency ranges.

Read →
dsa5 min read

Meta — Binary Tree Right Side View (BFS Level Order)

Return the rightmost visible node at each level of a binary tree using BFS level order traversal. Meta uses this to test BFS confidence, level tracking, and tree traversal variants applied to visual rendering problems.

Read →
dsa6 min read

Google — Word Break II (DP + Backtracking with Memoization)

Return all possible sentence segmentations of a string using valid dictionary words via DP memoization and backtracking. Google tests this to evaluate recursive search pruning and memoization applied to NLP-style segmentation.

Read →
dsa5 min read

Meta — Accounts Merge (Union-Find on Emails)

Merge accounts that share any email address using Union-Find on email nodes. Meta uses this to test graph connectivity thinking and identity resolution — directly applicable to Facebook account deduplication systems.

Read →
dsa6 min read

Google — Trapping Rain Water II (3D BFS + Min-Heap)

Compute trapped rain water in a 3D height map using a min-heap BFS that processes cells from the boundary inward. Google asks this as a hard follow-up to 1D trapping rain water, testing 3D spatial reasoning and heap-driven BFS.

Read →
dsa5 min read

Meta — Clone Graph (Deep Copy with DFS and HashMap)

Deep copy an undirected graph using DFS or BFS with a HashMap to track already-cloned nodes. Meta tests this to evaluate graph traversal, deep copy semantics, and cycle detection in recursive graph structures.

Read →