Professional Documents
Culture Documents
Maang PDF Qns
Maang PDF Qns
+91-7260058093
info@algotutor.io
www.algotutor.io
Array
1. Two Sum
Given an array of integer nums and an integer target, return
indices of the two numbers such that they add up to the target.
You may assume that each input would have exactly one solution,
and you may not use the same element twice.
PRACTICE NOW
PRACTICE NOW
You must write an algorithm that runs in O(n) time and without
using the division operation.
PRACTICE NOW
02
5. Maximum Subarray
Given an integer array nums, find the subarray with the largest
sum, and return its sum.
PRACTICE NOW
PRACTICE NOW
03
7. Find the Minimum in Rotated
Sorted Array
Given the sorted rotated array nums of unique elements, return
the minimum element of this array.
PRACTICE NOW
PRACTICE NOW
04
9. 3Sum
Given an integer array nums, return all the triplets [nums[i],
nums[j], nums[k]]
such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the solution set must not contain duplicate triplets.
PRACTICE NOW
Find two lines that together with the x-axis form a container, such
that the container contains the most water.
Return the maximum amount of water a container can store.
PRACTICE NOW
05
Why Choose AlgoTutor?
1:1 PERSONAL
100 % PLACEMENT
MENTORSHIP FROM
ASSISTANCE
INDUSTRY EXPERTS
100 % SUCCESS
23 LPA(AVG.)CTC
RATE
LEARN FROM
CAREER SERVICES
SCRATCH
EXPLORE MORE
PRACTICE NOW
PRACTICE NOW
06
13. Rotate Image
You are given an n x n 2D matrix representing an image, rotate the
image by 90 degrees (clockwise).
You have to rotate the image in place, which means you have to
modify the input 2D matrix directly. DO NOT allocate another 2D
matrix and do the rotation.
PRACTICE NOW
07
PRACTICE NOW
String
15. Longest Substring Without
Repeating Characters
Given a string s, find the length of the longest
substring without repeating characters.
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with a length of 3.
PRACTICE NOW
Input: s = "ABAB", k = 2
Output: 4
Explanation: Replace the two 'A's with two 'B's or vice versa.
PRACTICE NOW
08
17. Minimum Window Substring
Given two strings s and t of lengths m and n respectively, return
the minimum window substring of s such that every character in t
(including duplicates) is included in the window. If there is no such
substring, return the empty string "".
PRACTICE NOW
PRACTICE NOW
09
19. Group Anagrams
Given an array of strings strs, group the anagrams together. You
can return the answer in any order.
PRACTICE NOW
Input: s = "()"
Output: true
Input: s = "()[]{}"
Output: true
PRACTICE NOW
10
21. Longest Palindromic Substring
Given a string s, return the longest palindromic substring in s.
Input: s = "babad"
Output: "bab"
Explanation: "aba" is also a valid answer.
Input: s = "cbbd"
Output: "bb"
PRACTICE NOW
Input: s = "abc"
Output: 3
Explanation: Three palindromic strings: "a", "b", "c".
Input: s = "aaa"
Output: 6
Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
PRACTICE NOW
11
23. Encode and Decode Strings
Design an algorithm to encode a list of strings to a string. The
encoded string is then sent over the network and decoded back to
the original list of strings.
Input: [“lint”,“code”,“love”,“you”]
Output: [“lint”,“code”,“love”,“you”]
Explanation: One possible encode method is: “lint:;code:;love:;you”
PRACTICE NOW
12
Linked List
24. Reverse Linked Lists
Given the head of a singly linked list, reverse the list, and return
the reversed list.
PRACTICE NOW
There is a cycle in a linked list if there is some node in the list that
can be reached again by continuously following the next pointer.
Internally, pos is used to denote the index of the node that the
tail's next pointer is connected to. Note that pos is not passed as a
parameter.
PRACTICE NOW
13
26. Merge Two Sorted Lists
You are given the heads of two sorted linked lists list1 and list2.
Merge the two lists in a one-sorted list. The list should be made by
splicing together the nodes of the first two lists.
PRACTICE NOW
Merge all the linked lists into one sorted linked list and return it.
PRACTICE NOW
14
28. Remove Nth Node From End of List
Given the head of a linked list, remove the nth node from the end
of the list and return its head.
PRACTICE NOW
You may not modify the values in the list's nodes. Only nodes
themselves may be changed.
PRACTICE NOW
15
Tree
30. Maximum Depth of Binary Tree
Given the root of a binary tree, return its maximum depth.
A binary tree's maximum depth is the number of nodes along the
longest path from the root node down to the farthest leaf node.
PRACTICE NOW
Two binary trees are considered the same if they are structurally
identical, and the nodes have the same value.
PRACTICE NOW
16
32. Invert Binary Tree
Given the root of a binary tree, invert the tree, and return its root.
PRACTICE NOW
The path sum of a path 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.
PRACTICE NOW 17
34. Binary Tree Level Order Traversal
Given the root of a binary tree, return the level order traversal of
its nodes' values. (i.e., from left to right, level by level).
PRACTICE NOW
PRACTICE NOW
18
36. Design Add and Search Words
Data Structure
Design a data structure that supports adding new words and
finding if a string matches any previously added string.
Implement the WordDictionary class:
WordDictionary() Initializes the object.
void addWord(word) Adds a word to the data structure, it can
be matched later.
bool search(word) Returns true if there is any string in the data
structure that matches the word or false otherwise. A word may
contain dots '.' where dots can be matched with any letter.
PRACTICE NOW
22
PRACTICE NOW
Want to up your Skill?
Join our Popular courses
EXPLORE MORE
PRACTICE NOW
23
40. Find Median from Data Stream
The median is the middle value in an ordered integer list. If the size
of the list is even, there is no middle value, and the median is the
mean of the two middle values.
For example, for arr = [2,3,4], the median is 3.
For example, for arr = [2,3], the median is (2 + 3) / 2 = 2.5.
Explanation:
MedianFinder medianFinder = new MedianFinder();
medianFinder.addNum(1); // arr = [1]
medianFinder.addNum(2); // arr = [1, 2]
medianFinder.findMedian(); // return 1.5 (i.e., (1 + 2) / 2)
medianFinder.addNum(3); // arr[1, 2, 3]
medianFinder.findMedian(); // return 2.0
PRACTICE NOW
24
Graph
41. Clone Graph
Given a reference of a node in a connected undirected graph.
Return a deep copy (clone) of the graph.
Each node in the graph contains a value (int) and a list (List[Node])
of its neighbors.
class Node {
public int val;
public List<Node> neighbors;
}
PRACTICE NOW
25
42. Course Schedule
There are a total of numCourses courses you have to take, labeled
from 0 to numCourses - 1. You are given an array of prerequisites
where prerequisites[i] = [ai, bi] indicates that you must take course
bi first if you want to take course ai.
For example, the pair [0, 1], indicates that to take course 0 you
have to first take course 1.
Return true if you can finish all courses. Otherwise, return false.
PRACTICE NOW
PRACTICE NOW
26
44. Pacific Atlantic Water Flow
There is an m x n rectangular island that borders both the Pacific
Ocean and the Atlantic Ocean. The Pacific Ocean touches the
island's left and top edges, and the Atlantic Ocean touches the
island's right and bottom edges.
The island is partitioned into a grid of square cells. You are given
an m x n integer matrix height where heights[r][c] represent the
height above sea level of the cell at coordinate (r, c).
The island receives a lot of rain, and the rainwater can flow to
neighboring cells directly north, south, east, and west if the
neighboring cell's height is less than or equal to the current cell's
height. Water can flow from any cell adjacent to an ocean into the
ocean.
PRACTICE NOW
27
Dynamic
Programming
45. 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?
Input: n = 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
PRACTICE NOW
Return the fewest number of coins that you need to make up that
amount. If that amount of money cannot be made up by any
combination of the coins, return -1.
PRACTICE NOW
30
Bitwise Operator
47. Sum of Two Integers
Given two integers a and b, return the sum of the two integers
without using the operators + and -.
Input: a = 1, b = 2
Output: 3
Input: a = 2, b = 3
Output: 5
PRACTICE NOW
Input: n = 00000000000000000000000000001011
Output: 3
Explanation: The input binary string
00000000000000000000000000001011 has a total of three '1'
bits.
PRACTICE NOW
39
49. Counting Bits
Given an integer n, return an array of length n + 1 such that for
each i (0 <= i <= n), ans[i] is the number of 1's in the binary
representation of i.
Input: n = 2
Output: [0,1,1]
Explanation:
0 --> 0
1 --> 1
2 --> 10
PRACTICE NOW
40
PRACTICE NOW
Why Choose AlgoTutor?
1:1 PERSONAL
100 % PLACEMENT
MENTORSHIP FROM
ASSISTANCE
INDUSTRY EXPERTS
100 % SUCCESS
23 LPA(AVG.)CTC
RATE
LEARN FROM
CAREER SERVICES
SCRATCH
EXPLORE MORE
EXPLORE MORE