SWIGGY ALL INTERVIEW QUESTIONS
Summary
I have compiled a comprehensive list of interview questions encountered during Swiggy's onsite interviews for both SDE-1 and SDE-2 roles, covering a wide range of LeetCode problems and system design challenges.
Full Experience
I've gathered these interview questions from various Swiggy SDE-1 and SDE-2 onsite rounds. This collection provides insights into the types of problems asked, encompassing classic data structures and algorithms, with direct references to many LeetCode problems, as well as several conceptual and system design questions. It serves as a valuable resource for anyone preparing for technical interviews at Swiggy.
Interview Questions (24)
Rotting Oranges (Similar)
A problem similar to Rotting Oranges, which typically involves a grid of fresh, rotten, and empty oranges. Fresh oranges rot if adjacent to a rotten orange. The goal is to find the minimum time until all fresh oranges rot or if it's impossible for all fresh oranges to rot.
Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive). Prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one. The interviewer specifically looked for an O(1) space complexity solution.
Nth Recently Used Number in Stream
Given a stream of numbers, find the nth most recently recurring number. For example, if the stream is [1, 1, 2, 3, 2, 4] and n = 2, the output should be the 2nd most recently recurring number. This problem implies tracking both frequency and recency of numbers in a stream.
Group Anagrams
Given an array of strings strs, group the anagrams together. You can return the answer in any order.
Merge k Sorted Lists
You are given an array of k linked-lists, each sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it.
Course Schedule II (Modified)
A problem with a slight modification based on Course Schedule II. The original problem asks to return the ordering of courses you should take to finish all courses, or an empty array if it's impossible. The core problem involves topological sorting.
Subarray Sum Equals K (Modified)
A modified version of the Subarray Sum Equals K problem. The original problem asks to find the total number of continuous subarrays whose sum equals k.
Subarray Sums Divisible by K
Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.
Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
Alien Dictionary
There is a new alien language that uses the English alphabet. However, the order among the letters is unknown to you. You are given a list of words from the alien language's dictionary, where the words are sorted lexicographically by the rules of this new language. Derive the order of the letters in this language.
Building Bridges
This problem typically involves finding the maximum number of non-crossing bridges that can be built between two banks of a river, given coordinates for cities on both banks. It's a classic dynamic programming problem, often solved using a variation of the Longest Increasing Subsequence algorithm.
Design LRU Cache
Design a Least Recently Used (LRU) cache. Implement the LRUCache class: LRUCache(int capacity) initializes the LRU cache with positive size capacity. int get(int key) returns the value of the key if the key exists, otherwise returns -1. void put(int key, int value) updates the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key.
Coin Change (Similar)
A problem similar to the Coin Change problem. The standard Coin Change problem asks for the fewest number of coins needed to make up a certain amount, or the number of combinations of coins that sum up to a given amount.
Surrounded Regions
Given an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region. Regions touching the border are not considered surrounded.
Maximum Length of Pair Chain
You are given n pairs of numbers, pairs[i] = [starti, endi]. A pair (c, d) follows a pair (a, b) if b < c. A chain of pairs can be formed in this fashion. Return the length of the longest chain which can be formed.
Find All Greater Numbers Formed by Digits
Given a number, find all possible numbers that can be formed using its digits which are greater than the given number. For example, if the input is 213, the output should include 231, 312, 321. This typically involves generating permutations.
Nearest Node Value in Binary Tree
Given a binary tree and a target value, find the node value in the tree that is closest to the target value.
String Replacement with Mismatched Substrings
Given a string S, a source array source, a target array target, and an index array indices. For each i, if the substring of S starting at indices[i] matches source[i], then replace that substring with target[i]. Otherwise, do nothing. Replacements are independent and should be performed simultaneously.
Game on Circular Array (Maximizing Score)
Two players take turns picking one element from either end of a circular array. The goal for each player is to maximize their own score. The problem asks to find the maximum possible gain for the first player and determine if the first player always wins.
Palindrome Pairs
Given a list of unique words, return all the pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words words[i] + words[j] is a palindrome.
Climbing Stairs
You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Jump Game III
Given an array of non-negative integers arr and a start index start. You are initially at start. When you are at index i, you can jump to i + arr[i] or i - arr[i]. Can you reach any index with value 0?
Jump Game II
Given an array of non-negative integers nums, you are initially positioned at the first index. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps.
Longest Substring Without Repeating Characters
Given a string s, find the length of the longest substring without repeating characters.