PhonePe Prep
Summary
This post summarizes my interview experience at PhonePe, detailing the various Data Structures & Algorithms and System Design questions I encountered across multiple technical rounds.
Full Experience
My interview journey at PhonePe involved several intense rounds, primarily focusing on Data Structures & Algorithms (DSA) and System Design.
DSA Rounds
The DSA rounds were comprehensive, covering a wide array of topics. I was presented with problems such as "Burning Tree" and "Shortest Path to Get All Keys". I also tackled LeetCode 1235: Maximum Profit in Job Scheduling and 1657: Determine if Two Strings Are Close. During Matchsticks to Square, I initially struggled due to misinterpreting the input format, but once I understood, my approach was satisfactory to the interviewer. For Kth Smallest Element in a Sorted Matrix, I started with a min-heap solution, and after a hint, optimized it using binary search.
Other notable DSA problems included Burst Balloons (a hard DP problem) and The Celebrity Problem. In a subsequent PS/DS round, I was asked to solve Remove K Digits and a problem from Codeforces. I also faced a custom question: "Find the minimum number of swaps to make a string palindrome", for which I used a greedy approach. Another question involved finding "the sum of all nodes at the deepest level in a binary tree".
I encountered a complex problem on maximizing total damage with spell casting, where I had to consider sliding window or dynamic programming, and removing the most stones in the same row or column, which required graph theory and Union-Find. Classic problems like Trapping Rain Water, Left View of a Binary Tree, and finding nodes at 'k' distance from a target node were also asked. I implemented a Min Stack and was tasked with printing the level order traversal of a tree with alternate direction changes, which I solved easily. Another monotonic stack problem was given, and despite modifications, I managed to solve the first two versions.
Additional problems included First Missing Positive, Longest Increasing Path in a Matrix, and an O(log n) optimization challenge for the Complete Binary Tree Inserter (which I could only solve in O(n)). Queue Reconstruction by Height, House Robber III, Kth Ancestor of a Tree Node, and Bricks Falling When Hit were also part of the technical assessments. I was also asked a question related to the Convex Hull Algorithm and how to generate random points within a circle with equal probability distribution.
System Design Rounds
The System Design rounds were equally challenging. I was asked to design a Search Autocomplete feature, where I successfully implemented a Trie-based solution and discussed scalability and optimizations. One of the final rounds was to design Instagram, where I focused on posting, immediate visibility, feed generation, and likes/comments. I covered NFRs, scale, HLD, and trade-offs, though I felt I could have elaborated more on the likes/comments service. I also had to design a service for delayed triggers, a generic online game (like Ludo/Chess) where I had to drive the discussion from FNRs to tech stack and matching logic, and Payment Gateway Integration. Another iteration of Design Instagram highlighted the interviewer's disagreement with a message queue for feed publishing/fetching at massive scale. Lastly, I designed Twitter, covering tweet posting, follow-following, timelines, and profiles, emphasizing LLD and HLD aspects.
Interview Questions (62)
You are given an integer array matchsticks where matchsticks[i] is the length of the i-th matchstick. You want to use all the matchsticks to form one square. You should not break any single matchstick, but you can link them up, and each matchstick must be used exactly one time. Return true if you can make this square, and false otherwise.
In a group of N people, a celebrity is someone who is known by everyone else but does not know anyone. Find the celebrity if one exists.
Given a string, find the minimum number of swaps required to make it a palindrome.
A problem about maximizing total damage with spell casting. I had to devise a strategy, possibly using sliding window or dynamic programming, to balance choices and constraints.
Given a binary tree, print the nodes in 'left view' order (first node at each level from the left side).
A problem solvable using a monotonic stack. The interviewer modified the question multiple times during the interview. I solved the initial problem and its first modification.
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root. Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that all houses in this place form a binary tree. It will automatically contact the police if two directly-linked houses were robbed on the same night. Determine the maximum amount of money the thief can rob tonight without alerting the police.
You are given an m x n grid representing a map of bricks. A brick is at grid[i][j] = 1 and an empty cell is at grid[i][j] = 0. You are also given an array hits, where hits[i] = [rowi, coli] indicates a brick (if exists) at that position is removed. We need to find the number of bricks that will fall after each hit.
A problem related to finding the convex hull of a set of points.
Write a function that generates random points within a circle with equal probability distribution.
A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. The path does not necessarily need to pass through the root. The path sum is the sum of the node's values in the path. Given the root of a binary tree, return the maximum path sum of any non-empty path.
Given an array of integers, count the maximum number of integers you can add such that at any point, the cumulative sum from left to right never goes negative. The question was presented in a scenario.
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given an array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi. Return an array answer of length n where answer[i] is the sum of the distances between node i and all other nodes in the tree.
You are given an m x n grid where each cell can have one of three values: 0 representing an empty cell, 1 representing a fresh orange, or 2 representing a rotten orange. Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten. Return the minimum number of minutes that must elapse until no fresh oranges remain. If this is impossible, return -1.
A greedy problem similar to typical meeting scheduling or interval problems.
A problem that can be solved using a monotonic stack, similar to finding the next greater element.
You are given an m x n integer matrix grid where grid[i][j] is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right. You are also given an integer k. Return the minimum number of steps to walk from (0, 0) to (m - 1, n - 1) given that you can eliminate at most k obstacles. If it is impossible to find such a path, return -1.
You are given a 0-indexed m x n grid of integers fire. You are in a cell (0, 0) and a fire starts at a cell (fireRow, fireCol). You want to reach a safe cell (m - 1, n - 1) before the fire reaches it. Return the maximum time t you can wait before starting your journey, such that you can still reach the safe cell. If it is impossible to ever reach the safe cell, return -1. If you can always reach the safe cell regardless of how long you wait, return 10^9.
You have a 2-D grid of size m x n representing a box with some slanted walls. A ball will drop from the top of the box. The grid grid[i][j] can be 1 (representing a right-slanted wall) or -1 (representing a left-slanted wall). Return an array answer of size n where answer[i] is the column that the ball falls out of at the bottom, or -1 if it gets stuck.
Given two strings str1 and str2 of the same length, determine whether you can transform str1 into str2 by doing zero or more conversions. In one conversion you can convert all occurrences of one character in str1 to any other lowercase English character.
Design a search autocomplete feature. I used a Trie data structure and implemented a working solution. The discussion covered scalability, handling different scenarios, and optimization of memory and time complexity.
Design Instagram, focusing on core features like posting content, immediate post visibility, feed generation, and likes/comments. I covered non-functional requirements, set scale expectations, and outlined a high-level design, detailing each service and its trade-offs.
Design a service that registers triggers with specified delays from other services and sends a response once the delay for that trigger is completed.
Design an online multiplayer game like Ludo or Chess. I had to lead the discussion, covering functional and non-functional requirements, high-level design, APIs, tech stack choices, implementation details, exception handling, fault tolerance, and database choices. I also explained core logic for features like player matching (e.g., Noob vs. Noob) and presented multiple approaches with their trade-offs.
Design a system for payment gateway integration. The interviewers were looking for very specific details in the design.
Design Twitter, focusing on functionalities such as posting tweets, follow/following mechanisms, user timelines, and user profiles. The interview emphasized both Low-Level Design (LLD) and High-Level Design (HLD).
Preparation Tips
My preparation primarily involved in-depth study of Data Structures and Algorithms, practicing a wide range of LeetCode problems, and gaining a solid understanding of System Design principles. I focused on common patterns and complex problem-solving techniques relevant to both domains.