Zomato Previous Year Coding Questions
Zomato is one of India's leading food-tech and hyperlocal delivery platforms, operating in 1000+ cities across India and internationally. Its engineering teams build real-time, high-throughput systems for food ordering, delivery logistics, restaurant discovery, dynamic pricing, payments, and personalised recommendations — serving millions of users daily.
Working at Zomato means tackling genuinely hard engineering problems: low-latency APIs, geo-spatial search, real-time delivery tracking, and massive-scale data pipelines. Their interview process reflects this — expect strong emphasis on graphs, BFS/DFS, dynamic programming, system design, and real-world delivery-flavoured scenarios.
All questions below are sourced directly from candidate interview reports on GeeksforGeeks, LeetCode Discuss, Medium, and DataLemur.
Zomato's Hiring Process
Application & Shortlisting: Apply via Zomato Careers, LinkedIn, campus drives (IITs, NITs, BITS), or referrals. Strong projects, open-source contributions, and system-level thinking stand out.
Online Assessment (OA): 3 DSA problems in 60–90 minutes + 15–20 CS MCQs (OS, DBMS, Networks). Conducted on HackerRank or a similar platform. Difficulty: Medium to Hard. Some roles include SQL questions.
Technical Round 1: 1–2 medium DSA problems on a shared editor + resume discussion. Interviewers focus on correctness, time/space complexity, and edge cases. Expect "Can you do better?" follow-ups.
Technical Round 2: 1 harder DSA problem + System Design or LLD. Common for SDE-1 final rounds and mandatory for SDE-2+. Zomato-specific design topics (delivery systems, notification at scale) are frequently asked.
Hiring Manager Round: Past project deep-dives, ownership mindset, and culture fit. Zomato values engineers who move fast, own problems end-to-end, and think about scale.
Offer: Competitive packages with base salary, ESOPs, and performance bonuses. Campus SDE-1 roles come with structured onboarding and mentorship programs.
Frequently Tested Topics at Zomato
Based on recurring patterns across 2021–2025 interview reports:
- Graphs & BFS/DFS: Shortest path, multi-source BFS, connected components, grid traversal, cyclic grids — the most heavily tested area at Zomato due to delivery network problems.
- Dynamic Programming: Knapsack, LCS, LIS, binary search on answer (Allocate Books, Painters' Partition), bitmask DP.
- Monotonic Stack: Previous/Next smaller or greater element, histogram rectangle — appears in both OA and Tech Rounds.
- Linked Lists: Reverse in groups, palindrome check, cycle detection and removal — standard across all rounds.
- Trie: Prefix search, autocomplete, reverse history search — asked specifically in Tech Round 2.
- Design Problems: LRU Cache (confirmed across 4+ years), Shuffle Playlist, HashMap design.
- SQL: Window functions, GROUP BY + HAVING, CASE WHEN — for backend and data roles.
- Zomato-Specific Scenarios: Delivery agent assignment, restaurant search, notification systems, order management.
How to Use This Resource
Each question includes:
- Round — which stage it was asked in, and the year
- Difficulty — Easy / Medium / Hard
- Topic — the primary DSA concept being tested
- Constraints — where reported, to guide your complexity thinking
- Problem Statement — accurate description from candidate reports
- Example — input/output with explanation
- Approach — optimal strategy and complexity
Practice these on LeetCode, HackerRank, or GFG. Always state the brute-force first, explain why it is insufficient, then derive the optimized solution.
Additional Resources for Preparation
- Free mock test
- ATS Score checker & Resume optimization
- Roadmaps
- Interview questions
- Interview experience
- Resume Templates
- Free study notes
- Free placement material drive link
Tips for Success
- Graphs are Non-Negotiable: BFS/DFS, Dijkstra, Union-Find — be fluent in all of them. Zomato maps delivery networks to graph problems constantly.
- Know Your Stack Patterns: Monotonic stack for previous/next smaller or greater element problems comes up in both OA and interviews. Practice until it's reflexive.
- Think Zomato-Scale: When discussing complexity, mention that Zomato processes millions of orders per day. An O(n²) solution that works for n=1000 may be unacceptable at production scale.
- LRU Cache is Almost Guaranteed: It has appeared in Zomato interviews across 2021, 2022, 2023, and 2024. Know the HashMap + Doubly Linked List implementation cold.
- Binary Search on Answer: The "Allocate Books / Painters' Partition" pattern is a staple — binary search on the answer combined with a greedy check. Recognise this pattern quickly.
- SQL is Real: For backend and data engineering roles, SQL questions are part of the OA and tech rounds. Focus on GROUP BY, HAVING, window functions, and CASE WHEN.
- Explain Constantly: Zomato interviewers value structured thinkers. Walk through your thought process before writing a single line of code.
- Prepare STAR Stories: The hiring manager round is competency-based. Prepare 4–5 stories covering ownership, fast delivery under pressure, handling failure, and cross-functional collaboration.
Good luck with your preparation!
Online Assessment (OA) Questions
1. Friends — Partition Value Maximization
Round: Online Assessment — IIT Campuses, November 2022 | Difficulty: Hard | Topic: Graphs, Binary Search, Greedy
Problem Statement: There are N people. Each pair has an associated "friend value" A[i][j]. Partition all N people into exactly 2 non-empty groups. The partition value = minimum of (minimum intra-group friend value in Group 1, minimum intra-group friend value in Group 2). Find the partition that maximises this value.
Constraints:
- 3 < N ≤ 500
- 1 ≤ A[i][j] ≤ 10⁹ (for i ≠ j), A[i][i] = 0
- A[i][j] = A[j][i] (symmetric)
Example:
Input: N = 3, A = [[0,3,2],[3,0,5],[2,5,0]]
Partitions: {1,2} vs {3} → value = min(3, ∞) = 3; {1,3} vs {2} → value = min(2, ∞) = 2; {2,3} vs {1} → value = min(5, ∞) = 5
Output: 5
Approach: Binary search on the answer value m. For a given m, treat all pairs with A[i][j] ≥ m as connected. Check if the graph can be 2-coloured (bipartite check) to form a valid partition. O(N² log(max_val)).
2. XOR Operation on Range Queries
Round: Online Assessment — IIT Campuses, November 2022 | Difficulty: Medium | Topic: Bit Manipulation, Prefix Sums
Problem Statement: Given an array of N integers and Q queries, for each query (L, R, X) output the sum of (A[i] XOR X) for all indices i from L to R (1-indexed).
Constraints: 1 ≤ N, Q ≤ 10⁵, 0 ≤ A[i], X ≤ 10⁹
Example:
Input:
5 2
2 3 1 4 5
1 1 3
3 5 2
Output:
1
16
Explanation: Query 1: A[1] XOR 3 = 2 XOR 3 = 1. Query 2: (A[3] XOR 2) + (A[4] XOR 2) + (A[5] XOR 2) = (1 XOR 2) + (4 XOR 2) + (5 XOR 2) = 3 + 6 + 7 = 16.
Approach: For each of the 32 bit positions, maintain a prefix count of set bits. For a query, compute the XOR contribution per bit: if bit b of X is 1, it flips every element's bit b in the range. Use prefix sums to find how many elements in [L,R] have bit b set vs unset, then compute the contribution. Total: O(N × 32) preprocessing, O(32) per query.
3. Binary String Partition — Each Substring Has Exactly Two 1s
Round: Online Assessment — On-Campus 2023 | Difficulty: Medium | Topic: Strings, Combinatorics
Problem Statement: Given a binary string, find the number of ways to partition it into substrings such that each substring contains exactly two 1s.
Example:
Input: s = "110110"
Positions of 1s (0-indexed): 0, 1, 3, 4
Pairs of 1s: (0,1) and (3,4). Between position 1 and position 3, there is 1 zero (position 2) → 2 split choices. Leading zeros before first pair: 1 choice. Trailing zeros after last pair: 1 choice.
Output: 2
Approach: Collect all indices of '1's. If the count of 1s is 0 or odd, return 0. Between every consecutive even-indexed pair of 1s (positions 2k and 2k+1 in the 1s-array), count the zeros between 1[2k+1] and 1[2k+2]. Each such gap of z zeros gives (z+1) split choices. Multiply all choices. O(n).
4. Allocate Minimum Number of Pages
Round: Online Assessment — On-Campus 2021 and 2023 | Difficulty: Medium | Topic: Binary Search on Answer, Greedy
Problem Statement: Given N books (page counts in an array) and M students, allocate contiguous books to each student such that the maximum pages allocated to any student is minimised. Return that minimum value.
Constraints: N ≥ M, 1 ≤ pages[i] ≤ 10⁶, 1 ≤ M ≤ N ≤ 10⁵
Example:
Input: pages = [12, 34, 67, 90], M = 2
Output: 113
Explanation: Best split: [12, 34, 67] to student 1 (sum=113), [90] to student 2 (sum=90) → max = 113. Any other split gives a higher max.
Approach: Binary search between low = max(pages) and high = sum(pages). For each mid, greedily assign books left to right until adding another book exceeds mid — increment student count. If student count ≤ M, mid is feasible. O(N log(sum)).
5. Unique Paths in a Grid with Obstacles
Round: Online Assessment — On-Campus 2021 (4 DSA problems, 60 min) | Difficulty: Medium | Topic: Dynamic Programming, Grid
Problem Statement: An m × n grid has obstacles (1) and free cells (0). A robot at the top-left must reach the bottom-right, moving only right or down. Find the number of unique paths that avoid all obstacles.
Constraints: 1 ≤ m, n ≤ 100, grid[i][j] ∈ {0, 1}
Example:
Input: grid = [[0,0,0],[0,1,0],[0,0,0]]
Output: 2
Explanation: Two paths avoid the obstacle at (1,1): right→right→down→down and down→down→right→right.
Approach: dp[i][j] = number of paths to reach (i,j). If grid[i][j] == 1, dp[i][j] = 0. Otherwise dp[i][j] = dp[i-1][j] + dp[i][j-1]. Base case: dp[0][0] = 1. O(m × n) time and space. (LeetCode 63)
6. Largest Rectangular Area in a Histogram
Round: Online Assessment — On-Campus 2021 | Difficulty: Hard | Topic: Monotonic Stack
Problem Statement: Given an array of bar heights in a histogram (each bar width = 1), find the area of the largest rectangle that can be formed within the histogram.
Constraints: 1 ≤ heights.length ≤ 10⁵, 0 ≤ heights[i] ≤ 10⁴
Example:
Input: heights = [2, 1, 5, 6, 2, 3]
Output: 10
Explanation: The rectangle of height 5 spanning bars at indices 2–3 (width 2) gives area = 10.
Approach: Maintain a monotonic increasing stack of indices. When heights[i] < heights[stack.top()], pop and compute the area: width = i − stack.top() − 1 (or i if stack is empty), height = popped bar's height. Track the maximum. O(n) time, O(n) space. (LeetCode 84)
7. Split Array Into Two Subsequences With Equal Average
Round: Online Assessment — New Delhi OA 2023, SDE-1 New Grad | Difficulty: Hard | Topic: Dynamic Programming, Meet in the Middle
Problem Statement: Given an integer array nums, split every element into one of two non-empty groups A and B such that average(A) == average(B). Return true if possible, false otherwise.
Constraints: 1 ≤ nums.length ≤ 30, 0 ≤ nums[i] ≤ 10⁴
Example:
Input: nums = [1, 2, 3, 4, 5, 6, 7, 8]
Output: true
Explanation: A = [1, 4, 5, 8] → avg = 18/4 = 4.5; B = [2, 3, 6, 7] → avg = 18/4 = 4.5.
Approach: avg(A) = avg(B) = avg(nums) = total/n. So find a subset of size k (1 ≤ k < n) with sum = k × total / n. If k × total % n ≠ 0 for any k, immediately false. Use DP with a set of reachable (size, sum) pairs. O(n² × sum) in the worst case, or meet-in-the-middle for tighter bounds. (LeetCode 805)
8. Minimum Swaps to Sort Non-Zero Elements
Round: Online Assessment — 2023–2024 | Difficulty: Medium | Topic: Arrays, Cycle Detection in Permutations
Problem Statement: Given an array containing zeros and non-zero integers, find the minimum number of swaps to sort the non-zero elements. Each swap must involve exactly one zero and one non-zero element (you can only move a non-zero element into a zero slot).
Example:
Input: [0, 3, 0, 1, 2]
Non-zero elements in-place: at indices 1, 3, 4 with values 3, 1, 2.
Sorted order should be: 1, 2, 3 at those same relative indices.
Minimum swaps to achieve this: 2
Output: 2
Approach: Extract the non-zero elements with their positions. Map each non-zero element to its target position in the sorted order. Count cycles in the resulting positional permutation. Each cycle of length L requires (L − 1) swaps. Zeros act as scratch space for temporary storage. O(n log n) for sorting, O(n) for cycle detection.
Technical Interview Round Questions
9. Distance from Nearest Guard in a Grid
Round: Technical Round 2 — Off-Campus SDE Backend 2023 | Difficulty: Medium | Topic: Graphs, Multi-source BFS
Problem Statement: Given a 2D grid where cells are 'G' (guard), 'W' (wall), or 'O' (open), find the minimum distance from each open cell to its nearest guard. Walls block movement. Movement is 4-directional only.
Constraints: 1 ≤ rows, cols ≤ 100
Example:
Input:
O O O O G
O W W O O
O O O W G
O W O O O
Output:
3 3 2 1 0
2 W W 2 1
1 2 3 W 0
2 W 2 1 1
Approach: Multi-source BFS — enqueue all 'G' cells simultaneously with distance 0. Expand outward level by level; skip 'W' cells. The first time BFS reaches an open cell, that is its minimum distance. O(rows × cols) time. (Similar to LeetCode 286 — Walls and Gates)
10. Maximum Sum by Switching Between Two Arrays
Round: Technical Round 1 and Round 2 — Multiple reports, 2022–2023 | Difficulty: Medium | Topic: Arrays, Two Pointers, Greedy
Problem Statement: Given two integer arrays ar1 and ar2 (both sorted), traverse from left to right. You may switch from one array to the other only at positions where both arrays share the same value. At a switch point, the shared value is counted once. Collect the maximum possible sum.
Constraints: Arrays may have different lengths. Elements are positive integers. Both arrays are sorted in ascending order.
Example:
ar1[] = {2, 3, 7, 10, 12, 15, 30, 34}
ar2[] = {1, 5, 7, 8, 10, 15, 16, 17}
Common elements: 7, 10, 15
Segment 1 (before 7): max(2+3, 1+5) = max(5, 6) = 6. Add intersection value 7 → running = 13.
Segment 2 (between 7 and 10): max(10, 8) = 10. Add intersection value 10 → running = 33.
Segment 3 (between 10 and 15): max(12, 15) = 15. Add intersection value 15 → running = 63.
Segment 4 (after 15): max(30+34, 16+17) = max(64, 33) = 64. Running total = 127.
Output: 127
Approach: Use two pointers, one per array. Accumulate partial sums between common elements. At each common element, add max(partial_sum_ar1, partial_sum_ar2) + common_value, reset both partial sums. O(n + m) time, O(1) space.
11. Reverse a Linked List in Groups of K
Round: Technical Round — On-Campus 2022–2023 | Difficulty: Medium | Topic: Linked List, Recursion, Iteration
Problem Statement: Given a singly linked list and integer k, reverse every k consecutive nodes. If the remaining nodes at the end are fewer than k, leave them unchanged.
Constraints: 1 ≤ k ≤ n ≤ 5000, node values are integers
Example:
Input: 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8, k = 3
Output: 3 → 2 → 1 → 6 → 5 → 4 → 7 → 8
Explanation: First group [1,2,3] reversed to [3,2,1]. Second group [4,5,6] reversed to [6,5,4]. Remaining [7,8] (< k) left as-is.
Note: Interviewers asked for both iterative and recursive implementations. Recursive is cleaner to write but uses O(n/k) call stack space; iterative runs in O(1) extra space.
12. Check if Linked List is a Palindrome
Round: Technical Round 1 — Off-Campus SDE Backend 2023 | Difficulty: Easy-Medium | Topic: Linked List, Two Pointers, Reversal
Problem Statement: Given a singly linked list, determine if it reads the same forwards and backwards. Return true or false.
Constraints: 1 ≤ n ≤ 10⁵, must run in O(n) time and O(1) extra space.
Example:
Input: 1 → 2 → 3 → 2 → 1
Output: true
Input: 1 → 2 → 3 → 3 → 2
Output: false
Approach: (1) Find the middle using slow/fast pointers. (2) Reverse the second half in-place. (3) Compare first half and reversed second half node by node. (4) Optionally restore the list. O(n) time, O(1) space.
13. LRU Cache
Round: Technical Interview — On-Campus 2021, 2022, 2023, 2024 (confirmed across all years) | Difficulty: Hard | Topic: Design, HashMap + Doubly Linked List
Problem Statement: Design and implement a Least Recently Used (LRU) cache:
get(key)— Return value if key exists, else -1. Mark key as most recently used.put(key, value)— Insert or update. If at capacity, evict the least recently used key before inserting.
Constraint: Both operations must run in O(1) average time.
Example:
LRUCache(capacity=2)
put(1, 1) → cache: {1:1}
put(2, 2) → cache: {1:1, 2:2}
get(1) → 1 (key 1 is now MRU) → cache order: [2, 1]
put(3, 3) → evicts key 2 (LRU) → cache: {1:1, 3:3}
get(2) → -1 (evicted)
get(3) → 3
Approach: Combine a HashMap (O(1) key lookup) with a Doubly Linked List (O(1) insert/delete at any position). Head = MRU end, Tail = LRU end. On every get/put, move the accessed node to the head. On eviction, remove the tail. (LeetCode 146)
14. Reverse History Search (Unix Ctrl+R Feature)
Round: Technical Round 2 — SDE-1 Interview, Multiple Reports | Difficulty: Medium-Hard | Topic: Strings, Trie, Design
Problem Statement: Implement a command-line terminal's reverse history search feature (similar to pressing Ctrl+R in a Unix shell):
recordCommand(cmd)— Adds a command to historypreviousCommand()— Returns the previously entered commandsearchHistory(query)— Returns the most recent command in history that containsqueryas a prefix
Example:
History: ["git status", "git commit", "npm install", "git push"]
searchHistory("git") → "git push" (most recent match)
searchHistory("npm") → "npm install"
previousCommand() → "git commit"
Naive approach: Linear scan backwards over history — O(n × m) per search.
Optimized approach: Insert all commands into a Trie. At each Trie node, store the most recently recorded command that passes through it. Prefix queries run in O(m) where m = query length.
Interviewer follow-up: "When would you prefer naive over Trie?" — For small or infrequently searched histories, naive is simpler. For large histories with frequent prefix searches, the Trie is worth the memory overhead.
15. Number of Islands — Spherical (Cyclic) Grid Variant
Round: Technical Round — Multiple Reports | Difficulty: Medium | Topic: Graphs, BFS/DFS, Union-Find
Problem Statement: Given a 2D grid of 'L' (land) and 'W' (water), count the number of distinct islands. In this Zomato variant, the grid is spherical — the top row wraps to the bottom row and the leftmost column wraps to the rightmost column. Boundary cells can therefore be connected to cells on the opposite side.
Constraints: 1 ≤ rows, cols ≤ 300
Example:
Grid (3×5):
L W W W L
W W W W W
L W W W L
Without wrapping: 4 islands (one at each corner).
With cyclic wrapping: top-left (0,0) connects to bottom-left (2,0) and top-right (0,4) connects to bottom-right (2,4), and (0,0) connects to (0,4) via horizontal wrap → all 4 corner cells form 1 island.
Output: 1
Approach: Standard DFS/BFS with modular index arithmetic.nextRow = (row + dr + rows) % rowsnextCol = (col + dc + cols) % cols
Alternatively, use Union-Find with wrap-around neighbour unions.
16. Find Previous Shorter Element
Round: Initial Round / OA — Confirmed Multiple Reports | Difficulty: Medium | Topic: Monotonic Stack
Problem Statement: Given an array of integers, for each element find the nearest element to its left that is strictly smaller. If no such element exists, output -1.
Constraints: 1 ≤ n ≤ 10⁵, -10⁶ ≤ A[i] ≤ 10⁶
Example:
Input: [1, 3, 0, 2, 5]
Output: [-1, 1, -1, 0, 2]
Explanation: For 3: nearest left smaller = 1. For 0: no smaller element to the left → -1. For 2: nearest left smaller = 0. For 5: nearest left smaller = 2.
Approach: Maintain a monotonic increasing stack of values. For each element, pop all elements ≥ current. The stack top (if non-empty) is the answer; push current element. O(n) time, O(n) space.
17. Remove Adjacent Duplicate Characters Repeatedly
Round: Technical Round 2 — Confirmed Reports | Difficulty: Medium | Topic: Stack, Strings
Problem Statement: Given a string, repeatedly remove pairs of adjacent identical characters until no two adjacent characters are the same. Return the final string.
Constraints: 1 ≤ s.length ≤ 10⁵, s consists of lowercase English letters.
Example:
Input: "abccbdccc"
Step 1: "cc" at index 2–3 removed → "abbdccc"
Step 2: "bb" at index 1–2 removed → "adccc"
Step 3: "cc" at index 2–3 removed → "adc"
Output: "adc"
Approach: Use a stack. For each character, if the stack top equals the current character, pop (they cancel out). Otherwise push. A single left-to-right pass naturally handles cascading removals. O(n) time and space. (LeetCode 1047 variant)
18. Longest Common Subsequence — Optimized for Unique Characters
Round: Technical Round 2 — SDE Interview, Confirmed | Difficulty: Hard | Topic: Dynamic Programming, LIS, Binary Search
Problem Statement: Given two strings, find the length of their Longest Common Subsequence (LCS).
Standard approach (always asked first): O(n × m) 2D DP. dp[i][j] = LCS of text1[0..i-1] and text2[0..j-1].
Zomato follow-up twist: "Both strings contain only unique characters — can you do better than O(n × m)?"
Example:
text1 = "acdbf", text2 = "bcadf" (all unique characters in each string)
LCS = "adf", length = 3.
Optimized approach for unique characters: Map each character of text2 to its position. Convert text1 into a sequence of positions in text2 (skip characters not in text2). Finding the LCS now becomes finding the Longest Increasing Subsequence (LIS) of this position array, solvable in O(n log n) using patience sorting with binary search.
19. Shuffle Playlist Without Repetition
Round: Technical Round 1 and Round 2 — Multiple Reports, 2022–2023 | Difficulty: Medium | Topic: Randomization, Array Manipulation, Design
Problem Statement: Implement a music player's shuffle function with these two guarantees:
- No song repeats until all songs in the playlist have been played once.
- At each step, each remaining unplayed song has an equal probability of being selected next.
Also implement previousSong() which returns the song played immediately before the current one.
Example:
Playlist: [A, B, C, D, E] (5 songs)
A valid shuffle cycle: D → B → A → E → C (all played once, each equally likely at each step).
After the cycle ends, a new random cycle begins.
Approach: Adapted Fisher-Yates (Knuth) shuffle. Maintain a boundary pointer starting at n-1. Each call: pick a random index r in [0, boundary], swap songs[r] with songs[boundary], return songs[boundary], decrement boundary. When boundary hits -1, reset to n-1 for the next cycle. O(1) per shuffle call, O(n) space.
For previousSong(): maintain a small history stack.
20. Maximal Square in Binary Matrix
Round: OA and Technical Round 1 — 2024 | Difficulty: Medium | Topic: Dynamic Programming, Matrix
Problem Statement: Given an m × n binary matrix of '0's and '1's, find the size of the largest square containing only '1's and return its area.
Constraints: 1 ≤ m, n ≤ 300, matrix[i][j] ∈ {'0', '1'}
Example: Input:
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
Output: 4 (a 2×2 square of all 1s exists at rows 1–2, cols 2–3)
Approach: dp[i][j] = side length of the largest all-1 square with its bottom-right corner at (i,j).
Recurrence: if matrix[i][j] == '1', dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1.
Answer = max(dp[i][j])². O(m × n) time and space. (LeetCode 221)
21. Majority Element II
Round: Technical Round — 2024 | Difficulty: Medium | Topic: Arrays, Boyer-Moore Voting Algorithm
Problem Statement: Given an integer array of size n, find all elements that appear more than ⌊n/3⌋ times. Return all such elements.
Constraints: 1 ≤ nums.length ≤ 5×10⁴, -10⁹ ≤ nums[i] ≤ 10⁹
Example:
Input: nums = [3, 2, 3]
Output: [3]
Input: nums = [1, 1, 1, 3, 3, 2, 2, 2]
Output: [1, 2]
Key insight: There can be at most 2 elements appearing more than n/3 times.
Approach: Extended Boyer-Moore Voting with 2 candidate slots and 2 counters. Phase 1: find the 2 candidates. Phase 2: verify their actual counts. O(n) time, O(1) space. (LeetCode 229)
22. Painters' Partition Problem
Round: Technical Round 2 — 2022 | Difficulty: Medium-Hard | Topic: Binary Search on Answer, Greedy
Problem Statement: Given N boards with integer lengths and K painters, each painter paints only contiguous boards and takes 1 unit of time per unit of board length. All K painters work simultaneously. Find the minimum time required to paint all boards.
Constraints: 1 ≤ N ≤ 10⁵, 1 ≤ K ≤ N, 1 ≤ len[i] ≤ 10⁶
Example:
Input: boards = [10, 20, 30, 40], K = 2
Option A: Painter 1 = [10,20,30] (60), Painter 2 = [40] (40) → max = 60
Option B: Painter 1 = [10,20] (30), Painter 2 = [30,40] (70) → max = 70
Output: 60
Approach: Binary search on time T between max(boards) (lower bound) and sum(boards) (upper bound). For each T, greedily check: iterate left to right, assign boards to current painter until the next board would exceed T — then start a new painter. If the number of painters needed ≤ K, T is feasible. O(N log(sum)).
23. Unit Conversion Graph
Round: Technical Round — 2022 | Difficulty: Medium | Topic: Graphs, BFS/DFS, Weighted Edges
Problem Statement: You are given a set of unit conversion facts (e.g., "1 meter = 10 decimeters", "1 centimeter = 0.01 meters"). Given a query (unit A → unit B), find the conversion factor.
Example:
Known conversions: m → dm = 10.0, cm → m = 0.01
Query: cm → dm
Output: 0.1 (path: cm →[×0.01]→ m →[×10]→ dm = 0.1)
Query: dm → cm
Output: 10.0 (path: dm →[÷10]→ m →[÷0.01]→ cm = 10.0)
Approach: Build a directed weighted graph. For each known conversion A → B with factor f, add edge A→B (weight f) and B→A (weight 1/f). For a query (A, B), do BFS/DFS from A multiplying edge weights along the path until reaching B. Return the accumulated product, or -1.0 if no path exists. (LeetCode 399 — Evaluate Division)
24. Count Strings Matching Given Prefixes
Round: Technical Round — 2024 | Difficulty: Medium | Topic: Trie, Strings
Problem Statement: Given N prefix strings and M query strings (M > N), for each of the N prefixes, count how many of the M strings start with that prefix.
Constraints: 1 ≤ N ≤ 10³, 1 ≤ M ≤ 10⁵, string lengths ≤ 100
Example:
Prefixes: ["ap", "ban"]
Strings: ["apple", "application", "banana", "band", "mango", "ape"]
Output: ap → 3 (apple, application, ape), ban → 2 (banana, band)
Approach: Insert all M strings into a Trie. At each Trie node, maintain a count of how many strings were inserted through it. For each prefix query, traverse the Trie to the last character of the prefix and return the node's count. O(M × L) to build, O(N × P) to answer all queries, where L = avg string length, P = avg prefix length.
25. Sort Coordinates by Parabola Value (Two-Pointer Math)
Round: Technical Round 2 — SDE-2 Interview | Difficulty: Medium-Hard | Topic: Mathematics, Two Pointers, Sorting
Problem Statement: Given an array of (x, y) coordinate pairs sorted by x-value in ascending order, re-sort them in ascending order by their y-values, where y is defined by an upward-opening parabola y = ax² + bx + c (a > 0). Do not recompute y for all points from scratch — use the mathematical properties of the parabola.
Example:
Parabola: y = x² − 4x + 4 = (x−2)², sorted input by x: [(-1,9), (0,4), (1,1), (2,0), (3,1), (4,4), (5,9)]
Output sorted by y: [(2,0), (1,1), (3,1), (0,4), (4,4), (-1,9), (5,9)]
Approach:
- Find vertex x-coordinate: x_vertex = -b/(2a). This is where y is minimised.
- Use two pointers: left pointer at the smallest x, right pointer at the largest x.
- Since the parabola opens upward, the maximum y-values are at the extremes. Compare y at left and right pointers; place the larger into the result from the right side; move that pointer inward.
- Result is filled from right to left. O(n) after the initial sorted array is given.
SQL Questions (Confirmed Zomato Interviews)
26. Swapped Food Delivery Orders
Round: SQL / Technical Round | Difficulty: Medium | Topic: SQL, CASE WHEN, Subquery
Source: Confirmed Zomato SQL question on DataLemur
Problem Statement: Due to a system error, each order's item was swapped with the item in the subsequent row. Write a SQL query to correct these swaps. If the total number of orders is odd, the final order remains unchanged.
Table: orders
| Column | Type |
|---|---|
| order_id | integer |
| item | varchar |
Sample Input:
| order_id | item |
|---|---|
| 1 | Chow Mein |
| 2 | Pizza |
| 3 | Pad Thai |
| 4 | Butter Chicken |
| 5 | Eggrolls |
| 6 | Burger |
| 7 | Tandoori Chicken |
Expected Output:
| corrected_order_id | item |
|---|---|
| 1 | Pizza |
| 2 | Chow Mein |
| 3 | Butter Chicken |
| 4 | Pad Thai |
| 5 | Burger |
| 6 | Eggrolls |
| 7 | Tandoori Chicken |
Approach:
SELECT
CASE
WHEN order_id % 2 = 1 AND order_id != (SELECT COUNT(*) FROM orders)
THEN order_id + 1
WHEN order_id % 2 = 0
THEN order_id - 1
ELSE order_id
END AS corrected_order_id,
item
FROM orders
ORDER BY corrected_order_id;
27. Average Restaurant Rating Per Month
Round: SQL / Technical Round | Difficulty: Medium | Topic: SQL, GROUP BY, HAVING, EXTRACT
Source: Confirmed Zomato SQL question on DataLemur
Problem Statement: Find the average rating for each restaurant per calendar month. Only include restaurant-month combinations with at least 2 reviews. Return restaurant_id, month number, and average rating rounded to 2 decimal places, ordered by restaurant_id and month.
Table: reviews
| Column | Type |
|---|---|
| review_id | integer |
| user_id | integer |
| submit_date | date |
| restaurant_id | integer |
| rating | decimal |
Approach:
SELECT
restaurant_id,
EXTRACT(MONTH FROM submit_date) AS month,
ROUND(AVG(rating), 2) AS avg_rating
FROM reviews
GROUP BY restaurant_id, EXTRACT(MONTH FROM submit_date)
HAVING COUNT(*) >= 2
ORDER BY restaurant_id, month;
28. Find Persons With At Least One Living Parent
Round: Technical Round 1 — SDE-1 Interview, Confirmed | Difficulty: Easy-Medium | Topic: SQL, GROUP BY, HAVING, Aggregation
Problem Statement: Given a parents table where each person has exactly two rows (one for Mother, one for Father) with a Status column of 'Alive' or 'Dead', write:
- A query to count persons where at least one parent is Alive.
- A follow-up query to count persons where both parents are Alive.
Table: parents
| Column | Type |
|---|---|
| person | varchar |
| parent | varchar |
| status | varchar |
Approach:
-- At least one parent alive:
SELECT COUNT(DISTINCT person) AS persons_with_one_alive_parent
FROM parents
GROUP BY person
HAVING SUM(CASE WHEN status = 'Alive' THEN 1 ELSE 0 END) >= 1;
-- Both parents alive:
SELECT COUNT(DISTINCT person) AS persons_with_both_parents_alive
FROM parents
GROUP BY person
HAVING SUM(CASE WHEN status = 'Alive' THEN 1 ELSE 0 END) = 2;
System Design Questions (Zomato-Flavored)
29. Restaurant Reopening Notification System
Round: Technical Round 2 / System Design — SDE-1 Interview, Confirmed | Difficulty: Hard
Problem Statement: Many restaurants close during major holidays. When they reopen, Zomato needs to:
- Detect the reopening event
- Check if delivery partners are available in that restaurant's area
- Send a push notification to users who have shown interest in that restaurant
Design a highly scalable system to handle this for millions of users and thousands of restaurants reopening simultaneously.
Key points Zomato interviewers specifically asked about:
- Event Detection: How does the system know a restaurant reopened? (Polling vs webhook from restaurant app vs status field change trigger)
- Message Queue: Use Kafka to decouple the reopening event from downstream processing. The reopening event is published to a topic; multiple consumers can react independently.
- Geo-availability Check: A geofencing microservice queries a delivery partner location store (Redis with geospatial index) to confirm partners exist within the restaurant's delivery radius.
- Interest Graph: A restaurant-user subscription table stores which users have favourited or ordered from a given restaurant. Sharded by restaurant_id.
- Notification Dispatch: Fan-out to millions of users must be async. Push via FCM/APNs. Apply per-user rate limiting to avoid spamming.
- Database Design: Restaurant status table, user-restaurant interest table (restaurant_id, user_id, last_order_at), delivery partner location store.
30. Delivery Agent Order Maximisation
Round: Technical Round 1 — Off-Campus SDE Backend 2023 | Difficulty: Medium | Topic: Dynamic Programming, Graphs
Problem Statement: A Zomato delivery agent is at their current location with a fixed total available time budget T (in minutes). You are given travel times between all delivery locations. Maximise the number of orders the agent can complete (visit each assigned delivery address once) within time T, starting and ending at the depot.
Example:
T = 60 minutes, 4 delivery locations with travel times from depot: [15, 20, 10, 30].
Travel between locations adds to the total. Assuming direct travel, the agent can cover at most 2–3 deliveries depending on routing.
Approach:
- Small input (≤ 20 locations): Bitmask DP (TSP variant). State dp[mask][i] = minimum time to visit all locations in
mask, ending at location i. Check all states where time ≤ T and maximise the popcount(mask). - Large input: Greedy nearest-neighbour — always go to the closest unvisited delivery location. Not optimal but runs in O(n²).
- Interviewer focus: Recognise the TSP structure, explain the bitmask DP state transition clearly, and discuss why greedy fails to guarantee optimality.
Explore More Company PYQs
Looking for interview questions from other top companies? Check out these curated PYQ guides: