Round 1 - Machine Coding

Problem Statement: Design and implement an Order Management System for Flipkart.

Complete problem and discussion: PhonePe | Machine Coding | Design Order Management System like Flipkart | LeetCode LLD


Round 2 - Problem Solving/Data Structures

Question 1: Remove K Digits

private static String removeKDigits(String num, int k) {
	Stack<Character> stack = new Stack<>();
	int index = 0;
	for(;index < num.length(); index++) {
		while(!stack.isEmpty() && k > 0 && stack.peek() > num.charAt(index)) {
			stack.pop();
			k--;
		}
		stack.push(num.charAt(index));
		if(k == 0) {
			break;
		}
	}
	while(index < num.length()) {
		stack.push(num.charAt(index));
		index++;
	}
	StringBuilder sb = new StringBuilder();
	while(!stack.isEmpty()) {
		sb.append(stack.pop());
	}
	sb = sb.reverse();
	return sb.toString();
}

Question 2: Find if we can cover all given treasures in a matrix of m x n with values:

  • 0 : Open position
  • 1 : Treasure
  • -1: Wall [Blocked position]

We will be given a coordinate of where to start and it will always be a valid position.
I found this pretty similar to these:
- Unique Paths III
- Cherry Pickup

private static boolean canCollectTreasure(int[][] matrix, int x, int y) {
	int treasureCount = 0;

	for(int[] row : matrix) {
		for(int val : row) {
			if(val == 1) {
				treasureCount++;
			}
		}
	}
	return countTreasure(matrix, x, y) == treasureCount;
}

private static int countTreasure(int[][] matrix, int r, int c) {
	if(r < 0 || c < 0 || r >= matrix.length || c >= matrix[0].length || matrix[r][c] < 0) {
		return 0;
	}
	int count = matrix[r][c];
	matrix[r][c] = -2;
	count += countTreasure(matrix, r + 1, c);
	count += countTreasure(matrix, r - 1, c);
	count += countTreasure(matrix, r, c + 1);
	count += countTreasure(matrix, r, c - 1);
	return count;
}

Follow up was to produce the minimum path to collect all these treasure if possible, which I wasn't able to achieve. Just the possible path to individual treausres or path which we found through this DFS by turning it into a BFS and exploring paths using Queue.


Round 3 - System Design

Problem Statement: The problem was presented as a feature use-case in existing product. We have an in-house browser [like Chrome, FireFox] to serve customers, and a data analytics team. Data analytics team frequently produces files with list of websites that are malicious and should not be visited due to security concerns. We need to build a System to consume and process the data from data analystics team, and let the browser know if a website is malicious or not for any given URL.

Complete problem and discussion: PhonePe | System Design | Malicious URL Detection


Result
I was expecting the call to final round which was HM but suprisingly got a rejection mail in few days. Feedback seemed good in all interviews so no idea why that would be the case. Hope the post helps! 😄

Comments (2)