Insert into a Sorted Circular Linked List LeetCode Solution

Difficulty Level Medium
Frequently asked in Amazon Facebook Google Microsoft
Linked-ListViews 60

Problem Statement:

Insert into a Sorted Circular Linked List LeetCode Solution – says that Given a Circular Linked List node, which is sorted in ascending order, write a function to insert a value insertVal into the list such that it remains a sorted circular list. The given node can be a reference to any single node in the list and may not necessarily be the smallest value in the circular list.

If there are multiple suitable places for insertion, you may choose any place to insert the new value. After the insertion, the circular list should remain sorted.

If the list is empty (i.e., the given node is null), you should create a new single circular list and return the reference to that single node. Otherwise, you should return the originally given node.

Example:

Input:

Insert into a Sorted Circular Linked List LeetCode SolutionPin

 head = [3,4,1], insertVal = 2

Output:

 [3,4,1,2]

Explanation:

You are given a reference to the node with value 3, and we need to insert 2 into the list. The new node should be inserted between node 1 and node 3. After the insertion we should still return node 3.

Approach:

Idea:

The basic approach is to find the exact position where we need to insert the new node. We just need to keep track of what position are we inserting the new node. That is in the beginning, in the end, or in between two nodes. Here insertion at the beginning or at the end will give the same results as it is a circular linked list. Also, we need to keep track of some base cases, like if the node is NULL or we have only one node.

Code:

Insert into a Sorted Circular Linked List C++ Leetcode Solution:

class Solution {
public:
    Node* insert(Node* head, int insertVal) {
        if(!head){
            head = new Node(insertVal);
            head->next = head;
            return head;
        }
        
        Node* ptr = head;
        Node* start = head;
        while(ptr->next){
            if(ptr->val > ptr->next->val){
                start = ptr->next;
                break;
            }
            if(ptr->next == head)
                break;
            ptr = ptr->next;
        }
        if(ptr==start){
            ptr->next = new Node(insertVal);
            ptr->next->next = ptr;
            return head;
        }
        Node* prev = NULL;
        int cnt=0;
        while(start){
            if(start->val>=insertVal){
                if(!prev){
                    Node* temp = head;
                    while(temp->next!=start)
                        temp = temp->next;
                    
                    temp->next = new Node(insertVal);
                    temp->next->next = start;
                    return head;
                
                }
                prev->next = new Node(insertVal);
                prev->next->next = start;
                return head;
            }
            prev = start;
            start = start->next;
            
            if(start==head)
                cnt++;
            
            if(cnt==2){
                Node* temp = ptr->next;
                ptr->next = new Node(insertVal);
                ptr->next->next = temp;
                return head;
            }
        }
        return head;
    }
};

Insert into a Sorted Circular Linked List Java Leetcode Solution:

class Solution {
    public Node insert(Node head, int insertVal) {
        Node r = new Node(insertVal,null);
        if(head == null){
            r.next = r;
            return r;
        }
        Node n = head;
        while(true){
            if((insertVal >= n.val && insertVal <= n.next.val)
               || (n.next.val < n.val && (insertVal >= n.val || insertVal <= n.next.val))
               || n.next == head){
                r.next = n.next;
                n.next = r;
                break;
            }
            n = n.next;
        }
        
        return head;
    }
}

Complexity Analysis of Insert into a Sorted Circular Linked List:

  • Time Complexity: The time complexity of the above code is  where n is the number of nodes in the list.
  • Space Complexity: The space complexity of the above code is  as we did not use any extra space.

Similar Problem: https://www.tutorialcup.com/leetcode-solutions/linked-list-cycle-ii-leetcode-solution.htm

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2815
2Java program to find the number of Nodes in a Binary Tree2497
3Reverse a string without affecting special characters2453
4Delete a node of a linked list at given position1972
5Palindrome using Recursion1775
6Insert nodes in a linked list in a sorted way (Ascending Order)1656
7Find elements pair from array whose sum equal to number1644
8Sort Elements by Frequency of Occurrences1626
9Write a program to print all permutations of a given string1599
10Find Minimum Distance Between Two Numbers in an Array1470
11Create a Doubly Linked List1443
12Quick Sort1415
13Reverse an Array1408
14Smallest window in a string containing all characters of another string1393
15Find a Triplet That Sum to a Given Value1355
16Recursively remove all adjacent duplicates1351
17First Repeating Element1334
18Arrange Even and Odd number such that Odd comes after Even1317
19Sum of numbers in String1310
20Smallest Positive Number Missing in an Unsorted Array1277
21Check if the Elements of an Array are Consecutive1250
22Detect a loop in the Linked List1234
23Largest Sum Contiguous Subarray1228
24Quick Sort on SIngly Linked List1212
25Subarray with Given Sum1209
26Print all Possible Combinations of R Elements in a given Array of size N1198
27Recursive function to do substring search1195
28Find the Maximum Repeating Number in Array1149
29Binary Tree Level order traversal in Java1121
30Find the First and Second Smallest Elements1118
31Check if two linked lists are identical1100
32Maximum Subarray Sum using Divide and Conquer1097
33Remove characters from first string which are in second1065
34Find Leaders in an Array1057
35Swap nodes in the linked list1031
36Find the Number Occurring Odd Number of Times in an Array999
37Arrange given Numbers to Form the Biggest Number II989
38Find the second most frequent character983
39Given a string find its first non-repeating character962
40Find Triplet in Array With a Given Sum958
41Total number of occurrences of a given item in the linked list950
42Given a sorted array and a number x, find the pair in array whose sum is closest to x950
43A Program to check if strings are rotations of each other or not941
44Print all possible words from phone digits927
45Find the Missing Number922
46Rearrange Positive and Negative Numbers Alternatively in Array916
47Longest Palindromic Substring900
48Segregate even and odd nodes in a linked list880
49Print Longest common subsequence877
50Union and Intersection of Two Linked Lists869
51Transform one string to another using minimum number of given operations861
52Check rearranged string can form a palindrome841
53Rearrange given Array in Maximum Minimum Form841
54Count Possible Triangles818
55Iterative Implementation of Quick Sort812
56Multiplication of Two Matrices796
57Check if the linked list is palindrome792
58Count of Triplets With Sum Less than Given Value788
59Rotate a Linked List788
60Stock Buy Sell to Maximize Profit784
61Concatenation of two strings756
62Tug of War755
63Count Number of Substrings with K Distinct Character’s750
64Print all duplicates in the input string748
65Find Nearest Greater and Smaller Element742
66Find Pythagorean Triplets from Array735
67The Celebrity Problem735
68Reverse String Without Temporary Variable729
69Remove ‘b’ and ‘ac’ from a given string726
70Find all Common Elements in Given Three Sorted Arrays726
71Remove all duplicates in an unsorted linked list708
72Find the Row with Maximum Number of 1’s702
73Find the Peak Element from an Array696
74Find the subarray whose sum is equal to a given number X692
75Insertion Sort685
76Remove Minimum Characters so that Two Strings Become Anagrams683
77Find Smallest Missing Number in a Sorted Array682
78Addition of Two Matrices680
79A Product Array Puzzle680
80Implement Two Stacks in an Array674
81Generate all Binary Strings Without Consecutive 1’s670
82Maximum Sum of Non Consecutive Elements666
83Maximum Product Subarray II658
84Lexicographic rank of string651
85Multiplication of Previous and Next641
86Check if Two given Matrices are Identical641
87Merge K Sorted Arrays and Print Sorted Output631
88Subtraction of Two Matrices630
89Move All the Zeros to the End of the Given Array625
90Online Algorithm for Checking Palindrome in a Stream620
91Form Minimum Number from Given Sequence of D’s and I’s620
92Divide a string in N equal parts620
93Check whether two strings are anagram of each other611
94Remove recurring digits in a given number607
95Maximum Circular Subarray Sum607
96Sort a linked list that is sorted alternating ascending and descending606
97Sort a stack using a temporary stack603
98Find the Minimum Element in a Sorted and Rotated Array602
99Move last element of the Linked List at first place600
100Subarray and Subsequence596
101First Circular Tour to Visit all the Petrol Bunks596
102Largest Subarray with Equal Number of 0’s and 1’s592
103Compare two strings(linked lists)589
104Flattening a linked list589
105Maximum Element in an Array which is Increasing and then Decreasing588
106Palindrome Permutations of a String581
107Elements Appear more than N/K times in Array580
108Majority Element572
109Minimum insertions to form a shortest palindrome571
110Run length encoding571
111Print all permutations with repetition570
112Palindromes in a given range569
113Pangram Checking565
114Merge a linked list into another at alternate positions563
115Rearrange a given linked list in-place561
116Remove all duplicates in a sorted linked list561
117Minimum Characters to be Added at Front to Make String Palindrome561
118Minimum number of Merge Operations to make an Array Palindrome557
119Rotate string to get lexicographically minimum string556
120Repeated Subsequence of Length Two or More553
121Most repeating character in a string550
122Print all anagrams together in a sequence of words548
123Reorder an Array According to the Given Indexes546
124Pancake Sorting Problem540
125Clone a Linked List with next and random pointer535
126Merge Overlapping Intervals II534
127Two Sum Leetcode Solution533
128Size of The Subarray With Maximum Sum524
129Transpose of a Matrix522
130Remove Extra Spaces from a String518
131Removing Spaces from a String using stringstream517
132Check if a given string is a rotation of a palindrome515
133Smallest Palindrome after Replacement514
134Partition Problem513
135Remove duplicates from a string512
136Longest Palindrome can be Formed by Removing or Rearranging Characters511
137Maximum Sum Increasing Subsequence510
138Check whether Strings are K Distance Apart or Not501
139Generate all Binary Strings from Given Pattern499
140Insert Node in the Sorted Linked List497
141Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized497
142Delete Last Occurrence494
1433Sum Leetcode Solution494
144Length of Longest valid Substring494
145Check if Two given Strings are Isomorphic to each other490
146Maximum difference between two elements such as larger element comes after smaller486
147Program to Toggle all Characters in a String481
148Count Minimum Steps to Get the given Array478
149Given string is interleaving of two other strings or not478
150Merge sort better than quick sort for linked lists474
151Number of Smaller Elements on Right Side471
152Find Pair with Given Difference470
153Check length of a String is Equal to the Number Appended at its Last468
154Check if all Rows of a Matrix are Circular Rotations of Each Other468
155Longest Common Prefix using Divide and Conquer466
156Find nth node of the Linked list from the end466
157Sort 0s 1s and 2s in an Array457
158Find a Fixed Point in a Given Array456
159Print all interleavings of given two strings454
160Compare Two Version Numbers452
161Merge two sorted linked lists such that merged list is in reverse order452
162Find the Subarray of given length with Least Average452
163Split linked list using alternate nodes449
164Reorder Array Using Given Indexes449
165Reverse words in a given string448
166Print Reverse of a string (Recursion)446
167Median of Two Sorted Arrays LeetCode Solution444
168Print string of odd length in ‘X’ format434
169Find K Length Subarray of Maximum Average430
170Find Element Using Binary Search in Sorted Array430
171Swap Kth Node from beginning with Kth Node from End430
172Print all Palindromic Partitions of a String426
173Find Duplicates in an Array in Most Efficient Way424
174print all palindromic partitions420
175Maximum Length of Chain Pairs414
176Flatten a multilevel linked list414
177Shortest Superstring Problem413
178Check if String Follows Order of Characters by a Pattern or not410
179Sorting a K Sorted Array408
180Sort a String According to Another String401
181Longest Span with same Sum in two Binary Arrays II396
182Reverse a Linked List in groups394
183Find a Sorted Subsequence of size 3391
184Program to add two binary digits389
185Find the two Numbers with Odd Occurrences in an Unsorted Array386
186Recursively print all the sentences that can be formed from list of word lists385
187Longest Common Prefix Using Binary Search II382
188Reverse a Singly Linked List (Iterative/Non-Recursive)380
189Kth Non-repeating Character376
190Rearrange a linked list in Zig-Zag376
191Caesar Cipher375
192Check if String can Become Empty by Recursively Deleting given Substring374
193Pancake Sorting372
194Rotate Image by 90 degrees369
195Longest Common Prefix Word by Word Matching367
196Perfect Reversible String363
197Permutations of a Given String Using STL363
198Increasing Subsequence of Length three with Maximum Product361
199Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes360
200Merging Two Sorted Arrays360
201Find the point where a monotonically increasing function becomes positive first time358
202Sort a linked list with 0s, 1s and 2s357
203Find First non-repeating character in a string355
2041`s and 2`s complement of binary number355
205Four Elements that Sum to Given352
206Delete N nodes after M351
207List items containing all characters of a given word350
208Longest Common Prefix using Character by Character Matching347
209Count Number of Occurrences in a Sorted Array344
210Palindrome string (number)338
211Split a string338
212Minimum Characters to be Removed to Make a Binary String Alternate338
213Check if a Linked list of Strings form a Palindrome332
214Print All Distinct Elements of the Array330
215Recursive Implementation of atoi()330
216Sorting the array of strings329
217Convert a String that is Repetition of a Substring of Length K327
218Find the first Repeating Number in a Given Array325
219Even Substring Count324
220Maximum occurring character in a string323
221Reverse a singly linked list recursively323
222Valid Parentheses LeetCode Solution322
223Binary Tree to Doubly linked list321
224Print Shortest Path to Print a String on Screen320
225Can we reverse a linked list in less than O(n) time ?320
226Reverse a String using Stack316
227Nth Character in Concatenated Decimal String316
228Sort Elements by Frequency II316
229Convert string1 to string2 in one edit315
230Lower Case To Upper Case313
231wildcard character matching313
232Maximum Subarray Leetcode Solution310
233Merge Two Sorted Arrays310
234Find the Lost Element From a Duplicated Array310
235Count the number of words308
236Split Four Distinct Strings307
237Find middle of the Linked List304
238Longest Common Subsequence with Permutations298
239Count the Pairs at Same Distance as in English Alphabets298
240Next Greater Element in an Array293
241Matrix Chain Multiplication using Dynamic Programming292
242Palindrome Permutation287
243Searching a node in a Binary Search Tree283
244Find Nth Node283
245Find All Pairs With a Given Difference281
246Triplet from three linked lists with given sum280
247Roman to Integer Leetcode Solution279
248Delete a Tree279
249Print all Possible Ways to Break a String in Bracket Form275
250Reverse a String275
251String(represents an integer) to value275
252Binary Tree271
253Change Gender of a given String270
254Delete a node under given conditions270
255Reverse Bits270
256Word Search Leetcode Solution268
257Sort an array of strings268
258How to Efficiently Implement k Stacks in a Single Array?265
259Number of sub-strings which recursively add up to 9265
260Remove middle points in a linked list of line segments264
261Longest Common Extension264
262Count Pairs With Given Sum263
263Toeplitz Matrix262
264Meeting Rooms II LeetCode Solution261
265Remove spaces from a string261
266First non Repeating Element259
267Longest Palindromic Substring LeetCode Solution258
268Shuffle a given Array258
269Repeated Substring Pattern257
270Move all negative elements to one side of array256
271Min Stack254
272N queen problem253
273Number of Islands LeetCode Solution249
274Find, second, frequent, character249
275Dijkstra Algorithm248
276Cuckoo sequence program247
277Most Frequent Element in an Array246
278Clone a linked list with next and random pointer (Hashing)245
279House Robber Leetcode Solution244
280Minimize the maximum difference between the heights244
281Sort linked which is sorted on absolute values243
282Max stack243
283Expression Evaluation242
284Search Insert Position Leetcode Solution241
285Fibonacci numbers239
286Valid Palindrome Leetcode Solution237
287KMP Algorithm237
288How to Delete a Linked List237
289Sudoku Solver236
290Word Search235
291Min Stack Leetcode Solution235
292Plus One Leetcode Solution235
293Reverse words in a string233
294Evaluation of Postfix Expression233
295Subset Leetcode233
296Combination Sum Leetcode Solution232
297Number Of 1 bits232
298Backspace String Compare227
299Merge Sorted Arrays Leetcode Solution226
300Pair of Positive Negative Values in an Array226
301Rabin Karp Algorithm225
302Sqrt(x) Leetcode Solution224
303Contains Duplicate II Leetcode Solution223
304Set Matrix Zeroes223
305Reversing a Queue222
306Tower Of Hanoi222
307Subarray with 0 sum221
308Combination Sum220
309Common elements in all rows of a given matrix219
310Product of array except self219
311Integer to Roman Leetcode Solution217
312Intersection of Two Arrays II Leetcode Solution217
313Pascal Triangle Leetcode215
314Count subarrays with equal number of 1’s and 0’s215
315Reverse individual words214
316Delete middle element of a stack214
317String Compression214
318Construct Binary Tree from Given Inorder and Preorder Traversals213
319Find Top K (or Most Frequent) Numbers in a Stream213
320Minimum swaps required to bring all elements less than or equal to k together212
321Sliding Window Technique212
322Second Most Repeated Word in a Sequence212
323Pow(x, n) Leetcode Solution211
324Arithmetic Expression Evaluation211
325Add Binary Leetcode Solution211
326Bellman Ford Algorithm211
327Next Permutation210
328Palindrome Linked List Leetcode Solution210
329Segregate even and odd numbers210
330Page Replacement Algorithms in Operating Systems209
331Count of index pairs with equal elements in an array209
332Kruskal Algorithm208
333Postfix to Infix Conversion208
334Find sum of non-repeating elements (distinct) elements in an array208
335Single Number Leetcode Solution208
336Design a stack that supports getMin() in O(1) time and O(1) extra space207
337Implementation of Deque using Doubly Linked List207
338Contains Duplicate207
339Minimum Value to Get Positive Step by Step Sum Leetcode Solution207
340Sort elements by frequency206
341Count Odd Numbers in an Interval Range Leetcode Solution206
342Maximum Number of Balloons Leetcode Solution206
343K-th Smallest Element in a Sorted Matrix206
344Maximum Subarray205
345Longest Common Prefix Leetcode Solution204
346Group Words With Same Set of Characters204
347Third Maximum Number Leetcode Solution204
348Majority Element Leetcode Solution203
349Permutations Leetcode Solution203
350Top K Frequent Words203
351Convex Hull Algorithm203
352Find Numbers with Even Number of Digits Leetcode Solution202
353Longest Substring Without Repeating Characters LeetCode Solution202
354Find Lucky Integer in an Array Leetcode Solution202
355Minimum operation to make all elements equal in array201
356Sum of minimum and maximum elements of all subarrays of size k201
357Sorting array using Stacks201
358Spiral Matrix LeetCode Solution201
359Swap Nodes in Pairs Leetcode Solutions200
360Find the Town Judge Leetcode Solution200
361Smallest Subarray with k Distinct Numbers200
362Count subarrays having total distinct elements same as original array200
363Scramble String200
364Evaluate Division199
365Merge Two Sorted Lists Leetcode Solutions198
366Special Number198
367First element occurring k times in an array197
368Reverse a Number Using Stack197
369Group Anagrams196
370Given two unsorted arrays find all pairs whose sum is x196
371Check if two arrays are equal or not196
372Prefix to Infix Conversion196
373Best Time to Buy and Sell Stock  II Leetcode Solution195
374Count Primes Leetcode Solutions195
375Search in Rotated Sorted Array Leetcode Solution195
376Pascal’s Triangle II Leetcode Solution195
377Minimum Path Sum195
378Number of Good Pairs Leetcode Solution195
379Maximum Distance Between two Occurrences of Same Element in Array194
380Huffman Coding194
381Find duplicates in a given array when elements are not limited to a range194
382Reversing the First K elements of a Queue194
383Single Number193
384Fizz Buzz Leetcode193
385Power of Two Leetcode Solution193
386Minimum Steps to reach target by a Knight193
387Minimum Absolute Difference Leetcode Solution193
388House Robber II Leetcode Solution192
389Sort Array by Increasing Frequency Leetcode Solution192
390Missing Number Leetcode Solution192
391Range Sum Query 2D – Immutable Leetcode Solution191
392Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution191
393Maximum possible difference of two subsets of an array191
394Maximal Square191
395Running Sum of 1d Array Leetcode Solution190
396Top K Frequent Elements190
397Find All Numbers Disappeared in an Array Leetcode Solution190
398How Many Numbers Are Smaller Than the Current Number Leetcode Solution189
399Max Consecutive Ones Leetcode Solution189
400Coin Change 2 Leetcode Solution189
401Unique Paths Leetcode Solution189
402Matrix Diagonal Sum Leetcode Solution189
403Sorting using trivial hash function189
404Decode String188
405Zigzag Conversion188
406Expression Contains Redundant Bracket or Not188
407Leetcode Permutations188
408Subarray Sum Equals K LeetCode Solution188
409Palindrome Substring Queries188
410Unique Paths188
411Smallest Element Repeated Exactly K Times187
412Difference between highest and least frequencies in an array187
413Happy Number Leetcode Solution187
414Find The Duplicate Number187
415Check if Array Contains Contiguous Integers With Duplicates Allowed187
416How to Implement Stack Using Priority Queue or Heap?187
417Fibonacci Number LeetCode Solution187
418Sort Integers by The Number of 1 Bit Leetcode Solution187
419Subset sum problem187
420Find Winner on a Tic Tac Toe Game Leetcode Solution187
421Reverse Integer186
422Letter Case Permutation186
423Monotonic Array LeetCode Solution186
424Reverse Vowels of a String Leetcode Solution186
425Convert String To Int186
426Find the Closest Palindrome number186
427Subarray Sum Equals k186
428Check If N and Its Double Exist Leetcode Solution185
429Cumulative Frequency of Count of Each Element in an Unsorted Array185
430Remove Duplicates from Sorted Array Leetcode Solution185
431Print All Distinct Elements of a Given Integer Array185
432Nth Catalan Number185
433Find top three repeated in array185
434Length of the largest subarray with contiguous elements185
435Subtract the Product and Sum of Digits of an Integer Leetcode Solution185
436Find Number of Employees Under every Employee185
437Trapping Rain Water Leetcode Solution184
438Sort a stack using recursion184
439Shuffle the Array Leetcode Solution184
440Reverse Words in a String III LeetCode Solution184
441Bipartite Graph184
442Find Median from data Stream184
443Capacity To Ship Packages Within D Days Leetcode Solution184
444Best Time to Buy and Sell Stock III Leetcode Solution184
445Maximum Depth of Binary Tree Leetcode Solution183
446Find the first repeating element in an array of integers183
447LRU Cache Implementation183
448Prim’s Algorithm182
449Implement Stack and Queue using Deque182
450Find Minimum In Rotated Sorted Array182
451Find the Duplicate Element182
452Minimum Moves to Equal Array Elements Leetcode Solution182
453Generate a String With Characters That Have Odd Counts Leetcode Solution182
454Priority Queue Using Singly Linked List182
455Find all pairs (a, b) in an array such that a % b = k182
456Reverse a Stack Using Recursion181
457Delete a Node from linked list without head pointer181
458Count Substrings with equal number of 0s, 1s and 2s181
459Integer to English words181
460Kth largest element in an Array Leetcode Solutions181
461Longest Common Subsequence181
462Sum of Subarray Ranges Leetcode Solution181
463Merge Two Sorted Linked Lists181
464Subarrays with distinct elements181
465Sorting a Queue without Extra Space180
466The K Weakest Rows in a Matrix Leetcode Solution180
467Count pairs from two linked lists whose sum is equal to a given value180
468Fizz Buzz180
469Edit Distance179
470Remove Minimum Number of Elements Such That no Common Element Exist in both Array179
471Find Common Characters Leetcode Solution179
472Reverse a String179
473Find elements which are present in first array and not in second179
474Find the Difference Leetcode Solution179
475Find First and Last Position of Element in Sorted Array Leetcode Solution178
476MiniMax Algorithm178
477Reverse a linked list178
478Count and Say178
479Word Ladder LeetCode Solution178
480Degree of an array178
481Concatenation of Array LeetCode Solution178
482Target Sum178
483Next Greater Element I Leetcode Solution178
484Kth Largest Element in a Stream Leetcode Solution178
485Floyd Warshall Algorithm177
486Print all subarrays with 0 sum177
487Excel Sheet Column Number Leetcode Solution177
488Text Justification LeetCode Solution177
489Number of Steps to Reduce a Number to Zero Leetcode Solution177
490Multiply Strings Leetcode Solution177
491Balanced Binary Tree Leetcode Solution176
492Priority Queue in C++176
493Kids With the Greatest Number of Candies Leetcode Solution176
494Top View of Binary Tree176
495Merge Overlapping Intervals176
496Longest Common Prefix using Trie176
497Iterative Tower of Hanoi175
498Design Parking System Leetcode Solution175
499Longest subarray not having more than K distinct elements175
500Flood Fill LeetCode175
501Koko Eating Bananas Leetcode Solution175
502Shortest Palindrome175
503Pair with given product175
504Prefix to Postfix Conversion174
505Move Zeroes LeetCode Solution174
506Postfix to Prefix Conversion174
507Count and Say Leetcode Solution174
508Max Area of Island174
509Check if a given array contains duplicate elements within k distance from each other174
510Implement Stack using Queues173
511Valid Parenthesis String173
512Intersection of Two Arrays173
513Peak Index in a Mountain Array173
514Recursion173
515Zigzag Conversion LeetCode Solution173
516Find four elements that sum to a given value (Hashmap)173
517Shuffle String Leetcode Solution173
518The Stock Span Problem173
519Find N Unique Integers Sum up to Zero Leetcode Solution173
520Mobile Numeric Keypad Problem173
521Implement a stack using single queue173
522Length of Last Word Leetcode Solution173
523Find subarray with given sum (Handles Negative Numbers)173
524Substring With Concatenation Of All Words172
525Find Index of Closing Bracket for a Given Opening Bracket in an Expression172
526Slowest Key Leetcode Solution172
527Contiguous Array Leetcode172
528Convert array into Zig-Zag fashion172
529Count number of triplets with product equal to given number172
530Find missing elements of a range172
531Jump Game Leetcode Solution172
532Iterative Inorder Traversal of a Binary Tree172
533Container with Most Water172
534Find distinct elements common to all rows of a matrix172
535Maximum sum rectangle in a 2D matrix171
536Last Stone Weight171
537Longest Common Prefix using Sorting171
538Excel Sheet Column Title Leetcode Solution171
539Best Time to Buy and Sell Stock171
540Find any one of the multiple repeating elements in read only array170
541Convert a normal BST to Balanced BST170
542Smallest Subarray With all Occurrences of a Most Frequent Element170
543Relative Sort Array Leetcode Solution170
544Minimum Bracket Reversals170
545Delete Node in a Linked List Leetcode Solution170
546Largest Perimeter Triangle Leetcode Solution170
547K-th Distinct Element in an Array170
548Next Greater Frequency Element169
549Shuffle an Array169
550Valid Sudoku169
551Minimum Operations to convert X to Y169
552Check for Balanced Parentheses in an Expression168
553Sum of Left Leaves Leetcode Solutions168
554Arrange given numbers to form the biggest number168
555Build Array From Permutation Leetcode Solution168
556Change the Array into Permutation of Numbers From 1 to N168
557Assign Cookies Leetcode Solution168
558First negative integer in every window of size k168
559Distribute Candies to People Leetcode Solution168
560Jewels and Stones Leetcode Solution168
561Rearrange a binary string as alternate x and y occurrences167
562The Knapsack Problem167
563Implementation of Deque using circular array167
564Group Multiple Occurrence of Array Elements Ordered by first Occurrence167
565Shortest Path in a Grid with Obstacles Elimination LeetCode Solution167
566Isomorphic Strings Leetcode Solution167
567Integer to Roman167
568Find Words That Can Be Formed by Characters Leetcode Solution167
569Is Subsequence Leetcode Solution167
570Valid Anagrams167
57101 Matrix LeetCode Solution166
572Hamming Distance166
573Minimum Delete Operations to make all Elements of Array Same166
574Convert Sorted Array to Binary Search Tree Leetcode Solution166
5753Sum Closest LeetCode Solution166
576Maximum path sum in a triangle166
577Decode Ways166
578N-th Tribonacci Number Leetcode Solution166
579Linked List Cycle II LeetCode Solution166
580How to check if two given sets are disjoint?165
581Rotate List Leetcode Solution165
582Unique Binary Search Trees165
583Find the smallest positive integer value that cannot be represented as sum of any subset of a given array165
584Gold Mine Problem165
585Sieve of Eratosthenes165
586Island Perimeter Leetcode Solution165
587Count all subsequences having product less than K165
588Count the number of nodes at given level in a tree using BFS165
589Minimum Knight Moves LeetCode Solution164
590Minimum number of distinct elements after removing m items164
591Insert Interval Leetcode Solution164
592Maximum Distance in Array164
593Trapping Rain Water LeetCode Solution164
594Remove Linked List Elements Leetcode Solution164
595Combinations Leetcode Solution164
596LRU Cache LeetCode Solution164
597Maximum difference between first and last indexes of an element in array164
598Same Tree LeetCode Solution164
599Find minimum difference between any two elements163
600Summary Ranges Leetcode Solution163
601Rotate Image LeetCode Solution163
602Distance Between Bus Stops Leetcode Solution163
603Minimum number of subsets with distinct elements163
604K Empty Slots LeetCode163
605Printing brackets in Matrix Chain Multiplication Problem162
606Coin Change Problem162
607Applications of Breadth First Search and Depth First Search162
608Find Sum of all unique sub-array sum for a given array162
609Minimum insertions to form a palindrome with permutations allowed162
610Frog Jump Leetcode Solution162
611Maximum Number of Chocolates to be Distributed Equally Among k Students162
612Replace Elements with Greatest Element on Right Side Leetcode Solution161
613Sort Array By Parity LeetCode Solution161
614Find the Duplicate Number LeetCode Solution161
615Word Wrap Problem161
616Word Pattern161
617Best Time to Buy and Sell Stock LeetCode Solution161
618Find if an Expression has Duplicate Parenthesis or Not161
619Minimum Cost to Hire K Workers161
620Distance of nearest cell having 1 in a binary matrix160
621Stone Game LeetCode160
622House Robber160
623Minimum Depth of Binary Tree Leetcode Solution160
624License Key Formatting Leetcode Solution160
625Find Maximum Level sum in Binary Tree160
626Permutation in String Leetcode Solution160
627Remove All Occurrences of a Substring LeetCode Solution160
628Longest Increasing Subsequence159
629XOR Operation in an Array Leetcode Solution159
630Smallest Good Base159
631Kth Missing Positive Number Leetcode Solution159
632Painting Fence Algorithm159
633Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest159
634Segregate 0s and 1s in an Array159
635Maximum Consecutive Numbers Present in an Array159
636Defanging an IP Address Leetcode Solution159
637Sort Characters By Frequency LeetCode Solution159
638Check If It Is a Straight Line Leetcode Solution158
639Non-overlapping sum of two sets158
640Queries for counts of array elements with values in given range158
641Reverse a stack without using extra space in O(n)158
642Longest Substring with At Most K Distinct Characters LeetCode Solution157
643K Empty Slots157
644Optimal Account Balancing LeetCode Solution157
645Reorganize String157
646Tracking current Maximum Element in a Stack157
647Find Largest d in Array such that a + b + c = d157
648Best Time to Buy and Sell Stock with Cooldown Leetcode Solution157
649Power of Four Leetcode Solution157
650Binary Tree Zigzag Level Order Traversal LeetCode Solution157
651Isomorphic Strings157
652Iterative Method to find Height of Binary Tree157
653Valid Palindrome II Leetcode Solution157
654Merge Two Balanced Binary Search Trees157
655Count Good Nodes in Binary Tree Leetcode Solution157
656Moving Average from Data Stream Leetcode Solution156
657Check If Two String Arrays are Equivalent Leetcode Solution156
658Strobogrammatic Number LeetCode Solution156
659How to Create Mergable Stack?156
660Sum of All Odd Length Subarrays Leetcode Solution156
661Longest Substring with At Least K Repeating Characters LeetCode Solution156
662Partition Labels LeetCode Solution156
663Number of Provinces Leetcode Solution156
664GCD Of Two Numbers156
665Flipping an Image LeetCode Solution156
666Wiggle Sort156
667Employee Free Time LeetCode Solution156
668Convert an array to reduced form155
669Inorder Successor of a node in Binary Tree155
670BFS vs DFS for Binary Tree155
671Form minimum number from given sequence155
672Check if a queue can be sorted into another queue using a stack155
673Sum of f(a[i], a[j]) over all pairs in an array of n integers155
674Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions155
675String to Integer (atoi) LeetCode Solution155
676Largest Sum Contiguous Subarray155
677Find the Distance Value Between Two Arrays Leetcode Solution155
678Reservoir Sampling155
679Letter Combinations of a Phone Number155
680Permutation Sequence LeetCode Solution155
681Populating Next Right Pointers in Each Node154
682Delete consecutive same words in a sequence154
683To Lower Case Leetcode Solution154
684Lucky Numbers in a Matrix Leetcode Solution154
685Ugly Number Leetcode Solution154
686Increasing Decreasing String Leetcode Solution154
687Maximum Number of Occurrences of a Substring Leetcode Solution154
688Subset Sum Leetcode154
689Reducing Dishes LeetCode Solution154
690Maximum Number of Coins You Can Get Leetcode Solution154
691Path With Maximum Minimum Value LeetCode Solution154
692Sort Array by Increasing Frequency Leetcode Solution153
693Longest Increasing Path in a Matrix LeetCode Solution153
694Find the Smallest Divisor given a Threshold Leetcode Solution153
695Valid Palindrome153
696Find whether an array is subset of another array153
697Maximum Product of Three Numbers LeetCode Solution153
698Find Leaves of Binary Tree LeetCode Solution153
699Find the node with minimum value in a Binary Search Tree153
700Hamming Distance Leetcode Solution153
701Reversing a Queue using Recursion153
702Print the Fibonacci numbers in reverse order153
703Majority Element II Leetcode Solution153
704Remove Invalid Parentheses Leetcode Solution152
705Unique Paths II Leetcode Solution152
706Construct BST from given Preorder Traversal152
707Recover Binary Search Tree152
708Dynamic Programming Basics152
709Add and Search Word – Data structure design LeetCode152
710Partition Array Into Three Parts With Equal Sum Leetcode Solution152
711Numbers with prime frequencies greater than or equal to k152
712Find pairs with given sum such that elements of pair are in different rows152
713Number of Dice Rolls With Target Sum LeetCode Solution152
714Delete Nth node from the end of the given linked list152
715Factorial Trailing Zeroes Leetcode Solution152
716Reverse Only Letters LeetCode Solution152
717Convert a Number to Hexadecimal Leetcode Solution151
718Decompress Run-Length Encoded List Leetcode Solution151
719Binary Tree zigzag level order Traversal151
720Largest subarray with equal number of 0s and 1s151
721Longest Span with same Sum in two Binary arrays151
722Edit Distance LeetCode Solution151
723Valid Perfect Square Leetcode Solution151
724Minimum Cost For Tickets Leetcode Solution150
725Maximum Product of Two Elements in an Array Leetcode Solution150
726Deletion in a Binary Tree150
727Restore IP Addresses Leetcode Solution150
728Binomial Coefficient150
729Best Meeting Point LeetCode Solution149
730Rank Transform of an Array Leetcode Solution149
731Find unique character in a string149
732Finding K closest element149
733Minimum Distance Between BST Nodes Leetcode Solution149
734Merge K Sorted Linked Lists149
735Minimum Height Trees149
736Maximum 69 Number Leetcode Solution149
737Find Maximum Depth of Nested Parenthesis in a String149
738Find Pair with Greatest Product in Array149
739Keyboard Row Leetcode Solution149
740Bubble sort using two Stacks149
741Stack Permutations (Check if an array is stack permutation of other)149
742Merge Two Binary Trees LeetCode Solution149
743Find the largest multiple of 3149
744Remove brackets from an algebraic string containing + and – operators148
745Sorted Linked List to Balanced BST148
746Morris Traversal148
747Word Pattern LeetCode Solution148
748Elements to be added so that all elements of a range are present in array148
749Binary Tree Maximum Path Sum LeetCode Solution148
750Jump Game148
751Generate all possible sorted arrays from alternate elements of two given sorted arrays148
752Invert Binary Tree LeetCode Solution148
753Bulb Switcher LeetCode Solution148
754Growable array based stack148
755Perform String Shifts Leetcode148
756Symmetric Tree Leetcode Solution148
757Race Car LeetCode Solution148
758Kth ancestor of a node in binary tree147
759Evaluate Reverse Polish Notation LeetCode Solution147
760First Unique Character in a String LeetCode Solution147
761Robot Room Cleaner Leetcode Solution147
762Number of NGEs to the Right147
763Count quadruples from four sorted arrays whose sum is equal to a given value x147
764Largest rectangular sub-matrix whose sum is 0147
765Program for Bridge and Torch problem147
766Diagonal Traversal of Binary Tree147
767Minimum time required to rot all oranges147
768Student Attendance Record I Leetcode Solution147
769Find All Duplicates in an Array LeetCode Solution147
770k-th missing element in increasing sequence which is not present in a given sequence147
771Non-decreasing Array LeetCode Solution147
772Queue based approach for first non-repeating character in a stream146
773Nested List Weight Sum II LeetCode Solution146
774Minimum number of jumps to reach end146
775String Compression LeetCode Solution146
776Search in a Binary Search Tree Leetcode Solution146
777Check for Palindrome after every character replacement Query146
778Remove Duplicates from Sorted List LeetCode Solution146
779Snakes and Ladders LeetCode Solution146
780Maximum Depth of N-ary Tree Leetcode Solution146
781Remove Nth Node From End of List Leetcode Solution146
782Largest Rectangle in Histogram LeetCode Solution146
783Maximum Length of a Concatenated String with Unique Characters Leetcode Solution146
784Merge Sorted Array LeetCode Solution146
785Tiling Problem146
786Valid Number146
787N-Queens LeetCode Solution146
788Count items common to both the lists but with different prices145
789Minimize Maximum Pair Sum in Array LeetCode Solution145
790Find Median from Data Stream LeetCode Solution145
791Minimum swaps to make sequences increasing145
792Find if Path Exists in Graph Leetcode Solution145
793Search a 2D Matrix II Leetcode Solution145
794Number of Islands II LeetCode Solution145
795Sort an array according to the order defined by another array145
796Interval Tree145
797Base 7 Leetcode Solution145
798Special Array With X Elements Greater Than or Equal X Leetcode Solution145
799Linked List Cycle145
800Maximum Difference Between Increasing Elements LeetCode Solution145
801Partition to K Equal Sum Subsets Leetcode Solution145
802Relative Ranks Leetcode Solution145
803Check If Array Pairs Are Divisible by k LeetCode Solution144
804Print a Binary Tree in Vertical Order144
805Circular Queue144
806Crawler Log Folder Leetcode Solution144
807Check if Two Expressions With Brackets are Same144
808A Space Optimized DP solution for 0-1 Knapsack Problem144
809Alien Dictionary LeetCode Solution144
810Reorder Data in Log Files LeetCode Solution144
811Final Prices With a Special Discount in a Shop Leetcode Solution144
812Split a String in Balanced Strings Leetcode Solution144
813String comparison containing wildcards144
814Transpose Graph144
815Find all triplets with zero sum143
816Number Complement Leetcode Solution143
817Get Maximum in Generated Array Leetcode Solution143
818Iterative Preorder Traversal143
819Course Schedule II – LeetCode143
820Priority Queue using doubly linked list143
821Clone Graph LeetCode Solution143
822Longest Subarray Having Count of 1s One More than Count of 0s143
823Permutation Coefficient143
824Remove Duplicates from Sorted List II143
825Minimum Time Visiting All Points Leetcode Solution143
826One Edit Distance LeetCode Solution143
827Convert BST to Min Heap143
828Nearest Exit from Entrance in Maze LeetCode Solution143
829Total Numbers With no Repeated Digits in a Range143
830Maximum Nesting Depth of the Parentheses Leetcode Solution142
831Minimum Swaps to Make Strings Equal Leetcode Solution142
832Sort Array By Parity II Leetcode Solution142
833Sort Colors142
834Last Stone Weight II LeetCode Solution142
835Path with maximum average value142
836Top K Frequent Words LeetCode Solution142
837Subset with sum divisible by m142
838Find the Only Repetitive Element Between 1 to N-1142
839Design a Stack With Increment Operation Leetcode Solution142
840Partition List Leetcode Solution142
841Find the subarray with least average142
842Regular Expression Matching141
843Maximum size subarray sum equals k141
844Friends Pairing Problem141
845Check if an Array is Stack Sortable141
846Check if a given array can represent Preorder Traversal of Binary Search Tree141
847Count ways to reach the nth stair using step 1, 2 or 3141
848Brick Wall LeetCode Solution141
849Minimum Number of Taps to Open to Water a Garden LeetCode Solution141
850Spiral Matrix II Leetcode Solution141
851Minimum Jumps to Reach Home LeetCode Solution141
852Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution141
853Matrix Chain Multiplication141
854Sum of nearest smaller and greater number141
855Sorted Array to Balanced BST141
856Find All Possible Recipes from Given Supplies LeetCode Solution141
857Count Distinct Elements in Every Window of Size K141
858Subarray Product Less Than K LeetCode Solution140
859Level order Traversal in Spiral Form140
860Tree Traversal (Preorder, Inorder & Postorder)140
861Binary Search Tree Search and Insertion140
862LCS (Longest Common Subsequence) of three strings140
863Can Place Flowers LeetCode Solution140
864Maximum Profit in Job Scheduling Leetcode Solution140
865Subsequence of Size K With the Largest Even Sum LeetCode Solution140
866Check whether a given Binary Tree is Complete or not140
867Valid Parentheses Leetcode Solution140
868Brightest Position on Street LeetCode Solution140
869Given an Array of Pairs Find all Symmetric Pairs in it140
870Form Minimum Number From Given Sequence140
871Insert Delete GetRandom140
872Range sum queries without updates139
873Find all permuted rows of a given row in a matrix139
874Insert into a Binary Search Tree Leetcode Solution139
875Union and Intersection of two Linked Lists139
876Minimum Sum Path in a Triangle139
877Rearrange an Array Such that arr[i] is equal to i139
878Find Maximum Sum Possible Equal Sum of Three Stacks139
879Count Subarrays with Same Even and Odd Elements139
880Guess Number Higher or Lower LeetCode Solution139
881Distinct adjacent elements in an array139
882Guess Number Higher or Lower II139
883Sequences of given length where every element is more than or equal to twice of previous139
884Check if stack elements are pairwise consecutive138
885Missing Element in Sorted Array LeetCode Solution138
886Alien Dictionary138
887Daily Temperatures Leetcode Solution138
888A program to check if a binary tree is BST or not138
889Convert Sorted List to Binary Search Tree138
890An Interesting Method to generate Binary Numbers from 1 to n138
891Maximum Score After Splitting a String Leetcode Solution138
892Rearrange Spaces Between Words Leetcode Solution138
893Find distance between two nodes of a Binary Tree138
894BFS for Disconnected Graph138
895Count Negative Numbers in a Sorted Matrix LeetCode Solution138
896Shortest Word Distance Leetcode Solution138
897Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution138
898Find Common Characters Leetcode Solution138
899Delete And Earn138
900Minimum sum of multiplications of n numbers138
901Identify and Mark Unmatched Parenthesis in an Expression138
902Destination City Leetcode Solution138
903Diagonal Traversal LeetCode Solution137
9044Sum137
905Balanced Expression with Replacement137
906Water Bottles Leetcode Solution137
907Repeated Substring Pattern LeetCode Solution137
908Range LCM Queries137
909Construct Complete Binary Tree from its Linked List Representation137
910Special Positions in a Binary Matrix Leetcode Solution137
911Check if the given array can represent Level Order Traversal of Binary Search Tree137
912GCDs of given index ranges in an array137
913Three way partitioning of an array around a given range137
914Number of Days Between Two Dates LeetCode Solution137
915Lemonade Change Leetcode Solution137
916Set Matrix Zeroes Leetcode Solution137
917Least Number of Unique Integers after K Removals Leetcode Solution136
918Diagonal Traverse LeetCode Solution136
919Robot Bounded In Circle LeetCode Solution136
920Spiral Matrix III LeetCode Solution136
921Infix to Postfix136
922Merge Two Sorted Lists Leetcode136
923Design Browser History LeetCode Solution136
924Number of Equivalent Domino Pairs Leetcode Solution136
925Vertical sum in a given binary tree136
926Queue using Stacks136
927Averages of Levels in Binary Tree135
928Print Fibonacci sequence using 2 variables135
929Trim a Binary Search Tree135
930Palindrome Partitioning Leetcode Solution135
931Maximum Subarray Sum Excluding Certain Elements135
932Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i135
933Longest Palindromic Subsequence135
934K’th Largest Element in BST when modification to BST is not allowed135
935Construct the Rectangle Leetcode Solution135
936Lexicographical Numbers Leetcode Solution135
937Dividing Array into Pairs With Sum Divisible by K135
938Queries for GCD of all numbers of an array except elements in a given range134
939Time Based Key-Value Store LeetCode Solution134
9403 Sum134
941Binary array after M range toggle operations134
942Check if any two intervals overlap among a given set of intervals134
943Largest area rectangular sub-matrix with equal number of 1’s and 0’s134
944Remove Duplicates from Sorted List II LeetCode Solution134
945Construct BST from its given Level Order Traversal134
946Strongly Connected Component134
947Median of Two Sorted Arrays134
948Stone Game II Leetcode134
949Analyze User Website Visit Pattern LeetCode Solution134
950All Unique Triplets that Sum up to a Given Value134
951Symmetric Tree133
952Create Maximum Number133
953Pattern Occurrences using Stack133
954Three Consecutive Odds Leetcode Solution133
955Word Break133
956Iterative Postorder Traversal Using Two Stacks133
957Newman-Conway Sequence133
958Maximize Sum of Array after K Negations Leetcode Solution133
959Palindrome Partitioning133
960Can Make Arithmetic Progression From Sequence Leetcode Solution133
961Binary Tree Longest Consecutive Sequence LeetCode Solution133
962Maximum Frequency Stack Leetcode Solution133
963Number of Distinct Islands Leetcode Solution133
964Merging Intervals133
965Largest Substring Between Two Equal Characters Leetcode Solution133
966Difference Array | Range update query in O(1)132
967Sign of the Product of an Array LeetCode Solution132
968Count Submatrices With All Ones LeetCode Solution132
969My Calendar I LeetCode Solution132
970Intersection of Two Linked Lists LeetCode Solution132
971Depth First Search (DFS) for a Graph132
972Split Array Into Consecutive Subsequences132
973Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space132
974Segment Tree132
975Sliding Window Maximum132
976Maximum Product Subarray132
977Length of Longest Fibonacci Subsequence132
978Find Maximum of Minimum for Every Window Size in a Given Array132
979Breadth First Search (BFS) for a Graph131
980Find Duplicate Subtrees131
981Level Order Traversal of Binary Tree131
982Climbing stairs131
983Count pair with Given Sum131
984Minimum Height Trees LeetCode Solution131
985Find the Difference Leetcode Solution131
986Count Primes in Ranges131
987First missing positive131
988Height of a generic tree from parent array131
989Maximum subsequence sum such that no three are consecutive131
990Binary Search Tree Delete Operation131
991Make The String Great Leetcode Solution130
992Insertion in a Binary Tree130
993Reverse Nodes in K-Group130
994Double the first element and move zero to end130
995Find postorder traversal of BST from preorder traversal130
996Minesweeper LeetCode Solution130
997Boundary Traversal of binary tree130
998Find the First Circular Tour that visits all the Petrol Pumps130
999Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution130
1000Serialize and Deserialize Binary Tree130
1001Largest Number Leetcode Solution129
1002Rearrange array such that even positioned are greater than odd129
1003The Painter’s Partition Problem129
1004Level order traversal using two Queues129
1005Partition Equal Subset Sum129
1006Find number of pairs in an array such that their XOR is 0129
1007Count subarrays where second highest lie before highest129
1008Compute nCr % p129
1009Valid Boomerang Leetcode Solution129
1010Unique Paths II129
1011Asteroid Collision LeetCode Solution129
1012Product of Array Except Self LeetCode Solution129
1013Largest divisible pairs subset129
1014Number Of Longest Increasing Subsequence129
1015Kth Smallest Element in a BST Leetcode Solution129
1016Collect maximum points in a grid using two traversals128
1017Scramble String LeetCode Solution128
1018Number of palindromic paths in a matrix128
1019Longest Nice Substring LeetCode Solution128
1020Decrypt String from Alphabet to Integer Mapping Leetcode Solution128
1021Maximum Number of Ways to Partition an Array LeetCode Solution128
1022Friends Of Appropriate Ages LeetCode Solution128
1023Construction of Longest Increasing Subsequence (N log N)128
1024Graph Valid Tree LeetCode Solution128
1025The Maze III LeetCode Solution128
1026Maximum Length of Repeated Subarray128
1027Shortest Completing Word Leetcode Solution128
1028Binary Search Tree128
1029Balanced Binary Tree127
1030Kill Process LeetCode Solution127
1031Ugly Numbers127
1032Next Greater Element III LeetCode Solution127
1033Find whether a subarray is in form of a mountain or not127
1034Advantages of BST over Hash Table127
1035Longest subsequence such that difference between adjacents is one127
1036String Matching in an Array Leetcode Solution127
1037Find Peak Element127
1038Design Hit Counter LeetCode Solution127
1039Construct Binary Tree from given Parent Array representation127
1040Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1041Boolean Parenthesization Problem127
1042Invalid Transactions LeetCode Solution127
1043Build an Array With Stack Operations Leetcode Solution127
1044Implement Trie (Prefix Tree) Leetcode Solution126
1045Minimum Size Subarray Sum126
1046Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’126
1047Maximum weight transformation of a given string126
1048Lowest Common Ancestor126
1049Kth Smallest Element in a Sorted Matrix LeetCode Solution126
1050Morris Inorder Traversal126
1051Maximum Product of Indexes of Next Greater on Left and Right126
1052K Closest Points to Origin Leetcode Solution126
1053Minimum Index Sum of Two Lists126
1054Available Captures for Rook Leetcode Solution126
1055Bitwise AND of Numbers Range LeetCode Solution125
1056Defanging an IP Address LeetCode Solution125
1057Count minimum steps to get the given desired array125
1058Path Sum II LeetCode Solution125
1059Ugly Number II LeetCode Solution125
1060Regular Expression Matching Regular Expression Matching LeetCode Solution125
1061Maximize Distance to Closest Person LeetCode Solution125
1062Find a Peak Element II LeetCode Solution125
1063Custom Sort String Leetcode Solution125
1064Maximum Sum of 3 Non-Overlapping Subarrays125
1065Add two numbers125
1066Validate Binary Search Tree125
1067Iterative Depth First Traversal of Graph125
1068Recover Binary Search Tree Leetcode Solution124
1069Binary Tree Right Side View LeetCode Solution124
1070Move all negative elements to end in order with extra space allowed124
1071Largest BST Subtree LeetCode Solution124
1072Divisible Pairs Counting124
1073Employee Importance LeetCode Solution124
1074Number of Closed Islands Leetcode Solution124
1075Super Ugly Number124
1076Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution123
1077Find Smallest Range Containing Elements from k Lists123
1078Count pairs from two sorted arrays whose sum is equal to a given value x123
1079Clone a Binary Tree with Random Pointers123
1080Maximum difference between frequency of two elements such that element having greater frequency is also greater123
1081Subarrays with K Different Integers Leetcode Solution123
1082Types of Binary Tree123
1083Print Next Greater Number of Q queries123
1084Binary Tree Data Structure123
1085Day of the Year Leetcode Solution123
1086Rearrange array such that even index elements are smaller and odd index elements are greater123
1087Serialize and Deserialize Binary Tree LeetCode Solution123
1088Remove Duplicates from Sorted Array II Leetcode Solution123
1089Populating Next Right Pointers in Each Node Leetcode Solution123
1090Print all triplets in sorted array that form AP123
1091Smallest Common Region Leetcode Solution122
1092Number of siblings of a given Node in n-ary Tree122
1093Consecutive Characters LeetCode Solution122
1094Remove Palindromic Subsequences Leetcode Solution122
1095Find the minimum distance between two numbers122
1096Generate Parentheses Leetcode Solution122
1097Search in Sorted Rotated Array122
1098Path Sum122
1099Number of Students Doing Homework at a Given Time Leetcode Solution122
1100Longest Bitonic Subsequence122
1101Valid Tic-Tac-Toe State LeetCode Solution121
1102Bottom View of a Binary Tree121
1103Print Right View of a Binary Tree121
1104Remove duplicates from sorted array121
1105Kth Smallest Product of Two Sorted Arrays LeetCode Solution121
1106Convert BST into a Min-Heap without using array121
1107Level of Each node in a Tree from source node121
1108Third Maximum Number Leetcode Solution121
1109Constant time range add operation on an array121
1110Combination Sum IV LeetCode Solution121
1111Root to Leaf path with target sum Leetcode Solutions121
1112Write Code to Determine if Two Trees are Identical121
1113Products of ranges in an array120
1114Search Insert Position120
1115Distinct Subsequences120
1116Palindrome Permutation LeetCode Solution120
1117Iterative method to find ancestors of a given binary tree120
1118Next Permutation Leetcode Solution120
1119Minimum sum of squares of character counts in a given string after removing k characters120
1120Find maximum difference between nearest left and right smaller elements120
1121Find Three Element From Different Three Arrays Such That a + b + c = sum119
1122Count Largest Group Leetcode Solution119
1123Increasing Triplet Subsequence LeetCode Solution119
1124Prime Palindrome LeetCode Solution119
1125Thousand Separator Leetcode Solution119
1126Maximum Product Subarray119
1127Maximum Binary Tree119
1128Minimum Score Triangulation of Polygon Leetcode Solution119
1129Longest Increasing Consecutive Subsequence119
1130Cutting a Rod119
1131Print modified array after executing the commands of addition and subtraction119
1132Topological Sorting119
1133Construct K Palindrome Strings LeetCode Solution118
1134Cells with Odd Values in a Matrix LeetCode Solution118
1135Search an Element in Sorted Rotated Array118
1136Golomb sequence118
1137Moser-de Bruijn Sequence118
1138Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution118
1139Mean of Array After Removing Some Elements Leetcode Solution118
1140Reformat The String Leetcode Solution118
1141Red-Black Tree Introduction117
1142Sum of Even Numbers After Queries117
1143Longest Subarray of 1’s After Deleting One Element LeetCode Solution117
1144Minimum Absolute Difference in BST Leetcode Solution117
1145Swap Nodes In Pairs117
1146K maximum sums of overlapping contiguous sub-arrays117
1147Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1148Transform a BST to Greater sum Tree117
1149Priority Queue116
1150Merge two BSTs with limited extra space116
1151Maximize sum of consecutive differences in a circular array116
1152Delete Nodes and Return Forest Leetcode Solution116
1153Kth Smallest Number in Multiplication Table Leetcode Solution116
1154Possible Bipartition LeetCode Solution116
1155Longest Repeated Subsequence116
1156Rotate Array116
1157Find maximum length Snake sequence116
1158Maximum Product of Splitted Binary Tree LeetCode Solution116
1159Count even length binary sequences with same sum of first and second half bits116
1160Binary Tree to Binary Search Tree Conversion116
1161K’th Largest element in BST using constant extra space116
1162Check Array Formation Through Concatenation Leetcode Solution116
1163Subset Sum Problem in O(sum) space116
1164Palindromic Substrings Leetcode Solution116
1165Queries for Number of Distinct Elements in a Subarray116
1166Factorial Trailing Zeroes LeetCode Solution116
1167Compare Strings by Frequency of the Smallest Character Leetcode Solution115
1168Decision Tree115
1169Find the smallest binary digit multiple of given number115
1170Bus Routes Leetcode Solution115
1171Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1172Find a sorted subsequence of size 3 in linear time114
1173Minimum Moves to Equal Array Elements LeetCode Solution114
1174Search Suggestions System LeetCode Solution114
1175Count Pairs Whose Products Exist in Array114
1176Minimum Sideway Jumps LeetCode Solution114
1177Closest Binary Search Tree Value Leetcode Solution114
1178First Bad Version114
1179Reverse a Path in BST using Queue113
1180Maximum number of segments of lengths a, b and c113
1181Diameter of N-Ary Tree LeetCode Solution113
1182Minimum Cost to Move Chips to The Same Position LeetCode Solution113
1183Number of Orders in the Backlog Leetcode Solution113
1184Given a binary tree, how do you remove all the half nodes?113
1185Matchsticks to Square Leetcode Solution112
1186Decrease Elements To Make Array Zigzag LeetCode Solution112
1187Contiguous Array LeetCode Solution112
1188Find Largest Value in Each Tree Row LeetCode Solution112
1189Queue Reconstruction by Height112
1190Swapping Nodes in a Linked List Leetcode Solution112
1191Web Crawler LeetCode Solution112
1192Lowest Common Ancestor in Binary Search Tree112
1193Reformat Date LeetCode Solution111
1194Moving Stones Until Consecutive Leetcode Solution111
1195Champagne Tower LeetCode Solution111
1196Array Queries for multiply replacements and product111
1197Convert Sorted Array to Binary Search Tree LeetCode Solutions111
1198Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution111
1199Closest Leaf in a Binary Tree LeetCode Solution111
1200Integer Break LeetCode Solution110
1201Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1202New 21 Game110
1203Valid Triangle Number110
1204Sum of Left Leaves LeetCode Solution110
1205Range Sum Query using Sparse Table110
1206Valid Perfect Square LeetCode Solution110
1207Maximum sum of pairs with specific difference110
1208Graph and its representation110
1209Maximum sum bitonic subarray110
1210Replace two consecutive equal values with one greater110
1211How to print maximum number of A’s using given four keys110
1212Kth Smallest Element in a BST109
1213BST to a Tree with Sum of all Smaller Keys109
1214The kth Factor of n Leetcode Solution109
1215Path Crossing Leetcode Solution109
1216Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution109
1217Range Queries for Longest Correct Bracket Subsequence109
1218Concatenation of Array LeetCode Solution109
1219Maximum Depth Of Binary Tree109
1220Write a function to get the intersection point of two Linked Lists109
1221Print modified array after multiple array range increment operations109
1222Arithmetic Slices II – Subsequence LeetCode Solution109
1223Maximum sum of a path in a Right Number Triangle108
1224Check if each internal node of a BST has exactly one child108
1225Guess The Word108
1226Design Skiplist LeetCode Solution108
1227Divide Two Integers Leetcode Solution108
1228Merge Sort108
1229Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1230Lowest Common Ancestor of a Binary Tree Leetcode Solution108
1231Check for Identical BSTs without building the trees107
1232Check if all levels of two Binary Tree are anagrams or not107
1233Graph Cloning107
1234Perfect Squares LeetCode Solution107
1235Sliding Window Median Leetcode Solution107
1236Count Subsets Having Distinct Even Numbers107
1237Flatten 2D Vector LeetCode Solution107
1238Check Completeness of a Binary Tree LeetCode Solution107
1239Queries on Probability of Even or Odd Number in given Ranges107
1240Longest Common Prefix Using Word by Word Matching106
1241Largest Plus Sign Leetcode Solution106
1242Symmetric Tree LeetCode Solution Leetcode Solution106
1243Maximize Elements Using Another Array106
1244Maximum Array from Two given Arrays Keeping Order Same106
1245LRU Cache Leetcode Solution106
1246Print n terms of Newman-Conway Sequence106
1247Power of Two106
1248Find minimum number of merge operations to make an array palindrome106
1249Mean of range in array105
1250Count and Toggle Queries on a Binary Array105
1251Bold Words in String LeetCode Solution105
1252Contiguous Array105
1253Find k-th smallest element in BST (Order Statistics in BST)105
1254Find Minimum in Rotated Sorted Array II LeetCode Solution105
1255Next greater element104
1256Verify Preorder Serialization of a Binary Tree104
1257Missing Number104
1258Merge k Sorted Lists Leetcode Solution103
1259Maximum Product Subarray103
1260Parallel Courses II LeetCode Solution103
1261Minimum Remove to Make Valid Parentheses LeetCode Solution103
1262Excel Sheet Column Title LeetCode Solution103
1263Check If a String Can Break Another String Leetcode Solution103
1264Print Ancestors of a Given Binary Tree Node Without Recursion103
1265Check if two nodes are on the same path in a Tree102
1266Image Overlap LeetCode Solution102
1267Smallest Range II Leetcode Solution102
1268Palindrome Partitioning101
1269Orderly Queue LeetCode Solution101
1270Minimum Time to Collect All Apples in a Tree LeetCode Solution101
1271Check in binary array the number represented by a subarray is odd or even101
1272Koko Eating Bananas LeetCode Solution100
1273Check if X can give change to every person in the Queue99
1274Min Cost Climbing Stairs LeetCode Solution98
1275Different Ways to Add Parentheses Leetcode Solution98
1276Number of elements less than or equal to a given number in a given subarray98
1277Merge Sorted Array98
1278Newman–Shanks–Williams prime98
1279Peeking Iterator LeetCode Solution98
1280Largest Submatrix With Rearrangements LeetCode Solution97
1281Maximum Sum Increasing Subsequence97
1282Find maximum average subarray of k length96
1283Number of indexes with equal elements in given range95
1284Queries for Decimal Values of Subarrays of a Binary Array95
1285Longest Substring Without Repeating Characters Leetcode Solution95
1286Range Minimum Query (Square Root Decomposition and Sparse Table)95
1287Check given array of size n can represent BST of n levels or not94
1288Maximum product of an increasing subsequence93
1289Binary Tree to Binary Search Tree Conversion using STL set93
1290Array Nesting Leetcode Solution93
1291Arranging Coins Leetcode Solution92
1292Minimum Number of People to Teach LeetCode Solution92
1293Minimum Total Space Wasted With K Resizing Operations LeetCode Solution91
1294Random Pick Index LeetCode Solution91
1295Find the Winner of the Circular Game LeetCode Solution91
1296Encoded String With Shortest Length LeetCode Solution91
1297Convert a BST to a Binary Tree such that sum of all greater keys is added to every key90
1298Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1299Reach a Number LeetCode Solution90
1300Queries on XOR of greatest odd divisor of the range90
1301Convert to Base -2 LeetCode Solution89
1302Jump Game IV LeetCode Solution89
1303Insert Delete GetRandom O(1) Leetcode Solution88
1304Palindrome Number LeetCode Solution86
1305Vertical Order Traversal of Binary Tree LeetCode Solution86
1306Add Two Numbers II Leetcode Solution86
1307Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution84
1308Print Maximum Length Chain of Pairs83
1309Design Underground System Leetcode Solution83
1310Continuous Subarray Sum LeetCode Solution82
1311Detect Capital Leetcode Solution80
1312Design A Leaderboard Leetcode Solution78
1313Substring with Concatenation of All Words Leetcode Solution75
1314Minimum Swaps to Group All 1’s Together Leetcode Solution75
1315Top K Frequent Elements LeetCode Solution72
1316Odd Even Linked List Leetcode Solution72
1317Minimum Path Sum Leetcode Solution72
1318Shifting Letters LeetCode Solution71
1319Decode String Leetcode Solution70
1320Maximum Population Year LeetCode Solution70
1321Binary Tree Inorder Traversal LeetCode Solution70
1322Count Sub Islands LeetCode Solution69
1323Shortest Unsorted Continuous Subarray LeetCode Solution69
1324Find the Town Judge LeetCode Solution69
1325Best Meeting Point LeetCode Solution68
1326Longest Common Subsequence LeetCode Solution68
1327Sum Root to Leaf Numbers LeetCode Solution67
1328Find the Town Judge LeetCode Solution66
1329Design Add and Search Words Data Structure LeetCode Solution65
1330Rectangle Overlap LeetCode Solution63
1331Maximum Population Year LeetCode Solution62
1332Insert into a Sorted Circular Linked List LeetCode Solution60
1333Score of Parenthesis LeetCode Solution60
1334Stone Game IV LeetCode Solution60
1335Range Sum Query 2D – Immutable LeetCode Solution59
1336Flatten Binary Tree to Linked List LeetCode Solution59
1337Valid Triangle Number LeetCode Solution58
1338Is Graph Bipartite? LeetCode Solution57
1339Reveal Cards In Increasing Order Leetcode Solution52
1340Divide Chocolate LeetCode Solution47
1341Range Sum of BST LeetCode Solution40
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution38
1343Sort Colors LeetCode Solution36
1344Reverse Integer Leetcode Solution36
1345Find K Closest Elements LeetCode Solution33
1346Rotate String LeetCode Solution30
1347Excel Sheet Column Number LeetCode Solution29
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution28
Translate »