Range Sum Query 2D – Immutable LeetCode Solution

Difficulty Level Medium
Frequently asked in Amazon Bloomberg Facebook Google lyft Microsoft Nvidia Samsung UberViews 60

Problem Statement

Range Sum Query 2D – Immutable LeetCode Solution – Given a 2D matrix, handle multiple queries of the following type:

  • Calculate the sum of the elements of the matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).

Implement the NumMatrix class:

  • NumMatrix(int[][] matrix) Initializes the object with the integer matrix matrix.
  • int sumRegion(int row1, intcol1, int row2, int col2) Returns the sum of the elements of the matrix inside the rectangle defined by its upper left corner (row1, col) and lower right corner (row2, col2).

 

Example 1:

Range Sum Query 2D - Immutable LeetCode SolutionPinInput

["NumMatrix", "sumRegion", "sumRegion", "sumRegion"]
[[[[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]], [2, 1, 4, 3], [1, 1, 2, 2], [1, 2, 2, 4]]

Output

[null, 8, 11, 12]

Explanation

NumMatrix numMatrix = new NumMatrix([[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]);
numMatrix.sumRegion(2, 1, 4, 3);  return 8 (i.e sum of the red rectangle)
numMatrix.sumRegion(1, 1, 2, 2);  return 11 (i.e sum of the green rectangle)
numMatrix.sumRegion(1, 2, 2, 4);  return 12 (i.e sum of the blue rectangle)

Approach

Idea:

First, we make a cumulative sum for each row. Then, we use this new cumulative array and subtract the last int in our new “sumRegion” row from the first number in that “numMatrix” row. This shows us how much each row is and after we find the sums of each row, add them together to figure out the sum of the “sumRegion”. For regions that are taller than they are wide, do this same process but with the columns instead. The link down below shows the process written out.

Code

Python Program of Range Sum Query 2D – Immutable

class NumMatrix :
dp = None
def __init__(self, matrix) :
self.dp = [[0] * (len(matrix[0])) for _ in range(len(matrix))]
self.populateArray(matrix, self.dp)
def populateArray(self, arr, dp) :
i = 0
while (i < len(arr)) :
j = 0
while (j < len(arr[0])) :
if (j == 0) :
dp[i][j] = arr[i][j]
else :
dp[i][j] = arr[i][j] + dp[i][j - 1]
j += 1
i += 1
def sumRegion(self, row1, col1, row2, col2) :
if (row2 >= len(self.dp) or col2 >= len(self.dp[0]) or row1 < 0 or col1 < 0) :
return -1
sum = 0
i = row1
while (i <= row2) :
sum = sum + (self.dp[i][col2] - (self.dp[i][col1 - 1] if col1 > 0 else 0))
i += 1
return sum

Java Program of Range Sum Query 2D – Immutable

class NumMatrix {

int[][] dp;

public NumMatrix(int[][] matrix) {
dp = new int[matrix.length][matrix[0].length];
populateArray(matrix, dp);
}

private void populateArray(int[][] arr, int[][] dp) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
if (j == 0) {
dp[i][j] = arr[i][j];
} else {
dp[i][j] = arr[i][j] + dp[i][j - 1];
}
}
}
}

public int sumRegion(int row1, int col1, int row2, int col2) {
if (row2 >= dp.length || col2 >= dp[0].length || row1 < 0 || col1 < 0)
return -1;
int sum = 0;
for (int i = row1; i <= row2; i++) {
sum = sum + (dp[i][col2] - (col1 > 0 ? dp[i][col1 - 1] : 0));
}
return sum;
}
}

Complexity Analysis for Range Sum Query 2D – Immutable LeetCode Solution

Time Complexity

The time complexity of the above code is O(n^2) because there is a nested for loop.

Space Complexity

The space complexity of the above code is O(n) because we are using an array to store the prefix values of the original array.

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2822
2Java program to find the number of Nodes in a Binary Tree2504
3Reverse a string without affecting special characters2465
4Delete a node of a linked list at given position1979
5Palindrome using Recursion1839
6Insert nodes in a linked list in a sorted way (Ascending Order)1662
7Find elements pair from array whose sum equal to number1650
8Sort Elements by Frequency of Occurrences1633
9Write a program to print all permutations of a given string1607
10Find Minimum Distance Between Two Numbers in an Array1477
11Create a Doubly Linked List1445
12Quick Sort1422
13Reverse an Array1414
14Smallest window in a string containing all characters of another string1398
15Find a Triplet That Sum to a Given Value1357
16Recursively remove all adjacent duplicates1356
17First Repeating Element1341
18Arrange Even and Odd number such that Odd comes after Even1325
19Sum of numbers in String1319
20Smallest Positive Number Missing in an Unsorted Array1285
21Check if the Elements of an Array are Consecutive1256
22Detect a loop in the Linked List1239
23Largest Sum Contiguous Subarray1232
24Quick Sort on SIngly Linked List1218
25Subarray with Given Sum1216
26Print all Possible Combinations of R Elements in a given Array of size N1207
27Recursive function to do substring search1198
28Find the Maximum Repeating Number in Array1157
29Binary Tree Level order traversal in Java1128
30Find the First and Second Smallest Elements1123
31Check if two linked lists are identical1104
32Maximum Subarray Sum using Divide and Conquer1099
33Remove characters from first string which are in second1070
34Find Leaders in an Array1063
35Swap nodes in the linked list1039
36Find the Number Occurring Odd Number of Times in an Array1005
37Arrange given Numbers to Form the Biggest Number II995
38Find the second most frequent character990
39Given a string find its first non-repeating character972
40Find Triplet in Array With a Given Sum965
41Given a sorted array and a number x, find the pair in array whose sum is closest to x956
42Total number of occurrences of a given item in the linked list955
43A Program to check if strings are rotations of each other or not945
44Print all possible words from phone digits935
45Find the Missing Number927
46Rearrange Positive and Negative Numbers Alternatively in Array921
47Longest Palindromic Substring906
48Segregate even and odd nodes in a linked list884
49Print Longest common subsequence883
50Union and Intersection of Two Linked Lists874
51Transform one string to another using minimum number of given operations869
52Check rearranged string can form a palindrome847
53Rearrange given Array in Maximum Minimum Form847
54Count Possible Triangles821
55Iterative Implementation of Quick Sort816
56Multiplication of Two Matrices804
57Check if the linked list is palindrome797
58Rotate a Linked List795
59Count of Triplets With Sum Less than Given Value794
60Stock Buy Sell to Maximize Profit792
61Concatenation of two strings763
62Tug of War761
63Count Number of Substrings with K Distinct Character’s758
64Print all duplicates in the input string755
65Find Nearest Greater and Smaller Element748
66Find Pythagorean Triplets from Array739
67The Celebrity Problem738
68Reverse String Without Temporary Variable735
69Remove ‘b’ and ‘ac’ from a given string731
70Find all Common Elements in Given Three Sorted Arrays729
71Remove all duplicates in an unsorted linked list711
72Find the Row with Maximum Number of 1’s708
73Find the Peak Element from an Array703
74Find the subarray whose sum is equal to a given number X697
75Remove Minimum Characters so that Two Strings Become Anagrams690
76Find Smallest Missing Number in a Sorted Array689
77Addition of Two Matrices687
78A Product Array Puzzle687
79Insertion Sort686
80Implement Two Stacks in an Array679
81Generate all Binary Strings Without Consecutive 1’s678
82Maximum Sum of Non Consecutive Elements669
83Maximum Product Subarray II659
84Lexicographic rank of string655
85Check if Two given Matrices are Identical647
86Multiplication of Previous and Next644
87Subtraction of Two Matrices636
88Merge K Sorted Arrays and Print Sorted Output633
89Move All the Zeros to the End of the Given Array631
90Online Algorithm for Checking Palindrome in a Stream626
91Form Minimum Number from Given Sequence of D’s and I’s625
92Divide a string in N equal parts623
93Maximum Circular Subarray Sum615
94Check whether two strings are anagram of each other615
95Remove recurring digits in a given number610
96Sort a linked list that is sorted alternating ascending and descending610
97Sort a stack using a temporary stack609
98Find the Minimum Element in a Sorted and Rotated Array608
99First Circular Tour to Visit all the Petrol Bunks602
100Subarray and Subsequence602
101Move last element of the Linked List at first place601
102Largest Subarray with Equal Number of 0’s and 1’s599
103Flattening a linked list593
104Compare two strings(linked lists)592
105Maximum Element in an Array which is Increasing and then Decreasing590
106Palindrome Permutations of a String585
107Elements Appear more than N/K times in Array583
108Majority Element576
109Run length encoding575
110Palindromes in a given range574
111Minimum insertions to form a shortest palindrome573
112Pangram Checking572
113Print all permutations with repetition572
114Merge a linked list into another at alternate positions569
115Minimum Characters to be Added at Front to Make String Palindrome566
116Remove all duplicates in a sorted linked list565
117Rearrange a given linked list in-place564
118Minimum number of Merge Operations to make an Array Palindrome562
119Rotate string to get lexicographically minimum string558
120Most repeating character in a string558
121Repeated Subsequence of Length Two or More557
122Print all anagrams together in a sequence of words552
123Reorder an Array According to the Given Indexes551
124Pancake Sorting Problem543
125Merge Overlapping Intervals II539
126Two Sum Leetcode Solution539
127Clone a Linked List with next and random pointer538
128Size of The Subarray With Maximum Sum528
129Transpose of a Matrix527
130Removing Spaces from a String using stringstream522
131Remove duplicates from a string522
132Smallest Palindrome after Replacement521
133Remove Extra Spaces from a String521
134Check if a given string is a rotation of a palindrome519
135Maximum Sum Increasing Subsequence517
136Partition Problem517
137Longest Palindrome can be Formed by Removing or Rearranging Characters514
138Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized504
139Check whether Strings are K Distance Apart or Not504
140Insert Node in the Sorted Linked List502
141Delete Last Occurrence502
142Generate all Binary Strings from Given Pattern502
1433Sum Leetcode Solution500
144Length of Longest valid Substring499
145Check if Two given Strings are Isomorphic to each other494
146Maximum difference between two elements such as larger element comes after smaller489
147Program to Toggle all Characters in a String486
148Given string is interleaving of two other strings or not484
149Count Minimum Steps to Get the given Array481
150Number of Smaller Elements on Right Side481
151Merge sort better than quick sort for linked lists479
152Find Pair with Given Difference474
153Check length of a String is Equal to the Number Appended at its Last472
154Check if all Rows of a Matrix are Circular Rotations of Each Other471
155Find nth node of the Linked list from the end470
156Longest Common Prefix using Divide and Conquer470
157Find a Fixed Point in a Given Array466
158Sort 0s 1s and 2s in an Array464
159Print all interleavings of given two strings458
160Compare Two Version Numbers456
161Reverse words in a given string455
162Merge two sorted linked lists such that merged list is in reverse order454
163Find the Subarray of given length with Least Average453
164Median of Two Sorted Arrays LeetCode Solution452
165Reorder Array Using Given Indexes452
166Print Reverse of a string (Recursion)450
167Split linked list using alternate nodes450
168Find K Length Subarray of Maximum Average439
169Print string of odd length in ‘X’ format437
170Find Element Using Binary Search in Sorted Array434
171Swap Kth Node from beginning with Kth Node from End433
172Print all Palindromic Partitions of a String432
173Find Duplicates in an Array in Most Efficient Way429
174print all palindromic partitions422
175Maximum Length of Chain Pairs418
176Shortest Superstring Problem417
177Flatten a multilevel linked list416
178Check if String Follows Order of Characters by a Pattern or not413
179Sorting a K Sorted Array410
180Sort a String According to Another String404
181Longest Span with same Sum in two Binary Arrays II399
182Find a Sorted Subsequence of size 3398
183Reverse a Linked List in groups396
184Program to add two binary digits394
185Recursively print all the sentences that can be formed from list of word lists392
186Find the two Numbers with Odd Occurrences in an Unsorted Array390
187Longest Common Prefix Using Binary Search II385
188Reverse a Singly Linked List (Iterative/Non-Recursive)383
189Check if String can Become Empty by Recursively Deleting given Substring380
190Caesar Cipher379
191Kth Non-repeating Character379
192Rearrange a linked list in Zig-Zag378
193Rotate Image by 90 degrees374
194Pancake Sorting374
195Longest Common Prefix Word by Word Matching371
196Permutations of a Given String Using STL371
197Perfect Reversible String368
198Merging Two Sorted Arrays364
199Sort a linked list with 0s, 1s and 2s362
200Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes362
201Find the point where a monotonically increasing function becomes positive first time362
202Find First non-repeating character in a string361
203Increasing Subsequence of Length three with Maximum Product361
2041`s and 2`s complement of binary number358
205Four Elements that Sum to Given355
206Delete N nodes after M354
207List items containing all characters of a given word352
208Count Number of Occurrences in a Sorted Array350
209Longest Common Prefix using Character by Character Matching349
210Split a string344
211Palindrome string (number)343
212Minimum Characters to be Removed to Make a Binary String Alternate340
213Recursive Implementation of atoi()336
214Check if a Linked list of Strings form a Palindrome333
215Print All Distinct Elements of the Array332
216Sorting the array of strings331
217Convert a String that is Repetition of a Substring of Length K331
218Maximum occurring character in a string329
219Valid Parentheses LeetCode Solution329
220Reverse a singly linked list recursively328
221Even Substring Count328
222Find the first Repeating Number in a Given Array326
223Can we reverse a linked list in less than O(n) time ?326
224Print Shortest Path to Print a String on Screen323
225Binary Tree to Doubly linked list323
226Reverse a String using Stack322
227Convert string1 to string2 in one edit321
228Maximum Subarray Leetcode Solution320
229wildcard character matching319
230Nth Character in Concatenated Decimal String319
231Sort Elements by Frequency II318
232Lower Case To Upper Case316
233Count the number of words313
234Split Four Distinct Strings311
235Merge Two Sorted Arrays311
236Find the Lost Element From a Duplicated Array310
237Find middle of the Linked List308
238Longest Common Subsequence with Permutations306
239Count the Pairs at Same Distance as in English Alphabets301
240Matrix Chain Multiplication using Dynamic Programming298
241Next Greater Element in an Array295
242Palindrome Permutation290
243Roman to Integer Leetcode Solution287
244Find Nth Node285
245Find All Pairs With a Given Difference284
246Searching a node in a Binary Search Tree283
247Triplet from three linked lists with given sum281
248Delete a Tree280
249String(represents an integer) to value280
250Reverse a String278
251Print all Possible Ways to Break a String in Bracket Form277
252Reverse Bits276
253Word Search Leetcode Solution275
254Binary Tree274
255Delete a node under given conditions273
256How to Efficiently Implement k Stacks in a Single Array?273
257Change Gender of a given String273
258Sort an array of strings272
259Meeting Rooms II LeetCode Solution270
260Count Pairs With Given Sum269
261Number of sub-strings which recursively add up to 9269
262Longest Common Extension268
263Repeated Substring Pattern268
264First non Repeating Element268
265Remove middle points in a linked list of line segments267
266Move all negative elements to one side of array265
267Toeplitz Matrix265
268Longest Palindromic Substring LeetCode Solution264
269Remove spaces from a string263
270Min Stack261
271Shuffle a given Array260
272N queen problem259
273Number of Islands LeetCode Solution254
274Cuckoo sequence program254
275Minimize the maximum difference between the heights253
276House Robber Leetcode Solution252
277Find, second, frequent, character252
278Dijkstra Algorithm252
279Clone a linked list with next and random pointer (Hashing)249
280Max stack249
281Most Frequent Element in an Array248
282Search Insert Position Leetcode Solution248
283Sort linked which is sorted on absolute values246
284Expression Evaluation245
285Subset Leetcode244
286KMP Algorithm244
287Valid Palindrome Leetcode Solution244
288Fibonacci numbers243
289Sudoku Solver242
290Reverse words in a string242
291Plus One Leetcode Solution242
292Number Of 1 bits242
293Min Stack Leetcode Solution242
294How to Delete a Linked List241
295Evaluation of Postfix Expression240
296Word Search239
297Combination Sum Leetcode Solution238
298Backspace String Compare234
299Merge Sorted Arrays Leetcode Solution234
300Sqrt(x) Leetcode Solution232
301Set Matrix Zeroes231
302Reversing a Queue231
303Subarray with 0 sum231
304Pair of Positive Negative Values in an Array230
305Contains Duplicate II Leetcode Solution229
306Rabin Karp Algorithm228
307Product of array except self228
308Tower Of Hanoi226
309Combination Sum226
310Common elements in all rows of a given matrix225
311Delete middle element of a stack225
312Integer to Roman Leetcode Solution224
313Pascal Triangle Leetcode224
314Intersection of Two Arrays II Leetcode Solution224
315String Compression223
316Minimum swaps required to bring all elements less than or equal to k together221
317Count subarrays with equal number of 1’s and 0’s221
318Reverse individual words221
319Find Top K (or Most Frequent) Numbers in a Stream219
320Single Number Leetcode Solution219
321Implementation of Deque using Doubly Linked List218
322Sliding Window Technique218
323Bellman Ford Algorithm218
324Arithmetic Expression Evaluation218
325Add Binary Leetcode Solution218
326Pow(x, n) Leetcode Solution217
327Count of index pairs with equal elements in an array217
328Construct Binary Tree from Given Inorder and Preorder Traversals217
329Segregate even and odd numbers217
330Contains Duplicate216
331Palindrome Linked List Leetcode Solution216
332Second Most Repeated Word in a Sequence216
333Count Odd Numbers in an Interval Range Leetcode Solution215
334Design a stack that supports getMin() in O(1) time and O(1) extra space215
335Third Maximum Number Leetcode Solution214
336Next Permutation214
337Postfix to Infix Conversion214
338Page Replacement Algorithms in Operating Systems214
339Minimum Value to Get Positive Step by Step Sum Leetcode Solution213
340Maximum Number of Balloons Leetcode Solution213
341Find sum of non-repeating elements (distinct) elements in an array212
342Kruskal Algorithm212
343Convex Hull Algorithm211
344K-th Smallest Element in a Sorted Matrix211
345Sort elements by frequency210
346Permutations Leetcode Solution210
347Group Words With Same Set of Characters210
348Find the Town Judge Leetcode Solution209
349Longest Substring Without Repeating Characters LeetCode Solution209
350Longest Common Prefix Leetcode Solution209
351Find Lucky Integer in an Array Leetcode Solution209
352Majority Element Leetcode Solution207
353Maximum Subarray207
354Sum of minimum and maximum elements of all subarrays of size k207
355Spiral Matrix LeetCode Solution207
356Top K Frequent Words206
357Evaluate Division206
358Find Numbers with Even Number of Digits Leetcode Solution206
359Scramble String205
360Prefix to Infix Conversion205
361Minimum operation to make all elements equal in array205
362Sorting array using Stacks205
363First element occurring k times in an array204
364Minimum Path Sum204
365Number of Good Pairs Leetcode Solution204
366Count subarrays having total distinct elements same as original array204
367Swap Nodes in Pairs Leetcode Solutions204
368Smallest Subarray with k Distinct Numbers204
369Special Number203
370Count Primes Leetcode Solutions203
371Given two unsorted arrays find all pairs whose sum is x203
372Best Time to Buy and Sell Stock  II Leetcode Solution202
373Missing Number Leetcode Solution202
374Merge Two Sorted Lists Leetcode Solutions202
375Power of Two Leetcode Solution202
376Check if two arrays are equal or not202
377Pascal’s Triangle II Leetcode Solution201
378Sort Array by Increasing Frequency Leetcode Solution201
379Search in Rotated Sorted Array Leetcode Solution201
380Reverse a Number Using Stack200
381Huffman Coding200
382Find All Numbers Disappeared in an Array Leetcode Solution200
383House Robber II Leetcode Solution199
384Fizz Buzz Leetcode199
385Minimum Steps to reach target by a Knight199
386Reversing the First K elements of a Queue198
387Top K Frequent Elements198
388Minimum Absolute Difference Leetcode Solution198
389Maximal Square198
390Unique Paths Leetcode Solution198
391Running Sum of 1d Array Leetcode Solution198
392Group Anagrams198
393Matrix Diagonal Sum Leetcode Solution197
394Leetcode Permutations197
395Find duplicates in a given array when elements are not limited to a range197
396Coin Change 2 Leetcode Solution197
397How to Implement Stack Using Priority Queue or Heap?197
398Maximum possible difference of two subsets of an array197
399Single Number196
400Find Minimum In Rotated Sorted Array196
401Sort Integers by The Number of 1 Bit Leetcode Solution196
402How Many Numbers Are Smaller Than the Current Number Leetcode Solution196
403Range Sum Query 2D – Immutable Leetcode Solution196
404Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution195
405Maximum Distance Between two Occurrences of Same Element in Array195
406Happy Number Leetcode Solution195
407Max Consecutive Ones Leetcode Solution195
408Find Number of Employees Under every Employee195
409Expression Contains Redundant Bracket or Not195
410Zigzag Conversion195
411Sorting using trivial hash function194
412Decode String194
413Check if Array Contains Contiguous Integers With Duplicates Allowed194
414Unique Paths193
415Remove Duplicates from Sorted Array Leetcode Solution193
416Convert String To Int193
417Subarray Sum Equals K LeetCode Solution193
418Subarray Sum Equals k193
419Find The Duplicate Number193
420Best Time to Buy and Sell Stock III Leetcode Solution192
421Length of the largest subarray with contiguous elements192
422Difference between highest and least frequencies in an array192
423Smallest Element Repeated Exactly K Times192
424Fibonacci Number LeetCode Solution192
425Find the Closest Palindrome number192
426Implement Stack and Queue using Deque192
427Reverse Vowels of a String Leetcode Solution192
428Reverse Integer192
429Subtract the Product and Sum of Digits of an Integer Leetcode Solution191
430Find Winner on a Tic Tac Toe Game Leetcode Solution191
431Subset sum problem191
432Check If N and Its Double Exist Leetcode Solution191
433Shuffle the Array Leetcode Solution190
434Reverse a Stack Using Recursion190
435Find Median from data Stream190
436Monotonic Array LeetCode Solution190
437Maximum Depth of Binary Tree Leetcode Solution190
438Nth Catalan Number189
439Find top three repeated in array189
440Trapping Rain Water Leetcode Solution189
441Delete a Node from linked list without head pointer189
442Kth largest element in an Array Leetcode Solutions189
443Cumulative Frequency of Count of Each Element in an Unsorted Array189
444LRU Cache Implementation189
445Palindrome Substring Queries189
446Count Substrings with equal number of 0s, 1s and 2s188
447Find the Duplicate Element188
448Subarrays with distinct elements188
449Letter Case Permutation188
450Reverse Words in a String III LeetCode Solution188
451Generate a String With Characters That Have Odd Counts Leetcode Solution188
452Print All Distinct Elements of a Given Integer Array188
453Capacity To Ship Packages Within D Days Leetcode Solution188
454Priority Queue Using Singly Linked List187
455The K Weakest Rows in a Matrix Leetcode Solution187
456Integer to English words187
457Sort a stack using recursion187
458Minimum Moves to Equal Array Elements Leetcode Solution187
459Find the first repeating element in an array of integers186
460Find all pairs (a, b) in an array such that a % b = k186
461Sorting a Queue without Extra Space186
462Bipartite Graph186
463Excel Sheet Column Number Leetcode Solution186
464Find Common Characters Leetcode Solution186
465Iterative Tower of Hanoi185
466Count pairs from two linked lists whose sum is equal to a given value185
467Next Greater Element I Leetcode Solution185
468Longest Common Subsequence185
469Floyd Warshall Algorithm185
470Target Sum185
471Find First and Last Position of Element in Sorted Array Leetcode Solution185
472Word Ladder LeetCode Solution185
473Merge Two Sorted Linked Lists185
474Concatenation of Array LeetCode Solution185
475Fizz Buzz185
476Balanced Binary Tree Leetcode Solution184
477Text Justification LeetCode Solution184
478Reverse a String184
479Multiply Strings Leetcode Solution184
480Prim’s Algorithm184
481Find elements which are present in first array and not in second184
482Edit Distance183
483Merge Overlapping Intervals183
484Print all subarrays with 0 sum183
485Kids With the Greatest Number of Candies Leetcode Solution183
486Find the Difference Leetcode Solution183
487Degree of an array182
488Reverse a linked list182
489Kth Largest Element in a Stream Leetcode Solution182
490Remove Minimum Number of Elements Such That no Common Element Exist in both Array182
491Flood Fill LeetCode182
492Move Zeroes LeetCode Solution182
493Count and Say182
494Slowest Key Leetcode Solution182
495Sum of Subarray Ranges Leetcode Solution182
496Zigzag Conversion LeetCode Solution182
497Number of Steps to Reduce a Number to Zero Leetcode Solution182
498Length of Last Word Leetcode Solution181
499Top View of Binary Tree181
500Implement a stack using single queue181
501Longest Common Prefix using Trie181
502MiniMax Algorithm181
503Design Parking System Leetcode Solution181
504Substring With Concatenation Of All Words180
505Intersection of Two Arrays180
506Jump Game Leetcode Solution180
507Find subarray with given sum (Handles Negative Numbers)179
508Valid Parenthesis String179
509Peak Index in a Mountain Array179
510Convert array into Zig-Zag fashion179
511The Stock Span Problem179
512Max Area of Island179
513Count and Say Leetcode Solution179
514Pair with given product179
515Last Stone Weight178
516Mobile Numeric Keypad Problem178
517Find four elements that sum to a given value (Hashmap)178
518Priority Queue in C++178
519Contiguous Array Leetcode178
520Postfix to Prefix Conversion178
521Find N Unique Integers Sum up to Zero Leetcode Solution178
522Longest subarray not having more than K distinct elements178
523Delete Node in a Linked List Leetcode Solution177
524N-th Tribonacci Number Leetcode Solution177
525Koko Eating Bananas Leetcode Solution177
526Relative Sort Array Leetcode Solution177
527Shuffle String Leetcode Solution177
528Check if a given array contains duplicate elements within k distance from each other177
529Prefix to Postfix Conversion177
530Longest Common Prefix using Sorting177
531Find missing elements of a range177
532Shortest Palindrome176
533Find Index of Closing Bracket for a Given Opening Bracket in an Expression176
534Largest Perimeter Triangle Leetcode Solution176
535Isomorphic Strings Leetcode Solution175
536Find distinct elements common to all rows of a matrix175
537Iterative Inorder Traversal of a Binary Tree175
538K-th Distinct Element in an Array175
539Find any one of the multiple repeating elements in read only array175
540Best Time to Buy and Sell Stock175
541Container with Most Water174
542Build Array From Permutation Leetcode Solution174
54301 Matrix LeetCode Solution174
544Count number of triplets with product equal to given number174
545Implement Stack using Queues174
546Excel Sheet Column Title Leetcode Solution174
547Implementation of Deque using circular array174
548Minimum Operations to convert X to Y174
549First negative integer in every window of size k174
550Jewels and Stones Leetcode Solution174
551Recursion174
552Smallest Subarray With all Occurrences of a Most Frequent Element174
553Is Subsequence Leetcode Solution174
554Change the Array into Permutation of Numbers From 1 to N174
555Distribute Candies to People Leetcode Solution174
556Hamming Distance173
557Valid Anagrams173
558Convert Sorted Array to Binary Search Tree Leetcode Solution173
559Linked List Cycle II LeetCode Solution173
560Island Perimeter Leetcode Solution173
561Valid Sudoku173
562Maximum sum rectangle in a 2D matrix173
563Remove Linked List Elements Leetcode Solution173
564Convert a normal BST to Balanced BST173
565Find the smallest positive integer value that cannot be represented as sum of any subset of a given array172
566Rotate List Leetcode Solution172
567Sum of Left Leaves Leetcode Solutions172
568Next Greater Frequency Element172
569Shuffle an Array172
570Insert Interval Leetcode Solution171
571Assign Cookies Leetcode Solution171
572Minimum Delete Operations to make all Elements of Array Same171
573Arrange given numbers to form the biggest number171
574Check for Balanced Parentheses in an Expression171
575Group Multiple Occurrence of Array Elements Ordered by first Occurrence171
576Gold Mine Problem171
577Minimum Bracket Reversals171
578Trapping Rain Water LeetCode Solution171
579Summary Ranges Leetcode Solution171
580Count the number of nodes at given level in a tree using BFS171
581Find Words That Can Be Formed by Characters Leetcode Solution171
5823Sum Closest LeetCode Solution170
583Shortest Path in a Grid with Obstacles Elimination LeetCode Solution170
584Minimum number of distinct elements after removing m items170
585Count all subsequences having product less than K170
586Rotate Image LeetCode Solution170
587Maximum Number of Chocolates to be Distributed Equally Among k Students170
588Integer to Roman170
589Rearrange a binary string as alternate x and y occurrences170
590Maximum path sum in a triangle170
591LRU Cache LeetCode Solution169
592Maximum Distance in Array169
593Permutation in String Leetcode Solution169
594Distance Between Bus Stops Leetcode Solution169
595The Knapsack Problem169
596Combinations Leetcode Solution169
597Unique Binary Search Trees169
598Same Tree LeetCode Solution168
599Minimum Knight Moves LeetCode Solution168
600How to check if two given sets are disjoint?168
601Decode Ways168
602Stone Game LeetCode168
603K Empty Slots LeetCode168
604Remove All Occurrences of a Substring LeetCode Solution167
605Printing brackets in Matrix Chain Multiplication Problem167
606Segregate 0s and 1s in an Array167
607Find the Duplicate Number LeetCode Solution167
608XOR Operation in an Array Leetcode Solution167
609Sieve of Eratosthenes167
610Replace Elements with Greatest Element on Right Side Leetcode Solution167
611Distance of nearest cell having 1 in a binary matrix167
612Word Wrap Problem166
613Best Time to Buy and Sell Stock LeetCode Solution166
614Sort Array By Parity LeetCode Solution166
615License Key Formatting Leetcode Solution166
616Find if an Expression has Duplicate Parenthesis or Not166
617Find Sum of all unique sub-array sum for a given array166
618Sort Characters By Frequency LeetCode Solution166
619Minimum number of subsets with distinct elements165
620Frog Jump Leetcode Solution165
621Painting Fence Algorithm165
622Find minimum difference between any two elements165
623Maximum difference between first and last indexes of an element in array165
624Applications of Breadth First Search and Depth First Search165
625Minimum insertions to form a palindrome with permutations allowed165
626Word Pattern165
627Defanging an IP Address Leetcode Solution164
628Smallest Good Base164
629Maximum Consecutive Numbers Present in an Array164
630House Robber164
631Longest Substring with At Most K Distinct Characters LeetCode Solution163
632Tracking current Maximum Element in a Stack163
633Queries for counts of array elements with values in given range163
634Find Maximum Level sum in Binary Tree163
635Minimum Depth of Binary Tree Leetcode Solution163
636Binary Tree Zigzag Level Order Traversal LeetCode Solution163
637Coin Change Problem163
638Find pairs with given sum such that elements of pair are in different rows163
639Check If It Is a Straight Line Leetcode Solution163
640Best Time to Buy and Sell Stock with Cooldown Leetcode Solution163
641GCD Of Two Numbers163
642Maximum Number of Coins You Can Get Leetcode Solution162
643Optimal Account Balancing LeetCode Solution162
644Iterative Method to find Height of Binary Tree162
645Minimum Cost to Hire K Workers162
646Isomorphic Strings162
647Valid Palindrome II Leetcode Solution162
648Letter Combinations of a Phone Number162
649Kth Missing Positive Number Leetcode Solution162
650Employee Free Time LeetCode Solution162
651Strobogrammatic Number LeetCode Solution162
652Print the Fibonacci numbers in reverse order162
653Non-overlapping sum of two sets162
654Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
655Power of Four Leetcode Solution161
656Delete consecutive same words in a sequence161
657Merge Two Balanced Binary Search Trees161
658Wiggle Sort161
659Maximum Number of Occurrences of a Substring Leetcode Solution161
660Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions161
661Number of Provinces Leetcode Solution161
662Longest Increasing Subsequence161
663Longest Substring with At Least K Repeating Characters LeetCode Solution161
664Count Good Nodes in Binary Tree Leetcode Solution161
665Sum of All Odd Length Subarrays Leetcode Solution161
666Number of Dice Rolls With Target Sum LeetCode Solution160
667Ugly Number Leetcode Solution160
668Reverse a stack without using extra space in O(n)160
669K Empty Slots160
670Longest Increasing Path in a Matrix LeetCode Solution160
671Partition Labels LeetCode Solution160
672Moving Average from Data Stream Leetcode Solution160
673Sort Array by Increasing Frequency Leetcode Solution159
674Form minimum number from given sequence159
675Find the Distance Value Between Two Arrays Leetcode Solution159
676Reversing a Queue using Recursion159
677BFS vs DFS for Binary Tree159
678Convert an array to reduced form159
679Reverse Only Letters LeetCode Solution159
680Find Leaves of Binary Tree LeetCode Solution159
681Check If Two String Arrays are Equivalent Leetcode Solution159
682Valid Perfect Square Leetcode Solution159
683Reducing Dishes LeetCode Solution158
684Flipping an Image LeetCode Solution158
685Check if a queue can be sorted into another queue using a stack158
686Largest Sum Contiguous Subarray158
687Path With Maximum Minimum Value LeetCode Solution158
688String to Integer (atoi) LeetCode Solution158
689Find the Smallest Divisor given a Threshold Leetcode Solution158
690To Lower Case Leetcode Solution158
691Unique Paths II Leetcode Solution158
692Remove Invalid Parentheses Leetcode Solution158
693Maximum Product of Two Elements in an Array Leetcode Solution158
694Edit Distance LeetCode Solution158
695How to Create Mergable Stack?157
696Populating Next Right Pointers in Each Node157
697Binary Tree zigzag level order Traversal157
698Recover Binary Search Tree157
699Construct BST from given Preorder Traversal157
700Reservoir Sampling157
701Dynamic Programming Basics157
702Reorganize String157
703Convert a Number to Hexadecimal Leetcode Solution157
704Find whether an array is subset of another array157
705Delete Nth node from the end of the given linked list157
706Find Largest d in Array such that a + b + c = d157
707Sum of f(a[i], a[j]) over all pairs in an array of n integers157
708Robot Room Cleaner Leetcode Solution157
709Permutation Sequence LeetCode Solution157
710Subset Sum Leetcode157
711Merge Two Binary Trees LeetCode Solution157
712Increasing Decreasing String Leetcode Solution157
713Inorder Successor of a node in Binary Tree157
714Lucky Numbers in a Matrix Leetcode Solution157
715Minimum Cost For Tickets Leetcode Solution156
716Partition Array Into Three Parts With Equal Sum Leetcode Solution156
717Restore IP Addresses Leetcode Solution156
718Majority Element II Leetcode Solution156
719Factorial Trailing Zeroes Leetcode Solution156
720Keyboard Row Leetcode Solution156
721Find the node with minimum value in a Binary Search Tree156
722Valid Palindrome156
723Decompress Run-Length Encoded List Leetcode Solution155
724Add and Search Word – Data structure design LeetCode155
725Bulb Switcher LeetCode Solution155
726Maximum Product of Three Numbers LeetCode Solution154
727Search a 2D Matrix II Leetcode Solution154
728Student Attendance Record I Leetcode Solution154
729Maximum 69 Number Leetcode Solution154
730Hamming Distance Leetcode Solution154
731Rank Transform of an Array Leetcode Solution154
732Finding K closest element154
733First Unique Character in a String LeetCode Solution154
734Diagonal Traversal of Binary Tree153
735Find unique character in a string153
736Numbers with prime frequencies greater than or equal to k153
737Minimum Distance Between BST Nodes Leetcode Solution153
738Morris Traversal153
739Sorted Linked List to Balanced BST153
740Symmetric Tree Leetcode Solution153
741Bubble sort using two Stacks153
742Evaluate Reverse Polish Notation LeetCode Solution153
743Word Pattern LeetCode Solution153
744Stack Permutations (Check if an array is stack permutation of other)153
745Find the largest multiple of 3153
746String Compression LeetCode Solution153
747Invert Binary Tree LeetCode Solution153
748Queue based approach for first non-repeating character in a stream153
749Find Median from Data Stream LeetCode Solution153
750Maximum Depth of N-ary Tree Leetcode Solution153
751Jump Game152
752Deletion in a Binary Tree152
753Perform String Shifts Leetcode152
754Search in a Binary Search Tree Leetcode Solution152
755Largest rectangular sub-matrix whose sum is 0152
756Minimum Height Trees152
757Largest subarray with equal number of 0s and 1s152
758Longest Span with same Sum in two Binary arrays152
759Generate all possible sorted arrays from alternate elements of two given sorted arrays152
760Non-decreasing Array LeetCode Solution152
761Number of Islands II LeetCode Solution152
762Snakes and Ladders LeetCode Solution152
763Binary Tree Maximum Path Sum LeetCode Solution152
764Elements to be added so that all elements of a range are present in array152
765Maximum Length of a Concatenated String with Unique Characters Leetcode Solution152
766Find All Duplicates in an Array LeetCode Solution152
767Best Meeting Point LeetCode Solution152
768Largest Rectangle in Histogram LeetCode Solution152
769Binomial Coefficient152
770Maximum Difference Between Increasing Elements LeetCode Solution151
771Find Maximum Depth of Nested Parenthesis in a String151
772Remove Duplicates from Sorted List LeetCode Solution151
773Race Car LeetCode Solution151
774Check If Array Pairs Are Divisible by k LeetCode Solution151
775Kth ancestor of a node in binary tree151
776Merge K Sorted Linked Lists151
777Split a String in Balanced Strings Leetcode Solution151
778N-Queens LeetCode Solution151
779Remove Nth Node From End of List Leetcode Solution151
780k-th missing element in increasing sequence which is not present in a given sequence151
781Linked List Cycle151
782Minimize Maximum Pair Sum in Array LeetCode Solution150
783Count quadruples from four sorted arrays whose sum is equal to a given value x150
784Minimum number of jumps to reach end150
785Find Pair with Greatest Product in Array150
786Transpose Graph150
787Special Array With X Elements Greater Than or Equal X Leetcode Solution150
788Crawler Log Folder Leetcode Solution150
789Find if Path Exists in Graph Leetcode Solution150
790Final Prices With a Special Discount in a Shop Leetcode Solution150
791Number of NGEs to the Right149
792Alien Dictionary LeetCode Solution149
793Can Place Flowers LeetCode Solution149
794Relative Ranks Leetcode Solution149
795Merge Sorted Array LeetCode Solution149
796Growable array based stack149
797Tiling Problem149
798Nearest Exit from Entrance in Maze LeetCode Solution149
799Interval Tree148
800Nested List Weight Sum II LeetCode Solution148
801Valid Number148
802Check if a given array can represent Preorder Traversal of Binary Search Tree148
803Print a Binary Tree in Vertical Order148
804Sort an array according to the order defined by another array148
805Remove brackets from an algebraic string containing + and – operators148
806Convert BST to Min Heap148
807Check if Two Expressions With Brackets are Same148
808Minimum Time Visiting All Points Leetcode Solution148
809Iterative Preorder Traversal148
810Check for Palindrome after every character replacement Query148
811Minimum Jumps to Reach Home LeetCode Solution148
812Program for Bridge and Torch problem148
813Number Complement Leetcode Solution148
814Remove Duplicates from Sorted List II148
815String comparison containing wildcards148
816Get Maximum in Generated Array Leetcode Solution148
817Minimum time required to rot all oranges148
818Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution147
819Reorder Data in Log Files LeetCode Solution147
820Partition to K Equal Sum Subsets Leetcode Solution147
821Total Numbers With no Repeated Digits in a Range147
822Find the Only Repetitive Element Between 1 to N-1147
823Sort Array By Parity II Leetcode Solution147
824Top K Frequent Words LeetCode Solution147
825One Edit Distance LeetCode Solution147
826Regular Expression Matching147
827Subarray Product Less Than K LeetCode Solution147
828Maximum size subarray sum equals k147
829Design a Stack With Increment Operation Leetcode Solution147
830Sort Colors147
831Minimum swaps to make sequences increasing147
832Maximum Profit in Job Scheduling Leetcode Solution147
833Base 7 Leetcode Solution147
834A Space Optimized DP solution for 0-1 Knapsack Problem147
835Friends Pairing Problem147
836Count items common to both the lists but with different prices147
837Priority Queue using doubly linked list147
838Circular Queue146
839Path with maximum average value146
840Longest Subarray Having Count of 1s One More than Count of 0s146
841Minimum Number of Taps to Open to Water a Garden LeetCode Solution146
842Given an Array of Pairs Find all Symmetric Pairs in it145
843Guess Number Higher or Lower LeetCode Solution145
844Repeated Substring Pattern LeetCode Solution145
845Subsequence of Size K With the Largest Even Sum LeetCode Solution145
846Sorted Array to Balanced BST145
847Union and Intersection of two Linked Lists145
848Binary Search Tree Search and Insertion145
849Subset with sum divisible by m145
850Brightest Position on Street LeetCode Solution145
851Count Distinct Elements in Every Window of Size K145
852Clone Graph LeetCode Solution145
853Find the subarray with least average145
854Partition List Leetcode Solution145
855Find All Possible Recipes from Given Supplies LeetCode Solution144
856Tree Traversal (Preorder, Inorder & Postorder)144
857Minimum Swaps to Make Strings Equal Leetcode Solution144
858Minimum Sum Path in a Triangle144
859Permutation Coefficient144
860Course Schedule II – LeetCode144
861Sum of nearest smaller and greater number144
862Last Stone Weight II LeetCode Solution144
863Valid Parentheses Leetcode Solution144
864Insert into a Binary Search Tree Leetcode Solution144
865Level order Traversal in Spiral Form144
866Three way partitioning of an array around a given range144
867Check if an Array is Stack Sortable144
868Find all triplets with zero sum144
869Brick Wall LeetCode Solution144
870Maximum Nesting Depth of the Parentheses Leetcode Solution144
871Water Bottles Leetcode Solution143
872Count ways to reach the nth stair using step 1, 2 or 3143
873Rearrange Spaces Between Words Leetcode Solution143
874Check whether a given Binary Tree is Complete or not143
875Daily Temperatures Leetcode Solution143
876Distinct adjacent elements in an array143
877GCDs of given index ranges in an array142
878Minimum sum of multiplications of n numbers142
879Guess Number Higher or Lower II142
880Balanced Expression with Replacement142
881Sequences of given length where every element is more than or equal to twice of previous142
882Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution142
8834Sum142
884Lemonade Change Leetcode Solution142
885Destination City Leetcode Solution142
886LCS (Longest Common Subsequence) of three strings142
887Matrix Chain Multiplication142
888An Interesting Method to generate Binary Numbers from 1 to n142
889Robot Bounded In Circle LeetCode Solution142
890Missing Element in Sorted Array LeetCode Solution142
891Form Minimum Number From Given Sequence142
892Count Negative Numbers in a Sorted Matrix LeetCode Solution142
893Range sum queries without updates142
894Spiral Matrix II Leetcode Solution142
895Number of Days Between Two Dates LeetCode Solution142
896Identify and Mark Unmatched Parenthesis in an Expression142
897Least Number of Unique Integers after K Removals Leetcode Solution142
898Delete And Earn141
899Design Browser History LeetCode Solution141
900BFS for Disconnected Graph141
901Queries for GCD of all numbers of an array except elements in a given range141
902Palindrome Partitioning Leetcode Solution141
903Strongly Connected Component140
904Intersection of Two Linked Lists LeetCode Solution140
905Shortest Word Distance Leetcode Solution140
906Maximum Score After Splitting a String Leetcode Solution140
907Special Positions in a Binary Matrix Leetcode Solution140
908Time Based Key-Value Store LeetCode Solution140
909Check if the given array can represent Level Order Traversal of Binary Search Tree140
910Find Maximum Sum Possible Equal Sum of Three Stacks140
911Spiral Matrix III LeetCode Solution140
912Find all permuted rows of a given row in a matrix140
913Count Subarrays with Same Even and Odd Elements140
914Remove Duplicates from Sorted List II LeetCode Solution140
915Convert Sorted List to Binary Search Tree140
916Diagonal Traversal LeetCode Solution140
917Find distance between two nodes of a Binary Tree140
918Construct Complete Binary Tree from its Linked List Representation140
919Insert Delete GetRandom140
920Construct BST from its given Level Order Traversal139
921A program to check if a binary tree is BST or not139
922Lexicographical Numbers Leetcode Solution139
923Number of Distinct Islands Leetcode Solution139
924Set Matrix Zeroes Leetcode Solution139
925Rearrange an Array Such that arr[i] is equal to i139
926Check if stack elements are pairwise consecutive139
927Diagonal Traverse LeetCode Solution139
928Find Common Characters Leetcode Solution139
929Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i139
930Trim a Binary Search Tree139
931Merge Two Sorted Lists Leetcode139
932Alien Dictionary139
933Construct the Rectangle Leetcode Solution138
934Print Fibonacci sequence using 2 variables138
9353 Sum138
936Collect maximum points in a grid using two traversals138
937K’th Largest Element in BST when modification to BST is not allowed138
938Maximum Frequency Stack Leetcode Solution138
939Iterative Postorder Traversal Using Two Stacks138
940Longest Palindromic Subsequence138
941Range LCM Queries138
942Merging Intervals138
943Word Break138
944Vertical sum in a given binary tree138
945Analyze User Website Visit Pattern LeetCode Solution138
946Count pair with Given Sum137
947Three Consecutive Odds Leetcode Solution137
948Stone Game II Leetcode137
949Count Submatrices With All Ones LeetCode Solution137
950Infix to Postfix137
951All Unique Triplets that Sum up to a Given Value137
952Can Make Arithmetic Progression From Sequence Leetcode Solution137
953Queue using Stacks137
954Longest Nice Substring LeetCode Solution137
955Find postorder traversal of BST from preorder traversal136
956Binary Tree Longest Consecutive Sequence LeetCode Solution136
957Palindrome Partitioning136
958Reverse Nodes in K-Group136
959Maximum Subarray Sum Excluding Certain Elements136
960Sliding Window Maximum136
961Difference Array | Range update query in O(1)136
962Number of Equivalent Domino Pairs Leetcode Solution136
963Level order traversal using two Queues136
964Product of Array Except Self LeetCode Solution136
965Averages of Levels in Binary Tree136
966Minimum Height Trees LeetCode Solution136
967Maximize Sum of Array after K Negations Leetcode Solution136
968Dividing Array into Pairs With Sum Divisible by K136
969Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space136
970Largest area rectangular sub-matrix with equal number of 1’s and 0’s136
971Asteroid Collision LeetCode Solution135
972Breadth First Search (BFS) for a Graph135
973Largest divisible pairs subset135
974Binary array after M range toggle operations135
975K Closest Points to Origin Leetcode Solution135
976Split Array Into Consecutive Subsequences135
977Maximum Product of Indexes of Next Greater on Left and Right135
978Create Maximum Number135
979Count Primes in Ranges135
980Check if any two intervals overlap among a given set of intervals135
981Median of Two Sorted Arrays135
982Pattern Occurrences using Stack135
983Kth Smallest Element in a BST Leetcode Solution134
984The Maze III LeetCode Solution134
985Symmetric Tree134
986Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution134
987Maximum Product Subarray134
988Height of a generic tree from parent array134
989Segment Tree134
990Maximum subsequence sum such that no three are consecutive134
991Level Order Traversal of Binary Tree134
992Largest Substring Between Two Equal Characters Leetcode Solution134
993Newman-Conway Sequence134
994Find Maximum of Minimum for Every Window Size in a Given Array134
995Minesweeper LeetCode Solution134
996Length of Longest Fibonacci Subsequence133
997Find Duplicate Subtrees133
998Unique Paths II133
999Serialize and Deserialize Binary Tree133
1000Friends Of Appropriate Ages LeetCode Solution133
1001Decrypt String from Alphabet to Integer Mapping Leetcode Solution133
1002Binary Search Tree Delete Operation133
1003Rearrange array such that even positioned are greater than odd133
1004Find the Difference Leetcode Solution133
1005Next Greater Element III LeetCode Solution133
1006First missing positive133
1007Maximum Number of Ways to Partition an Array LeetCode Solution133
1008Build an Array With Stack Operations Leetcode Solution133
1009Kill Process LeetCode Solution133
1010The Painter’s Partition Problem133
1011Sign of the Product of an Array LeetCode Solution133
1012Maximum Length of Repeated Subarray133
1013Depth First Search (DFS) for a Graph133
1014Super Ugly Number132
1015Climbing stairs132
1016Insertion in a Binary Tree132
1017Graph Valid Tree LeetCode Solution132
1018Find number of pairs in an array such that their XOR is 0132
1019Balanced Binary Tree132
1020Longest subsequence such that difference between adjacents is one132
1021Find the First Circular Tour that visits all the Petrol Pumps132
1022My Calendar I LeetCode Solution132
1023Design Hit Counter LeetCode Solution132
1024Boundary Traversal of binary tree132
1025Number Of Longest Increasing Subsequence132
1026Count subarrays where second highest lie before highest132
1027Validate Binary Search Tree131
1028Make The String Great Leetcode Solution131
1029Morris Inorder Traversal131
1030Advantages of BST over Hash Table131
1031Valid Boomerang Leetcode Solution131
1032Move all negative elements to end in order with extra space allowed131
1033Partition Equal Subset Sum131
1034Largest Number Leetcode Solution131
1035Double the first element and move zero to end131
1036Construct Binary Tree from given Parent Array representation131
1037Implement Trie (Prefix Tree) Leetcode Solution130
1038Recover Binary Search Tree Leetcode Solution130
1039Add two numbers130
1040Ugly Numbers130
1041Compute nCr % p130
1042Boolean Parenthesization Problem130
1043Shortest Completing Word Leetcode Solution130
1044Maximum difference between frequency of two elements such that element having greater frequency is also greater129
1045Employee Importance LeetCode Solution129
1046Bitwise AND of Numbers Range LeetCode Solution129
1047String Matching in an Array Leetcode Solution129
1048Ugly Number II LeetCode Solution129
1049Binary Search Tree129
1050Generate Parentheses Leetcode Solution129
1051Available Captures for Rook Leetcode Solution129
1052Minimum Index Sum of Two Lists129
1053Kth Smallest Element in a Sorted Matrix LeetCode Solution129
1054Minimum Size Subarray Sum129
1055Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’129
1056Count minimum steps to get the given desired array129
1057Invalid Transactions LeetCode Solution128
1058Find Peak Element128
1059Number of palindromic paths in a matrix128
1060Find a Peak Element II LeetCode Solution128
1061Combination Sum IV LeetCode Solution128
1062Find whether a subarray is in form of a mountain or not128
1063Populating Next Right Pointers in Each Node Leetcode Solution128
1064Count pairs from two sorted arrays whose sum is equal to a given value x128
1065Increasing Triplet Subsequence LeetCode Solution128
1066Maximum Sum of 3 Non-Overlapping Subarrays128
1067Longest Bitonic Subsequence128
1068Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution128
1069Scramble String LeetCode Solution128
1070Binary Tree Right Side View LeetCode Solution128
1071Maximize Distance to Closest Person LeetCode Solution128
1072Defanging an IP Address LeetCode Solution128
1073Maximum length subsequence with difference between adjacent elements as either 0 or 1128
1074Construction of Longest Increasing Subsequence (N log N)128
1075Constant time range add operation on an array127
1076Maximum weight transformation of a given string127
1077Remove Palindromic Subsequences Leetcode Solution127
1078Regular Expression Matching Regular Expression Matching LeetCode Solution127
1079Clone a Binary Tree with Random Pointers127
1080Number of Students Doing Homework at a Given Time Leetcode Solution127
1081Path Sum II LeetCode Solution127
1082Iterative Depth First Traversal of Graph127
1083Search in Sorted Rotated Array127
1084Lowest Common Ancestor127
1085Find Three Element From Different Three Arrays Such That a + b + c = sum126
1086Number of Closed Islands Leetcode Solution126
1087Smallest Common Region Leetcode Solution126
1088Remove Duplicates from Sorted Array II Leetcode Solution126
1089Find the minimum distance between two numbers126
1090Custom Sort String Leetcode Solution126
1091Divisible Pairs Counting126
1092Day of the Year Leetcode Solution126
1093Write Code to Determine if Two Trees are Identical125
1094Find Smallest Range Containing Elements from k Lists125
1095Print all triplets in sorted array that form AP125
1096Rearrange array such that even index elements are smaller and odd index elements are greater125
1097Kth Smallest Product of Two Sorted Arrays LeetCode Solution125
1098Number of siblings of a given Node in n-ary Tree125
1099Find maximum difference between nearest left and right smaller elements125
1100Serialize and Deserialize Binary Tree LeetCode Solution125
1101Largest BST Subtree LeetCode Solution125
1102Next Permutation Leetcode Solution125
1103Print Next Greater Number of Q queries125
1104Path Sum125
1105Distinct Subsequences125
1106Types of Binary Tree125
1107Binary Tree Data Structure125
1108Consecutive Characters LeetCode Solution124
1109Minimum Absolute Difference in BST Leetcode Solution124
1110Bottom View of a Binary Tree124
1111Root to Leaf path with target sum Leetcode Solutions124
1112Subarrays with K Different Integers Leetcode Solution124
1113Level of Each node in a Tree from source node124
1114Remove duplicates from sorted array123
1115Cells with Odd Values in a Matrix LeetCode Solution123
1116Longest Subarray of 1’s After Deleting One Element LeetCode Solution123
1117Topological Sorting123
1118Products of ranges in an array123
1119Print Right View of a Binary Tree123
1120Cutting a Rod123
1121Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution123
1122Third Maximum Number Leetcode Solution123
1123Subset Sum Problem in O(sum) space123
1124Closest Binary Search Tree Value Leetcode Solution122
1125Maximum Binary Tree122
1126K maximum sums of overlapping contiguous sub-arrays122
1127Maximum Product Subarray122
1128Reformat The String Leetcode Solution122
1129Convert BST into a Min-Heap without using array122
1130Palindrome Permutation LeetCode Solution122
1131Queries for Number of Distinct Elements in a Subarray122
1132Count Largest Group Leetcode Solution121
1133Search an Element in Sorted Rotated Array121
1134Iterative method to find ancestors of a given binary tree121
1135Diameter of N-Ary Tree LeetCode Solution121
1136Prime Palindrome LeetCode Solution121
1137Minimum Score Triangulation of Polygon Leetcode Solution121
1138Valid Tic-Tac-Toe State LeetCode Solution121
1139Print modified array after executing the commands of addition and subtraction121
1140Mean of Array After Removing Some Elements Leetcode Solution121
1141Find a sorted subsequence of size 3 in linear time120
1142Sum of Even Numbers After Queries120
1143Moser-de Bruijn Sequence120
1144Kth Smallest Number in Multiplication Table Leetcode Solution120
1145Search Insert Position120
1146Construct K Palindrome Strings LeetCode Solution120
1147Golomb sequence120
1148Minimum sum of squares of character counts in a given string after removing k characters120
1149Thousand Separator Leetcode Solution120
1150Red-Black Tree Introduction119
1151Factorial Trailing Zeroes LeetCode Solution119
1152Merge two BSTs with limited extra space119
1153Check Array Formation Through Concatenation Leetcode Solution119
1154Longest Increasing Consecutive Subsequence119
1155Find maximum length Snake sequence119
1156Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution119
1157Maximum Product of Splitted Binary Tree LeetCode Solution118
1158Possible Bipartition LeetCode Solution118
1159Compare Strings by Frequency of the Smallest Character Leetcode Solution118
1160Find the smallest binary digit multiple of given number118
1161Palindromic Substrings Leetcode Solution118
1162Swapping Nodes in a Linked List Leetcode Solution118
1163Binary Tree to Binary Search Tree Conversion118
1164Delete Nodes and Return Forest Leetcode Solution118
1165Bus Routes Leetcode Solution118
1166Decrease Elements To Make Array Zigzag LeetCode Solution118
1167Transform a BST to Greater sum Tree118
1168Minimum Sideway Jumps LeetCode Solution118
1169Longest Repeated Subsequence117
1170Number of Orders in the Backlog Leetcode Solution117
1171Swap Nodes In Pairs117
1172Rotate Array117
1173Count even length binary sequences with same sum of first and second half bits117
1174Minimum Moves to Equal Array Elements LeetCode Solution117
1175Count Pairs Whose Products Exist in Array117
1176K’th Largest element in BST using constant extra space117
1177Minimum Cost to Move Chips to The Same Position LeetCode Solution117
1178Decision Tree117
1179Priority Queue117
1180Matchsticks to Square Leetcode Solution117
1181Maximize sum of consecutive differences in a circular array117
1182Web Crawler LeetCode Solution116
1183Find Largest Value in Each Tree Row LeetCode Solution116
1184Search Suggestions System LeetCode Solution115
1185Maximum sum bitonic subarray115
1186Closest Leaf in a Binary Tree LeetCode Solution115
1187First Bad Version115
1188Moving Stones Until Consecutive Leetcode Solution115
1189Contiguous Array LeetCode Solution115
1190Given a binary tree, how do you remove all the half nodes?115
1191Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution115
1192Maximum number of segments of lengths a, b and c114
1193Array Queries for multiply replacements and product114
1194Integer Break LeetCode Solution114
1195Divide Two Integers Leetcode Solution114
1196Queue Reconstruction by Height114
1197Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution113
1198Kth Smallest Element in a BST113
1199Convert Sorted Array to Binary Search Tree LeetCode Solutions113
1200Lowest Common Ancestor of a Binary Tree Leetcode Solution113
1201Reformat Date LeetCode Solution113
1202Sum of Left Leaves LeetCode Solution113
1203Lowest Common Ancestor in Binary Search Tree113
1204Reverse a Path in BST using Queue113
1205How to print maximum number of A’s using given four keys113
1206Valid Triangle Number113
1207Maximum sum of pairs with specific difference113
1208Maximum Depth Of Binary Tree113
1209Champagne Tower LeetCode Solution113
1210Replace two consecutive equal values with one greater112
1211Guess The Word112
1212Write a function to get the intersection point of two Linked Lists112
1213Range Sum Query using Sparse Table112
1214Longest Common Prefix Using Word by Word Matching112
1215Range Queries for Longest Correct Bracket Subsequence111
1216Largest Plus Sign Leetcode Solution111
1217Print modified array after multiple array range increment operations111
1218Arithmetic Slices II – Subsequence LeetCode Solution111
1219Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution111
1220Maximize Elements Using Another Array111
1221Symmetric Tree LeetCode Solution Leetcode Solution111
1222Flatten 2D Vector LeetCode Solution111
1223LRU Cache Leetcode Solution111
1224Graph and its representation111
1225Print n terms of Newman-Conway Sequence111
1226Check Completeness of a Binary Tree LeetCode Solution111
1227New 21 Game111
1228Queries on Probability of Even or Odd Number in given Ranges110
1229Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1230Concatenation of Array LeetCode Solution110
1231Check if each internal node of a BST has exactly one child110
1232Path Crossing Leetcode Solution110
1233Design Skiplist LeetCode Solution110
1234Valid Perfect Square LeetCode Solution110
1235Minimum Swaps To Make Sequences Increasing LeetCode Solution109
1236Check if all levels of two Binary Tree are anagrams or not109
1237Perfect Squares LeetCode Solution109
1238BST to a Tree with Sum of all Smaller Keys109
1239Graph Cloning109
1240Merge Sort109
1241Maximum sum of a path in a Right Number Triangle109
1242Sliding Window Median Leetcode Solution109
1243Check for Identical BSTs without building the trees109
1244Find Minimum in Rotated Sorted Array II LeetCode Solution109
1245The kth Factor of n Leetcode Solution109
1246Maximum Array from Two given Arrays Keeping Order Same109
1247Missing Number109
1248Bold Words in String LeetCode Solution108
1249Count and Toggle Queries on a Binary Array108
1250Power of Two108
1251Parallel Courses II LeetCode Solution108
1252Count Subsets Having Distinct Even Numbers108
1253Mean of range in array108
1254Smallest Range II Leetcode Solution108
1255Contiguous Array107
1256Min Cost Climbing Stairs LeetCode Solution107
1257Maximum Product Subarray107
1258Image Overlap LeetCode Solution107
1259Find minimum number of merge operations to make an array palindrome107
1260Minimum Remove to Make Valid Parentheses LeetCode Solution106
1261Excel Sheet Column Title LeetCode Solution106
1262Check If a String Can Break Another String Leetcode Solution106
1263Verify Preorder Serialization of a Binary Tree105
1264Next greater element105
1265Find k-th smallest element in BST (Order Statistics in BST)105
1266Number of elements less than or equal to a given number in a given subarray104
1267Print Ancestors of a Given Binary Tree Node Without Recursion104
1268Peeking Iterator LeetCode Solution104
1269Merge k Sorted Lists Leetcode Solution104
1270Palindrome Partitioning104
1271Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1272Orderly Queue LeetCode Solution103
1273Check if two nodes are on the same path in a Tree102
1274Merge Sorted Array102
1275Check in binary array the number represented by a subarray is odd or even102
1276Newman–Shanks–Williams prime102
1277Koko Eating Bananas LeetCode Solution100
1278Different Ways to Add Parentheses Leetcode Solution100
1279Check if X can give change to every person in the Queue99
1280Largest Submatrix With Rearrangements LeetCode Solution99
1281Arranging Coins Leetcode Solution98
1282Find maximum average subarray of k length98
1283Longest Substring Without Repeating Characters Leetcode Solution98
1284Maximum Sum Increasing Subsequence98
1285Range Minimum Query (Square Root Decomposition and Sparse Table)97
1286Minimum Total Space Wasted With K Resizing Operations LeetCode Solution97
1287Queries for Decimal Values of Subarrays of a Binary Array96
1288Number of indexes with equal elements in given range96
1289Array Nesting Leetcode Solution96
1290Minimum Number of People to Teach LeetCode Solution96
1291Maximum product of an increasing subsequence95
1292Binary Tree to Binary Search Tree Conversion using STL set94
1293Check given array of size n can represent BST of n levels or not94
1294Convert to Base -2 LeetCode Solution94
1295Random Pick Index LeetCode Solution93
1296Find the Winner of the Circular Game LeetCode Solution93
1297Jump Game IV LeetCode Solution93
1298Convert a BST to a Binary Tree such that sum of all greater keys is added to every key93
1299Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution93
1300Add Two Numbers II Leetcode Solution92
1301Reach a Number LeetCode Solution92
1302Queries on XOR of greatest odd divisor of the range92
1303Encoded String With Shortest Length LeetCode Solution92
1304Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution91
1305Insert Delete GetRandom O(1) Leetcode Solution91
1306Continuous Subarray Sum LeetCode Solution91
1307Vertical Order Traversal of Binary Tree LeetCode Solution89
1308Palindrome Number LeetCode Solution89
1309Design Underground System Leetcode Solution88
1310Print Maximum Length Chain of Pairs86
1311Design A Leaderboard Leetcode Solution83
1312Detect Capital Leetcode Solution83
1313Substring with Concatenation of All Words Leetcode Solution80
1314Top K Frequent Elements LeetCode Solution79
1315Minimum Swaps to Group All 1’s Together Leetcode Solution78
1316Count Sub Islands LeetCode Solution76
1317Minimum Path Sum Leetcode Solution75
1318Decode String Leetcode Solution74
1319Longest Common Subsequence LeetCode Solution74
1320Odd Even Linked List Leetcode Solution73
1321Binary Tree Inorder Traversal LeetCode Solution72
1322Shifting Letters LeetCode Solution72
1323Maximum Population Year LeetCode Solution71
1324Best Meeting Point LeetCode Solution71
1325Shortest Unsorted Continuous Subarray LeetCode Solution71
1326Find the Town Judge LeetCode Solution70
1327Sum Root to Leaf Numbers LeetCode Solution70
1328Find the Town Judge LeetCode Solution70
1329Design Add and Search Words Data Structure LeetCode Solution68
1330Rectangle Overlap LeetCode Solution66
1331Maximum Population Year LeetCode Solution66
1332Score of Parenthesis LeetCode Solution65
1333Flatten Binary Tree to Linked List LeetCode Solution63
1334Insert into a Sorted Circular Linked List LeetCode Solution63
1335Stone Game IV LeetCode Solution62
1336Is Graph Bipartite? LeetCode Solution60
1337Range Sum Query 2D – Immutable LeetCode Solution60
1338Valid Triangle Number LeetCode Solution59
1339Reveal Cards In Increasing Order Leetcode Solution59
1340Divide Chocolate LeetCode Solution51
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution46
1342Range Sum of BST LeetCode Solution44
1343Reverse Integer Leetcode Solution41
1344Sort Colors LeetCode Solution40
1345Find K Closest Elements LeetCode Solution38
1346Excel Sheet Column Number LeetCode Solution36
1347Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution35
1348Rotate String LeetCode Solution34
1349Maximum Size Subarray Sum Equals k Leetcode Solution12
1350High Five LeetCode Solution11
1351H-Index Leetcode Solution10
Translate »
1