Find the Town Judge LeetCode Solution

Difficulty Level Easy
Frequently asked in Adobe Amazon Apple Bloomberg Google
Arista Arista NetworksViews 72

Problem Statement:

Find the Town Judge Leetcode Solution: In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.

If the town judge exists, then:

  1. The town judge trusts nobody.
  2. Everybody (except for the town judge) trusts the town judge.
  3. There is exactly one person that satisfies properties 1 and 2.

You are given an array trust where trust[i] = [ai, bi] representing that the person labeled ai trusts the person labeled bi.

Return the label of the town judge if the town judge exists and can be identified, or return -1 otherwise.

Examples:

Example 1:

Input:

 n = 2, trust = [[1,2]]

Output:

 2

Example 2:

Input:

 n = 3, trust = [[1,3],[2,3]]

Output:

 3

Example 3:

Input:

 n = 3, trust = [[1,3],[2,3],[3,1]]

Output:

 -1

Approach for Find The Town Judge:

Idea:

We will be finding the person who trusts no one and is trusted by everyone. For this, we will use an array to store the count of people. For every element of trust, we will increment for trust[0] and will decrement for trust[1].

The idea is that in the end, the judge will be that guy whose count value will be equal to n-1 as everyone would be trusting him and he trust ain’t no one. This means that its count value would have been incremented n-1 times and decremented 0 times, with the final count as n-1.

We will iterate over the count array and will check for the index whose count value is n-1 and will return that index. If we don’t find any index with this value of count, then we will simply return -1.

Code:

Find The Town Judge C++ Leetcode Solution:

class Solution {
public:
    int findJudge(int n, vector<vector<int>>& trust) {
        int trust_count[n];
        memset(trust_count,0,sizeof(trust_count));
        
        for(auto it:trust){
            trust_count[it[0]-1]--;
            trust_count[it[1]-1]++;
        }
        
        for(int i=0;i<n;i++){
            if(trust_count[i]==n-1)
                return i+1;
        }
        return -1;
    }
};

Find The Town Judge Python Leetcode Solution:

class Solution:
    def findJudge(self, n: int, trust: List[List[int]]) -> int:
        trust_count = [0]*n
        
        for it in trust:
            trust_count[it[0]-1]-=1
            trust_count[it[1]-1]+=1
        
        for i in range(n):
            if trust_count[i]==n-1:
                return i+1
        return -1

Complexity Analysis of Find the Town Judge LeetCode Solution:

  • Time Complexity: The time complexity of the above code is O(n),  where n = the number of people.
  • Space Complexity: The space complexity of the above code is O(n).

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2826
2Java program to find the number of Nodes in a Binary Tree2506
3Reverse a string without affecting special characters2467
4Delete a node of a linked list at given position1981
5Palindrome using Recursion1878
6Insert nodes in a linked list in a sorted way (Ascending Order)1667
7Find elements pair from array whose sum equal to number1654
8Sort Elements by Frequency of Occurrences1637
9Write a program to print all permutations of a given string1611
10Find Minimum Distance Between Two Numbers in an Array1479
11Create a Doubly Linked List1450
12Quick Sort1423
13Reverse an Array1416
14Smallest window in a string containing all characters of another string1399
15Find a Triplet That Sum to a Given Value1363
16Recursively remove all adjacent duplicates1358
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1325
19Sum of numbers in String1322
20Smallest Positive Number Missing in an Unsorted Array1290
21Check if the Elements of an Array are Consecutive1259
22Detect a loop in the Linked List1243
23Largest Sum Contiguous Subarray1234
24Quick Sort on SIngly Linked List1220
25Subarray with Given Sum1216
26Print all Possible Combinations of R Elements in a given Array of size N1207
27Recursive function to do substring search1202
28Find the Maximum Repeating Number in Array1160
29Binary Tree Level order traversal in Java1128
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1110
32Maximum Subarray Sum using Divide and Conquer1105
33Remove characters from first string which are in second1073
34Find Leaders in an Array1064
35Swap nodes in the linked list1041
36Find the Number Occurring Odd Number of Times in an Array1008
37Arrange given Numbers to Form the Biggest Number II996
38Find the second most frequent character991
39Given a string find its first non-repeating character973
40Find Triplet in Array With a Given Sum967
41Given a sorted array and a number x, find the pair in array whose sum is closest to x958
42Total number of occurrences of a given item in the linked list958
43A Program to check if strings are rotations of each other or not949
44Print all possible words from phone digits937
45Find the Missing Number928
46Rearrange Positive and Negative Numbers Alternatively in Array925
47Longest Palindromic Substring907
48Segregate even and odd nodes in a linked list888
49Print Longest common subsequence885
50Union and Intersection of Two Linked Lists877
51Transform one string to another using minimum number of given operations872
52Check rearranged string can form a palindrome853
53Rearrange given Array in Maximum Minimum Form850
54Count Possible Triangles823
55Iterative Implementation of Quick Sort821
56Multiplication of Two Matrices806
57Check if the linked list is palindrome800
58Count of Triplets With Sum Less than Given Value796
59Rotate a Linked List795
60Stock Buy Sell to Maximize Profit795
61Concatenation of two strings766
62Tug of War763
63Print all duplicates in the input string759
64Count Number of Substrings with K Distinct Character’s758
65Find Nearest Greater and Smaller Element750
66Find Pythagorean Triplets from Array741
67The Celebrity Problem741
68Reverse String Without Temporary Variable735
69Remove ‘b’ and ‘ac’ from a given string734
70Find all Common Elements in Given Three Sorted Arrays731
71Remove all duplicates in an unsorted linked list713
72Find the Row with Maximum Number of 1’s712
73Find the Peak Element from an Array704
74Find the subarray whose sum is equal to a given number X697
75Remove Minimum Characters so that Two Strings Become Anagrams694
76Find Smallest Missing Number in a Sorted Array691
77Addition of Two Matrices690
78A Product Array Puzzle689
79Insertion Sort688
80Implement Two Stacks in an Array679
81Generate all Binary Strings Without Consecutive 1’s679
82Maximum Sum of Non Consecutive Elements672
83Maximum Product Subarray II660
84Lexicographic rank of string658
85Multiplication of Previous and Next650
86Check if Two given Matrices are Identical650
87Subtraction of Two Matrices639
88Merge K Sorted Arrays and Print Sorted Output636
89Move All the Zeros to the End of the Given Array634
90Online Algorithm for Checking Palindrome in a Stream627
91Form Minimum Number from Given Sequence of D’s and I’s626
92Divide a string in N equal parts626
93Check whether two strings are anagram of each other619
94Remove recurring digits in a given number618
95Maximum Circular Subarray Sum615
96Sort a stack using a temporary stack612
97Sort a linked list that is sorted alternating ascending and descending611
98Find the Minimum Element in a Sorted and Rotated Array609
99Move last element of the Linked List at first place605
100Subarray and Subsequence603
101First Circular Tour to Visit all the Petrol Bunks603
102Largest Subarray with Equal Number of 0’s and 1’s600
103Flattening a linked list598
104Compare two strings(linked lists)597
105Maximum Element in an Array which is Increasing and then Decreasing593
106Palindrome Permutations of a String587
107Elements Appear more than N/K times in Array584
108Majority Element581
109Palindromes in a given range580
110Run length encoding577
111Print all permutations with repetition575
112Pangram Checking573
113Minimum insertions to form a shortest palindrome573
114Merge a linked list into another at alternate positions569
115Minimum Characters to be Added at Front to Make String Palindrome569
116Remove all duplicates in a sorted linked list567
117Most repeating character in a string566
118Rearrange a given linked list in-place564
119Minimum number of Merge Operations to make an Array Palindrome564
120Rotate string to get lexicographically minimum string560
121Repeated Subsequence of Length Two or More558
122Print all anagrams together in a sequence of words556
123Reorder an Array According to the Given Indexes555
124Pancake Sorting Problem545
125Two Sum Leetcode Solution542
126Merge Overlapping Intervals II540
1273Sum Leetcode Solution539
128Clone a Linked List with next and random pointer538
129Transpose of a Matrix530
130Size of The Subarray With Maximum Sum529
131Remove Extra Spaces from a String525
132Removing Spaces from a String using stringstream525
133Remove duplicates from a string524
134Smallest Palindrome after Replacement522
135Check if a given string is a rotation of a palindrome521
136Maximum Sum Increasing Subsequence521
137Longest Palindrome can be Formed by Removing or Rearranging Characters518
138Partition Problem518
139Check whether Strings are K Distance Apart or Not509
140Generate all Binary Strings from Given Pattern506
141Insert Node in the Sorted Linked List504
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized504
143Delete Last Occurrence504
144Length of Longest valid Substring501
145Check if Two given Strings are Isomorphic to each other496
146Maximum difference between two elements such as larger element comes after smaller490
147Program to Toggle all Characters in a String487
148Given string is interleaving of two other strings or not486
149Count Minimum Steps to Get the given Array483
150Number of Smaller Elements on Right Side481
151Merge sort better than quick sort for linked lists480
152Find Pair with Given Difference478
153Check length of a String is Equal to the Number Appended at its Last478
154Find nth node of the Linked list from the end473
155Check if all Rows of a Matrix are Circular Rotations of Each Other473
156Longest Common Prefix using Divide and Conquer471
157Find a Fixed Point in a Given Array467
158Sort 0s 1s and 2s in an Array466
159Print all interleavings of given two strings462
160Reverse words in a given string459
161Find the Subarray of given length with Least Average458
162Compare Two Version Numbers457
163Median of Two Sorted Arrays LeetCode Solution455
164Print Reverse of a string (Recursion)454
165Split linked list using alternate nodes454
166Reorder Array Using Given Indexes454
167Merge two sorted linked lists such that merged list is in reverse order454
168Print string of odd length in ‘X’ format444
169Find K Length Subarray of Maximum Average440
170Find Element Using Binary Search in Sorted Array438
171Swap Kth Node from beginning with Kth Node from End437
172Print all Palindromic Partitions of a String432
173Find Duplicates in an Array in Most Efficient Way431
174print all palindromic partitions423
175Shortest Superstring Problem419
176Maximum Length of Chain Pairs419
177Flatten a multilevel linked list418
178Check if String Follows Order of Characters by a Pattern or not415
179Sorting a K Sorted Array412
180Sort a String According to Another String409
181Longest Span with same Sum in two Binary Arrays II403
182Reverse a Linked List in groups401
183Find a Sorted Subsequence of size 3400
184Program to add two binary digits396
185Recursively print all the sentences that can be formed from list of word lists394
186Find the two Numbers with Odd Occurrences in an Unsorted Array391
187Longest Common Prefix Using Binary Search II388
188Reverse a Singly Linked List (Iterative/Non-Recursive)385
189Caesar Cipher385
190Check if String can Become Empty by Recursively Deleting given Substring383
191Kth Non-repeating Character383
192Rotate Image by 90 degrees379
193Pancake Sorting379
194Rearrange a linked list in Zig-Zag379
195Longest Common Prefix Word by Word Matching373
196Permutations of a Given String Using STL372
197Perfect Reversible String370
198Merging Two Sorted Arrays367
199Increasing Subsequence of Length three with Maximum Product365
200Sort a linked list with 0s, 1s and 2s364
201Find the point where a monotonically increasing function becomes positive first time363
2021`s and 2`s complement of binary number362
203Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes362
204Find First non-repeating character in a string362
205Four Elements that Sum to Given355
206List items containing all characters of a given word355
207Delete N nodes after M354
208Count Number of Occurrences in a Sorted Array350
209Longest Common Prefix using Character by Character Matching349
210Split a string345
211Palindrome string (number)344
212Minimum Characters to be Removed to Make a Binary String Alternate341
213Recursive Implementation of atoi()339
214Check if a Linked list of Strings form a Palindrome336
215Print All Distinct Elements of the Array335
216Even Substring Count333
217Sorting the array of strings332
218Valid Parentheses LeetCode Solution332
219Convert a String that is Repetition of a Substring of Length K332
220Reverse a singly linked list recursively331
221Maximum occurring character in a string330
222Find the first Repeating Number in a Given Array330
223Can we reverse a linked list in less than O(n) time ?326
224Print Shortest Path to Print a String on Screen326
225Binary Tree to Doubly linked list324
226Reverse a String using Stack323
227Convert string1 to string2 in one edit323
228Nth Character in Concatenated Decimal String322
229wildcard character matching320
230Maximum Subarray Leetcode Solution320
231Sort Elements by Frequency II320
232Lower Case To Upper Case317
233Count the number of words315
234Merge Two Sorted Arrays314
235Find the Lost Element From a Duplicated Array312
236Split Four Distinct Strings311
237Find middle of the Linked List310
238Longest Common Subsequence with Permutations306
239Count the Pairs at Same Distance as in English Alphabets302
240Matrix Chain Multiplication using Dynamic Programming299
241Next Greater Element in an Array296
242Palindrome Permutation293
243Roman to Integer Leetcode Solution290
244Find All Pairs With a Given Difference287
245Find Nth Node286
246Triplet from three linked lists with given sum285
247Searching a node in a Binary Search Tree285
248String(represents an integer) to value282
249Delete a Tree281
250Word Search Leetcode Solution281
251Reverse a String280
252Reverse Bits279
253Print all Possible Ways to Break a String in Bracket Form278
254Binary Tree276
255How to Efficiently Implement k Stacks in a Single Array?275
256Change Gender of a given String274
257Delete a node under given conditions274
258Sort an array of strings273
259First non Repeating Element272
260Meeting Rooms II LeetCode Solution271
261Count Pairs With Given Sum270
262Number of sub-strings which recursively add up to 9269
263Longest Common Extension269
264Remove middle points in a linked list of line segments269
265Repeated Substring Pattern268
266Toeplitz Matrix267
267Move all negative elements to one side of array266
268Longest Palindromic Substring LeetCode Solution264
269Remove spaces from a string263
270Shuffle a given Array263
271Min Stack262
272N queen problem261
273Number of Islands LeetCode Solution257
274Cuckoo sequence program257
275Dijkstra Algorithm256
276Minimize the maximum difference between the heights253
277Max stack253
278House Robber Leetcode Solution253
279Find, second, frequent, character252
280Most Frequent Element in an Array251
281Search Insert Position Leetcode Solution250
282Clone a linked list with next and random pointer (Hashing)249
283Valid Palindrome Leetcode Solution247
284Expression Evaluation247
285Sort linked which is sorted on absolute values247
286Plus One Leetcode Solution246
287KMP Algorithm246
288Sudoku Solver245
289Subset Leetcode245
290Reverse words in a string244
291Fibonacci numbers244
292Combination Sum Leetcode Solution243
293Number Of 1 bits243
294Min Stack Leetcode Solution243
295Evaluation of Postfix Expression242
296How to Delete a Linked List242
297Word Search240
298Backspace String Compare236
299Set Matrix Zeroes234
300Merge Sorted Arrays Leetcode Solution234
301Pair of Positive Negative Values in an Array233
302Sqrt(x) Leetcode Solution233
303Subarray with 0 sum232
304Reversing a Queue232
305Rabin Karp Algorithm231
306Common elements in all rows of a given matrix230
307Contains Duplicate II Leetcode Solution230
308Product of array except self229
309Tower Of Hanoi228
310Integer to Roman Leetcode Solution227
311Delete middle element of a stack227
312Combination Sum227
313Pascal Triangle Leetcode226
314Intersection of Two Arrays II Leetcode Solution226
315Reverse individual words224
316String Compression224
317Sliding Window Technique222
318Minimum swaps required to bring all elements less than or equal to k together222
319Find Top K (or Most Frequent) Numbers in a Stream222
320Arithmetic Expression Evaluation221
321Construct Binary Tree from Given Inorder and Preorder Traversals221
322Count of index pairs with equal elements in an array221
323Single Number Leetcode Solution221
324Count subarrays with equal number of 1’s and 0’s221
325Bellman Ford Algorithm220
326Implementation of Deque using Doubly Linked List220
327Minimum Value to Get Positive Step by Step Sum Leetcode Solution219
328Add Binary Leetcode Solution219
329Contains Duplicate219
330Segregate even and odd numbers218
331Second Most Repeated Word in a Sequence218
332Palindrome Linked List Leetcode Solution218
333Pow(x, n) Leetcode Solution218
334Sort elements by frequency218
335Count Odd Numbers in an Interval Range Leetcode Solution216
336Page Replacement Algorithms in Operating Systems216
337Find sum of non-repeating elements (distinct) elements in an array216
338Design a stack that supports getMin() in O(1) time and O(1) extra space216
339Postfix to Infix Conversion216
340Kruskal Algorithm215
341Maximum Number of Balloons Leetcode Solution215
342Next Permutation215
343Third Maximum Number Leetcode Solution214
344Group Words With Same Set of Characters214
345K-th Smallest Element in a Sorted Matrix212
346Sum of minimum and maximum elements of all subarrays of size k212
347Convex Hull Algorithm211
348Smallest Subarray with k Distinct Numbers211
349Permutations Leetcode Solution211
350Longest Substring Without Repeating Characters LeetCode Solution211
351Top K Frequent Words210
352Longest Common Prefix Leetcode Solution210
353Find the Town Judge Leetcode Solution210
354Find Lucky Integer in an Array Leetcode Solution209
355Majority Element Leetcode Solution209
356Sorting array using Stacks209
357Maximum Subarray209
358Spiral Matrix LeetCode Solution208
359Find Numbers with Even Number of Digits Leetcode Solution208
360Scramble String208
361Swap Nodes in Pairs Leetcode Solutions207
362Count subarrays having total distinct elements same as original array207
363First element occurring k times in an array207
364Number of Good Pairs Leetcode Solution206
365Prefix to Infix Conversion206
366Evaluate Division206
367Minimum operation to make all elements equal in array206
368Minimum Path Sum205
369Merge Two Sorted Lists Leetcode Solutions205
370Missing Number Leetcode Solution205
371Given two unsorted arrays find all pairs whose sum is x205
372Special Number205
373Search in Rotated Sorted Array Leetcode Solution205
374Count Primes Leetcode Solutions204
375Check if two arrays are equal or not204
376Best Time to Buy and Sell Stock  II Leetcode Solution204
377Huffman Coding203
378Minimum Absolute Difference Leetcode Solution203
379Reverse a Number Using Stack203
380Sort Array by Increasing Frequency Leetcode Solution202
381Pascal’s Triangle II Leetcode Solution202
382Top K Frequent Elements202
383Power of Two Leetcode Solution202
384Reversing the First K elements of a Queue202
385Find All Numbers Disappeared in an Array Leetcode Solution202
386Maximum possible difference of two subsets of an array201
387Unique Paths Leetcode Solution201
388Group Anagrams201
389Maximal Square201
390House Robber II Leetcode Solution201
391Minimum Steps to reach target by a Knight201
392Find duplicates in a given array when elements are not limited to a range201
393Fizz Buzz Leetcode200
394Matrix Diagonal Sum Leetcode Solution200
395Single Number200
396Find Minimum In Rotated Sorted Array199
397Running Sum of 1d Array Leetcode Solution199
398How Many Numbers Are Smaller Than the Current Number Leetcode Solution199
399Sorting using trivial hash function199
400Maximum Distance Between two Occurrences of Same Element in Array198
401Leetcode Permutations198
402Sort Integers by The Number of 1 Bit Leetcode Solution198
403Coin Change 2 Leetcode Solution197
404How to Implement Stack Using Priority Queue or Heap?197
405Find the Closest Palindrome number197
406Range Sum Query 2D – Immutable Leetcode Solution197
407Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution197
408Unique Paths197
409Happy Number Leetcode Solution197
410Max Consecutive Ones Leetcode Solution196
411Expression Contains Redundant Bracket or Not196
412Find Number of Employees Under every Employee195
413Convert String To Int195
414Find Winner on a Tic Tac Toe Game Leetcode Solution195
415Subarray Sum Equals k195
416Difference between highest and least frequencies in an array195
417Decode String195
418Monotonic Array LeetCode Solution195
419Remove Duplicates from Sorted Array Leetcode Solution195
420Zigzag Conversion195
421Subarray Sum Equals K LeetCode Solution194
422Fibonacci Number LeetCode Solution194
423Best Time to Buy and Sell Stock III Leetcode Solution194
424Length of the largest subarray with contiguous elements194
425Smallest Element Repeated Exactly K Times194
426Reverse Integer194
427Check if Array Contains Contiguous Integers With Duplicates Allowed194
428Find top three repeated in array193
429Capacity To Ship Packages Within D Days Leetcode Solution193
430Implement Stack and Queue using Deque193
431Subset sum problem193
432Subtract the Product and Sum of Digits of an Integer Leetcode Solution193
433Find Median from data Stream193
434Palindrome Substring Queries193
435Find The Duplicate Number193
436Reverse Vowels of a String Leetcode Solution193
437Letter Case Permutation192
438Check If N and Its Double Exist Leetcode Solution192
439Reverse a Stack Using Recursion192
440Reverse Words in a String III LeetCode Solution192
441Delete a Node from linked list without head pointer192
442Shuffle the Array Leetcode Solution191
443Maximum Depth of Binary Tree Leetcode Solution191
444Generate a String With Characters That Have Odd Counts Leetcode Solution191
445Print All Distinct Elements of a Given Integer Array191
446LRU Cache Implementation191
447Nth Catalan Number191
448Sort a stack using recursion191
449Subarrays with distinct elements190
450Cumulative Frequency of Count of Each Element in an Unsorted Array190
451Priority Queue Using Singly Linked List190
452Find the Duplicate Element190
453Bipartite Graph190
454Trapping Rain Water Leetcode Solution190
455Prim’s Algorithm190
456Kth largest element in an Array Leetcode Solutions189
457Reverse a String189
458Sorting a Queue without Extra Space189
459Target Sum189
460Find Common Characters Leetcode Solution189
461Excel Sheet Column Number Leetcode Solution189
462Count Substrings with equal number of 0s, 1s and 2s189
463Find all pairs (a, b) in an array such that a % b = k188
464Find the first repeating element in an array of integers188
465Sum of Subarray Ranges Leetcode Solution188
466Integer to English words188
467Iterative Tower of Hanoi188
468Longest Common Subsequence188
469Print all subarrays with 0 sum188
470Concatenation of Array LeetCode Solution187
471Find elements which are present in first array and not in second187
472Find First and Last Position of Element in Sorted Array Leetcode Solution187
473Minimum Moves to Equal Array Elements Leetcode Solution187
474Fizz Buzz187
475Find the Difference Leetcode Solution187
476Balanced Binary Tree Leetcode Solution187
477Kids With the Greatest Number of Candies Leetcode Solution187
478The K Weakest Rows in a Matrix Leetcode Solution187
479Word Ladder LeetCode Solution187
480Count pairs from two linked lists whose sum is equal to a given value186
481Merge Two Sorted Linked Lists186
482Floyd Warshall Algorithm186
483Number of Steps to Reduce a Number to Zero Leetcode Solution186
484Kth Largest Element in a Stream Leetcode Solution185
485Next Greater Element I Leetcode Solution185
486Text Justification LeetCode Solution185
487Merge Overlapping Intervals185
488Edit Distance184
489Reverse a linked list184
490Count and Say184
491Longest Common Prefix using Trie184
492Design Parking System Leetcode Solution184
493Multiply Strings Leetcode Solution184
494Zigzag Conversion LeetCode Solution184
495Count and Say Leetcode Solution183
496Slowest Key Leetcode Solution183
497Mobile Numeric Keypad Problem183
498Peak Index in a Mountain Array183
499Max Area of Island183
500Remove Minimum Number of Elements Such That no Common Element Exist in both Array183
501Move Zeroes LeetCode Solution183
502Prefix to Postfix Conversion183
503Degree of an array183
504The Stock Span Problem183
505Length of Last Word Leetcode Solution183
506Flood Fill LeetCode183
507Implement a stack using single queue182
508Shuffle String Leetcode Solution182
509Find distinct elements common to all rows of a matrix182
510MiniMax Algorithm182
511Intersection of Two Arrays182
512Next Greater Frequency Element182
513Last Stone Weight181
514Top View of Binary Tree181
515Priority Queue in C++181
516Jump Game Leetcode Solution181
517Find subarray with given sum (Handles Negative Numbers)181
518Convert array into Zig-Zag fashion181
519Valid Parenthesis String181
520Substring With Concatenation Of All Words181
521Postfix to Prefix Conversion180
522Find N Unique Integers Sum up to Zero Leetcode Solution180
523Recursion179
524Contiguous Array Leetcode179
525Find any one of the multiple repeating elements in read only array179
526Iterative Inorder Traversal of a Binary Tree179
527Longest subarray not having more than K distinct elements179
528Shortest Palindrome179
529Find Index of Closing Bracket for a Given Opening Bracket in an Expression179
530Koko Eating Bananas Leetcode Solution179
531Pair with given product179
532Smallest Subarray With all Occurrences of a Most Frequent Element178
533Container with Most Water178
534Delete Node in a Linked List Leetcode Solution178
535Find four elements that sum to a given value (Hashmap)178
536Implement Stack using Queues178
537N-th Tribonacci Number Leetcode Solution178
538Longest Common Prefix using Sorting178
539Excel Sheet Column Title Leetcode Solution178
540Relative Sort Array Leetcode Solution178
541Count number of triplets with product equal to given number178
542Check if a given array contains duplicate elements within k distance from each other178
543Minimum Operations to convert X to Y177
544First negative integer in every window of size k177
545Convert a normal BST to Balanced BST177
546Is Subsequence Leetcode Solution177
547Find missing elements of a range177
548Isomorphic Strings Leetcode Solution177
549Best Time to Buy and Sell Stock177
550Jewels and Stones Leetcode Solution177
551K-th Distinct Element in an Array176
552Remove Linked List Elements Leetcode Solution176
553Largest Perimeter Triangle Leetcode Solution176
554Implementation of Deque using circular array176
555Sum of Left Leaves Leetcode Solutions176
556Assign Cookies Leetcode Solution176
557Check for Balanced Parentheses in an Expression175
558Find Words That Can Be Formed by Characters Leetcode Solution175
559Build Array From Permutation Leetcode Solution175
560Shuffle an Array175
561Linked List Cycle II LeetCode Solution175
562Minimum Bracket Reversals175
563Valid Anagrams175
56401 Matrix LeetCode Solution175
565Valid Sudoku175
566Island Perimeter Leetcode Solution175
567Maximum sum rectangle in a 2D matrix174
568Arrange given numbers to form the biggest number174
569Group Multiple Occurrence of Array Elements Ordered by first Occurrence174
570Convert Sorted Array to Binary Search Tree Leetcode Solution174
571Integer to Roman174
572Summary Ranges Leetcode Solution174
573Decode Ways174
574Distribute Candies to People Leetcode Solution174
575Change the Array into Permutation of Numbers From 1 to N174
576Combinations Leetcode Solution174
577Largest Sum Contiguous Subarray174
578Count the number of nodes at given level in a tree using BFS173
579Find the smallest positive integer value that cannot be represented as sum of any subset of a given array173
580Gold Mine Problem173
581Minimum Delete Operations to make all Elements of Array Same173
582Insert Interval Leetcode Solution173
583Hamming Distance173
584Unique Binary Search Trees173
585Count all subsequences having product less than K173
586Rotate List Leetcode Solution173
587LRU Cache LeetCode Solution173
588Minimum Knight Moves LeetCode Solution172
5893Sum Closest LeetCode Solution172
590Maximum path sum in a triangle172
591The Knapsack Problem172
592Trapping Rain Water LeetCode Solution172
593Maximum Number of Chocolates to be Distributed Equally Among k Students172
594Maximum Distance in Array172
595Distance Between Bus Stops Leetcode Solution172
596Minimum number of distinct elements after removing m items172
597Shortest Path in a Grid with Obstacles Elimination LeetCode Solution171
598Rearrange a binary string as alternate x and y occurrences171
599Rotate Image LeetCode Solution171
600K Empty Slots LeetCode170
601Sieve of Eratosthenes170
602Stone Game LeetCode170
603Permutation in String Leetcode Solution170
604Same Tree LeetCode Solution170
605Sort Array By Parity LeetCode Solution169
606Remove All Occurrences of a Substring LeetCode Solution169
607Find minimum difference between any two elements169
608Minimum number of subsets with distinct elements169
609Replace Elements with Greatest Element on Right Side Leetcode Solution169
610Best Time to Buy and Sell Stock LeetCode Solution168
611Applications of Breadth First Search and Depth First Search168
612Distance of nearest cell having 1 in a binary matrix168
613Sort Characters By Frequency LeetCode Solution168
614Find the Duplicate Number LeetCode Solution168
615Tracking current Maximum Element in a Stack168
616Word Pattern168
617Printing brackets in Matrix Chain Multiplication Problem168
618House Robber168
619XOR Operation in an Array Leetcode Solution168
620Defanging an IP Address Leetcode Solution168
621How to check if two given sets are disjoint?168
622Maximum Consecutive Numbers Present in an Array168
623License Key Formatting Leetcode Solution168
624Coin Change Problem167
625Find Sum of all unique sub-array sum for a given array167
626Minimum Depth of Binary Tree Leetcode Solution167
627Minimum insertions to form a palindrome with permutations allowed167
628Find if an Expression has Duplicate Parenthesis or Not167
629Maximum difference between first and last indexes of an element in array167
630Word Wrap Problem167
631Painting Fence Algorithm167
632Frog Jump Leetcode Solution167
633Smallest Good Base167
634Segregate 0s and 1s in an Array167
635Queries for counts of array elements with values in given range166
636Longest Substring with At Most K Distinct Characters LeetCode Solution166
637Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions166
638Sum of All Odd Length Subarrays Leetcode Solution166
639Check If It Is a Straight Line Leetcode Solution166
640Longest Substring with At Least K Repeating Characters LeetCode Solution165
641Maximum Number of Occurrences of a Substring Leetcode Solution165
642Best Time to Buy and Sell Stock with Cooldown Leetcode Solution165
643Merge Two Balanced Binary Search Trees165
644Binary Tree Zigzag Level Order Traversal LeetCode Solution165
645Count Good Nodes in Binary Tree Leetcode Solution165
646Reverse a stack without using extra space in O(n)165
647Minimum Cost to Hire K Workers165
648Isomorphic Strings165
649Kth Missing Positive Number Leetcode Solution164
650Employee Free Time LeetCode Solution164
651Strobogrammatic Number LeetCode Solution164
652Iterative Method to find Height of Binary Tree164
653Delete consecutive same words in a sequence164
654Optimal Account Balancing LeetCode Solution164
655Number of Provinces Leetcode Solution164
656Find Maximum Level sum in Binary Tree164
657Wiggle Sort164
658Valid Palindrome II Leetcode Solution164
659Letter Combinations of a Phone Number164
660Find pairs with given sum such that elements of pair are in different rows163
661GCD Of Two Numbers163
662Longest Increasing Subsequence163
663Reorganize String163
664Non-overlapping sum of two sets163
665Power of Four Leetcode Solution163
666Valid Perfect Square Leetcode Solution163
667Path With Maximum Minimum Value LeetCode Solution163
668Edit Distance LeetCode Solution163
669Partition Labels LeetCode Solution163
670Recover Binary Search Tree162
671Maximum Number of Coins You Can Get Leetcode Solution162
672Print the Fibonacci numbers in reverse order162
673Valid Palindrome162
674Moving Average from Data Stream Leetcode Solution162
675Find the Distance Value Between Two Arrays Leetcode Solution162
676Reducing Dishes LeetCode Solution162
677Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest162
678Convert an array to reduced form161
679Dynamic Programming Basics161
680Permutation Sequence LeetCode Solution161
681String to Integer (atoi) LeetCode Solution161
682Sort Array by Increasing Frequency Leetcode Solution161
683Longest Increasing Path in a Matrix LeetCode Solution161
684To Lower Case Leetcode Solution161
685BFS vs DFS for Binary Tree161
686Ugly Number Leetcode Solution161
687Inorder Successor of a node in Binary Tree161
688Flipping an Image LeetCode Solution161
689Find Largest d in Array such that a + b + c = d161
690How to Create Mergable Stack?160
691Subset Sum Leetcode160
692Find Leaves of Binary Tree LeetCode Solution160
693Maximum Product of Two Elements in an Array Leetcode Solution160
694Form minimum number from given sequence160
695Check If Two String Arrays are Equivalent Leetcode Solution160
696Check if a queue can be sorted into another queue using a stack160
697Number of Dice Rolls With Target Sum LeetCode Solution160
698Populating Next Right Pointers in Each Node160
699Restore IP Addresses Leetcode Solution160
700K Empty Slots160
701Factorial Trailing Zeroes Leetcode Solution160
702Partition Array Into Three Parts With Equal Sum Leetcode Solution160
703Reservoir Sampling160
704Find whether an array is subset of another array160
705Reverse Only Letters LeetCode Solution160
706Reversing a Queue using Recursion160
707Unique Paths II Leetcode Solution159
708Construct BST from given Preorder Traversal159
709Remove Invalid Parentheses Leetcode Solution159
710Binary Tree zigzag level order Traversal159
711Add and Search Word – Data structure design LeetCode159
712Delete Nth node from the end of the given linked list159
713Increasing Decreasing String Leetcode Solution159
714Majority Element II Leetcode Solution159
715Bulb Switcher LeetCode Solution158
716Find Pair with Greatest Product in Array158
717Robot Room Cleaner Leetcode Solution158
718Minimum Cost For Tickets Leetcode Solution158
719Find the Smallest Divisor given a Threshold Leetcode Solution158
720Convert a Number to Hexadecimal Leetcode Solution158
721Lucky Numbers in a Matrix Leetcode Solution158
722Perform String Shifts Leetcode158
723Find the largest multiple of 3158
724Merge Two Binary Trees LeetCode Solution158
725Sum of f(a[i], a[j]) over all pairs in an array of n integers157
726Binomial Coefficient157
727First Unique Character in a String LeetCode Solution157
728Find the node with minimum value in a Binary Search Tree157
729Keyboard Row Leetcode Solution157
730Morris Traversal157
731Maximum Product of Three Numbers LeetCode Solution156
732Student Attendance Record I Leetcode Solution156
733Decompress Run-Length Encoded List Leetcode Solution156
734Hamming Distance Leetcode Solution156
735Non-decreasing Array LeetCode Solution156
736Bubble sort using two Stacks156
737Rank Transform of an Array Leetcode Solution156
738Elements to be added so that all elements of a range are present in array155
739Finding K closest element155
740Minimum Distance Between BST Nodes Leetcode Solution155
741Merge K Sorted Linked Lists155
742Best Meeting Point LeetCode Solution155
743Diagonal Traversal of Binary Tree155
744Sorted Linked List to Balanced BST155
745Maximum 69 Number Leetcode Solution155
746Binary Tree Maximum Path Sum LeetCode Solution155
747Word Pattern LeetCode Solution155
748Find Median from Data Stream LeetCode Solution155
749Invert Binary Tree LeetCode Solution155
750Search a 2D Matrix II Leetcode Solution154
751String Compression LeetCode Solution154
752Special Array With X Elements Greater Than or Equal X Leetcode Solution154
753Queue based approach for first non-repeating character in a stream154
754Snakes and Ladders LeetCode Solution154
755Find if Path Exists in Graph Leetcode Solution154
756Find unique character in a string154
757Split a String in Balanced Strings Leetcode Solution154
758Minimum time required to rot all oranges154
759Largest subarray with equal number of 0s and 1s154
760Minimum Height Trees154
761Largest rectangular sub-matrix whose sum is 0154
762Evaluate Reverse Polish Notation LeetCode Solution154
763Stack Permutations (Check if an array is stack permutation of other)154
764Tiling Problem154
765Symmetric Tree Leetcode Solution154
766Maximum Length of a Concatenated String with Unique Characters Leetcode Solution154
767Maximum Depth of N-ary Tree Leetcode Solution154
768Kth ancestor of a node in binary tree154
769Maximum Difference Between Increasing Elements LeetCode Solution154
770Number of Islands II LeetCode Solution154
771Find All Duplicates in an Array LeetCode Solution154
772Generate all possible sorted arrays from alternate elements of two given sorted arrays154
773Transpose Graph153
774Race Car LeetCode Solution153
775Final Prices With a Special Discount in a Shop Leetcode Solution153
776k-th missing element in increasing sequence which is not present in a given sequence153
777Largest Rectangle in Histogram LeetCode Solution153
778Jump Game153
779Numbers with prime frequencies greater than or equal to k153
780Deletion in a Binary Tree153
781Minimize Maximum Pair Sum in Array LeetCode Solution153
782Search in a Binary Search Tree Leetcode Solution153
783Check If Array Pairs Are Divisible by k LeetCode Solution153
784Count quadruples from four sorted arrays whose sum is equal to a given value x153
785Find Maximum Depth of Nested Parenthesis in a String152
786Minimum Time Visiting All Points Leetcode Solution152
787Interval Tree152
788Check if Two Expressions With Brackets are Same152
789Minimum number of jumps to reach end152
790Sort an array according to the order defined by another array152
791N-Queens LeetCode Solution152
792Longest Span with same Sum in two Binary arrays152
793Remove Nth Node From End of List Leetcode Solution152
794Minimum swaps to make sequences increasing152
795Remove Duplicates from Sorted List II152
796Program for Bridge and Torch problem152
797Crawler Log Folder Leetcode Solution151
798A Space Optimized DP solution for 0-1 Knapsack Problem151
799Linked List Cycle151
800Minimum Jumps to Reach Home LeetCode Solution151
801Remove brackets from an algebraic string containing + and – operators151
802Base 7 Leetcode Solution151
803Remove Duplicates from Sorted List LeetCode Solution151
804Last Stone Weight II LeetCode Solution151
805Partition to K Equal Sum Subsets Leetcode Solution151
806String comparison containing wildcards151
807Maximum Profit in Job Scheduling Leetcode Solution151
808Number of NGEs to the Right151
809Brick Wall LeetCode Solution150
810Iterative Preorder Traversal150
811One Edit Distance LeetCode Solution150
812Nearest Exit from Entrance in Maze LeetCode Solution150
813Course Schedule II – LeetCode150
814Nested List Weight Sum II LeetCode Solution150
815Find all triplets with zero sum150
816Print a Binary Tree in Vertical Order150
817Total Numbers With no Repeated Digits in a Range150
818Sort Array By Parity II Leetcode Solution150
819Relative Ranks Leetcode Solution150
820Valid Number150
821Number Complement Leetcode Solution150
822Maximum size subarray sum equals k150
823Reorder Data in Log Files LeetCode Solution150
824Check for Palindrome after every character replacement Query150
825Count items common to both the lists but with different prices149
826Path with maximum average value149
827Growable array based stack149
828Merge Sorted Array LeetCode Solution149
829Get Maximum in Generated Array Leetcode Solution149
830Convert BST to Min Heap149
831Top K Frequent Words LeetCode Solution149
832Find the subarray with least average149
833Valid Parentheses Leetcode Solution149
834Check whether a given Binary Tree is Complete or not149
835Can Place Flowers LeetCode Solution149
836Partition List Leetcode Solution149
837Alien Dictionary LeetCode Solution149
838Circular Queue149
839Subarray Product Less Than K LeetCode Solution149
840Sequences of given length where every element is more than or equal to twice of previous148
841Find the Only Repetitive Element Between 1 to N-1148
842Count Distinct Elements in Every Window of Size K148
843Level order Traversal in Spiral Form148
844Design a Stack With Increment Operation Leetcode Solution148
845Subsequence of Size K With the Largest Even Sum LeetCode Solution148
846Sort Colors148
847Clone Graph LeetCode Solution148
848Check if a given array can represent Preorder Traversal of Binary Search Tree148
849Regular Expression Matching148
850Form Minimum Number From Given Sequence148
851Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution148
852Find All Possible Recipes from Given Supplies LeetCode Solution148
853Longest Subarray Having Count of 1s One More than Count of 0s148
854Permutation Coefficient147
855Subset with sum divisible by m147
856Minimum Number of Taps to Open to Water a Garden LeetCode Solution147
857Insert into a Binary Search Tree Leetcode Solution147
858Priority Queue using doubly linked list147
859Maximum Nesting Depth of the Parentheses Leetcode Solution147
860Guess Number Higher or Lower LeetCode Solution147
861Friends Pairing Problem147
862Count Negative Numbers in a Sorted Matrix LeetCode Solution147
863Binary Search Tree Search and Insertion147
864Given an Array of Pairs Find all Symmetric Pairs in it147
865Matrix Chain Multiplication146
866Brightest Position on Street LeetCode Solution146
867Rearrange an Array Such that arr[i] is equal to i146
868GCDs of given index ranges in an array146
869Design Browser History LeetCode Solution146
870Union and Intersection of two Linked Lists146
871Distinct adjacent elements in an array146
872Sum of nearest smaller and greater number146
873Minimum Sum Path in a Triangle146
874Repeated Substring Pattern LeetCode Solution146
875Tree Traversal (Preorder, Inorder & Postorder)146
876K’th Largest Element in BST when modification to BST is not allowed146
877Spiral Matrix II Leetcode Solution146
878Sorted Array to Balanced BST145
879Daily Temperatures Leetcode Solution145
880Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution145
881Check if stack elements are pairwise consecutive145
882Number of Days Between Two Dates LeetCode Solution145
883Find Maximum Sum Possible Equal Sum of Three Stacks145
884Minimum Swaps to Make Strings Equal Leetcode Solution145
885Three way partitioning of an array around a given range145
886Diagonal Traverse LeetCode Solution145
887Robot Bounded In Circle LeetCode Solution145
888An Interesting Method to generate Binary Numbers from 1 to n145
889Destination City Leetcode Solution145
890Delete And Earn145
891Lemonade Change Leetcode Solution144
892Least Number of Unique Integers after K Removals Leetcode Solution144
893Diagonal Traversal LeetCode Solution144
894Check if an Array is Stack Sortable144
895Maximum Score After Splitting a String Leetcode Solution144
896Guess Number Higher or Lower II144
897LCS (Longest Common Subsequence) of three strings144
898Find distance between two nodes of a Binary Tree144
899Range sum queries without updates144
900Minimum sum of multiplications of n numbers144
901Count ways to reach the nth stair using step 1, 2 or 3144
902Missing Element in Sorted Array LeetCode Solution143
903Balanced Expression with Replacement143
904Check if the given array can represent Level Order Traversal of Binary Search Tree143
905Special Positions in a Binary Matrix Leetcode Solution143
906Construct Complete Binary Tree from its Linked List Representation143
907Vertical sum in a given binary tree143
908Water Bottles Leetcode Solution143
909Rearrange Spaces Between Words Leetcode Solution143
910Spiral Matrix III LeetCode Solution143
9114Sum143
912Alien Dictionary142
913Time Based Key-Value Store LeetCode Solution142
914A program to check if a binary tree is BST or not142
915Construct BST from its given Level Order Traversal142
916Shortest Word Distance Leetcode Solution142
917Set Matrix Zeroes Leetcode Solution142
918Remove Duplicates from Sorted List II LeetCode Solution142
919Number of Distinct Islands Leetcode Solution142
920BFS for Disconnected Graph142
921Trim a Binary Search Tree142
922Queries for GCD of all numbers of an array except elements in a given range142
923Identify and Mark Unmatched Parenthesis in an Expression142
924Insert Delete GetRandom142
925Palindrome Partitioning Leetcode Solution142
926Collect maximum points in a grid using two traversals141
927Difference Array | Range update query in O(1)141
928Longest Palindromic Subsequence141
929All Unique Triplets that Sum up to a Given Value141
930Queue using Stacks141
931Lexicographical Numbers Leetcode Solution141
932Strongly Connected Component141
933Binary array after M range toggle operations141
934Convert Sorted List to Binary Search Tree141
935Construct the Rectangle Leetcode Solution141
936Iterative Postorder Traversal Using Two Stacks141
937Split Array Into Consecutive Subsequences141
938Range LCM Queries141
939Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i141
940Infix to Postfix141
941Merge Two Sorted Lists Leetcode140
9423 Sum140
943Averages of Levels in Binary Tree140
944Binary Tree Longest Consecutive Sequence LeetCode Solution140
945Maximum Frequency Stack Leetcode Solution140
946Number of Equivalent Domino Pairs Leetcode Solution140
947Reverse Nodes in K-Group140
948Count Subarrays with Same Even and Odd Elements140
949Find Common Characters Leetcode Solution140
950Intersection of Two Linked Lists LeetCode Solution140
951Check if any two intervals overlap among a given set of intervals140
952Merging Intervals140
953Count Submatrices With All Ones LeetCode Solution140
954Largest area rectangular sub-matrix with equal number of 1’s and 0’s140
955Find all permuted rows of a given row in a matrix140
956Find the Difference Leetcode Solution139
957Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space139
958Count pair with Given Sum139
959Word Break139
960Can Make Arithmetic Progression From Sequence Leetcode Solution139
961Stone Game II Leetcode139
962Print Fibonacci sequence using 2 variables139
963Length of Longest Fibonacci Subsequence138
964Palindrome Partitioning138
965Product of Array Except Self LeetCode Solution138
966Three Consecutive Odds Leetcode Solution138
967Analyze User Website Visit Pattern LeetCode Solution138
968Maximize Sum of Array after K Negations Leetcode Solution138
969Minimum Height Trees LeetCode Solution138
970Longest Nice Substring LeetCode Solution138
971Height of a generic tree from parent array138
972Find postorder traversal of BST from preorder traversal137
973Sliding Window Maximum137
974Largest divisible pairs subset137
975Dividing Array into Pairs With Sum Divisible by K137
976Sign of the Product of an Array LeetCode Solution137
977Create Maximum Number137
978Symmetric Tree137
979Unique Paths II137
980Valid Boomerang Leetcode Solution137
981Maximum Product of Indexes of Next Greater on Left and Right137
982Maximum Product Subarray137
983Count Primes in Ranges137
984Kth Smallest Element in a BST Leetcode Solution137
985Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution137
986Friends Of Appropriate Ages LeetCode Solution137
987Level Order Traversal of Binary Tree137
988Median of Two Sorted Arrays137
989Asteroid Collision LeetCode Solution136
990First missing positive136
991Newman-Conway Sequence136
992Level order traversal using two Queues136
993Minesweeper LeetCode Solution136
994Boolean Parenthesization Problem136
995K Closest Points to Origin Leetcode Solution136
996Segment Tree136
997Breadth First Search (BFS) for a Graph136
998Maximum Subarray Sum Excluding Certain Elements136
999Number Of Longest Increasing Subsequence136
1000Pattern Occurrences using Stack136
1001Maximum subsequence sum such that no three are consecutive136
1002Binary Search Tree Delete Operation136
1003Maximum weight transformation of a given string136
1004My Calendar I LeetCode Solution136
1005The Painter’s Partition Problem136
1006Serialize and Deserialize Binary Tree135
1007Longest subsequence such that difference between adjacents is one135
1008Depth First Search (DFS) for a Graph135
1009Partition Equal Subset Sum135
1010Next Greater Element III LeetCode Solution135
1011Insertion in a Binary Tree135
1012Largest Substring Between Two Equal Characters Leetcode Solution135
1013Double the first element and move zero to end135
1014Find Duplicate Subtrees135
1015Morris Inorder Traversal135
1016String Matching in an Array Leetcode Solution135
1017Find the First Circular Tour that visits all the Petrol Pumps135
1018Graph Valid Tree LeetCode Solution135
1019Maximum Length of Repeated Subarray135
1020Find Maximum of Minimum for Every Window Size in a Given Array135
1021Boundary Traversal of binary tree134
1022Shortest Completing Word Leetcode Solution134
1023The Maze III LeetCode Solution134
1024Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’134
1025Make The String Great Leetcode Solution134
1026Decrypt String from Alphabet to Integer Mapping Leetcode Solution134
1027K maximum sums of overlapping contiguous sub-arrays134
1028Construction of Longest Increasing Subsequence (N log N)134
1029Count subarrays where second highest lie before highest134
1030Validate Binary Search Tree134
1031Climbing stairs134
1032Maximum Number of Ways to Partition an Array LeetCode Solution134
1033Kill Process LeetCode Solution134
1034Build an Array With Stack Operations Leetcode Solution134
1035Compute nCr % p133
1036Construct Binary Tree from given Parent Array representation133
1037Design Hit Counter LeetCode Solution133
1038Rearrange array such that even positioned are greater than odd133
1039Largest Number Leetcode Solution133
1040Move all negative elements to end in order with extra space allowed132
1041Ugly Number II LeetCode Solution132
1042Available Captures for Rook Leetcode Solution132
1043Minimum Index Sum of Two Lists132
1044Scramble String LeetCode Solution132
1045Defanging an IP Address LeetCode Solution132
1046Maximum Sum of 3 Non-Overlapping Subarrays132
1047Add two numbers132
1048Find number of pairs in an array such that their XOR is 0132
1049Invalid Transactions LeetCode Solution132
1050Super Ugly Number132
1051Balanced Binary Tree132
1052Binary Search Tree132
1053Advantages of BST over Hash Table132
1054Regular Expression Matching Regular Expression Matching LeetCode Solution131
1055Binary Tree Right Side View LeetCode Solution131
1056Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution131
1057Implement Trie (Prefix Tree) Leetcode Solution131
1058Generate Parentheses Leetcode Solution131
1059Iterative Depth First Traversal of Graph131
1060Ugly Numbers131
1061Maximum difference between frequency of two elements such that element having greater frequency is also greater131
1062Find a Peak Element II LeetCode Solution131
1063Custom Sort String Leetcode Solution131
1064Recover Binary Search Tree Leetcode Solution131
1065Bitwise AND of Numbers Range LeetCode Solution131
1066Number of palindromic paths in a matrix131
1067Count pairs from two sorted arrays whose sum is equal to a given value x131
1068Find Peak Element130
1069Employee Importance LeetCode Solution130
1070Rearrange array such that even index elements are smaller and odd index elements are greater130
1071Maximum length subsequence with difference between adjacent elements as either 0 or 1130
1072Path Sum II LeetCode Solution130
1073Largest BST Subtree LeetCode Solution130
1074Clone a Binary Tree with Random Pointers129
1075Find whether a subarray is in form of a mountain or not129
1076Maximize Distance to Closest Person LeetCode Solution129
1077Minimum Size Subarray Sum129
1078Serialize and Deserialize Binary Tree LeetCode Solution129
1079Kth Smallest Product of Two Sorted Arrays LeetCode Solution129
1080Longest Bitonic Subsequence129
1081Kth Smallest Element in a Sorted Matrix LeetCode Solution129
1082Distinct Subsequences129
1083Number of Students Doing Homework at a Given Time Leetcode Solution129
1084Binary Tree Data Structure129
1085Count minimum steps to get the given desired array129
1086Find Smallest Range Containing Elements from k Lists129
1087Remove Duplicates from Sorted Array II Leetcode Solution129
1088Remove Palindromic Subsequences Leetcode Solution128
1089Number of Closed Islands Leetcode Solution128
1090Combination Sum IV LeetCode Solution128
1091Search in Sorted Rotated Array128
1092Remove duplicates from sorted array128
1093Print all triplets in sorted array that form AP128
1094Constant time range add operation on an array128
1095Populating Next Right Pointers in Each Node Leetcode Solution128
1096Number of siblings of a given Node in n-ary Tree128
1097Increasing Triplet Subsequence LeetCode Solution128
1098Lowest Common Ancestor128
1099Types of Binary Tree128
1100Smallest Common Region Leetcode Solution128
1101Find Three Element From Different Three Arrays Such That a + b + c = sum127
1102Path Sum127
1103Root to Leaf path with target sum Leetcode Solutions127
1104Find the minimum distance between two numbers127
1105Subarrays with K Different Integers Leetcode Solution127
1106Next Permutation Leetcode Solution127
1107Find maximum difference between nearest left and right smaller elements126
1108Level of Each node in a Tree from source node126
1109Cells with Odd Values in a Matrix LeetCode Solution126
1110Minimum Score Triangulation of Polygon Leetcode Solution126
1111Divisible Pairs Counting126
1112Day of the Year Leetcode Solution126
1113Print Next Greater Number of Q queries126
1114Third Maximum Number Leetcode Solution126
1115Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution126
1116Write Code to Determine if Two Trees are Identical125
1117Sum of Even Numbers After Queries125
1118Count Largest Group Leetcode Solution125
1119Consecutive Characters LeetCode Solution125
1120Convert BST into a Min-Heap without using array125
1121Maximum Product Subarray125
1122Longest Subarray of 1’s After Deleting One Element LeetCode Solution125
1123Reformat The String Leetcode Solution125
1124Mean of Array After Removing Some Elements Leetcode Solution124
1125Thousand Separator Leetcode Solution124
1126Products of ranges in an array124
1127Subset Sum Problem in O(sum) space124
1128Minimum Absolute Difference in BST Leetcode Solution124
1129Search Insert Position124
1130Prime Palindrome LeetCode Solution124
1131Topological Sorting124
1132Moser-de Bruijn Sequence124
1133Print Right View of a Binary Tree124
1134Bottom View of a Binary Tree124
1135Maximum Binary Tree123
1136Diameter of N-Ary Tree LeetCode Solution123
1137Palindrome Permutation LeetCode Solution123
1138Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution123
1139Cutting a Rod123
1140Valid Tic-Tac-Toe State LeetCode Solution123
1141Golomb sequence123
1142Queries for Number of Distinct Elements in a Subarray122
1143Longest Increasing Consecutive Subsequence122
1144Swap Nodes In Pairs122
1145Find a sorted subsequence of size 3 in linear time122
1146Iterative method to find ancestors of a given binary tree122
1147Search an Element in Sorted Rotated Array122
1148Merge two BSTs with limited extra space122
1149Closest Binary Search Tree Value Leetcode Solution122
1150Check Array Formation Through Concatenation Leetcode Solution122
1151Possible Bipartition LeetCode Solution121
1152Construct K Palindrome Strings LeetCode Solution121
1153Maximum Product of Splitted Binary Tree LeetCode Solution121
1154Binary Tree to Binary Search Tree Conversion121
1155Minimum Sideway Jumps LeetCode Solution121
1156Bus Routes Leetcode Solution121
1157Minimum sum of squares of character counts in a given string after removing k characters121
1158Kth Smallest Number in Multiplication Table Leetcode Solution121
1159Print modified array after executing the commands of addition and subtraction121
1160Find maximum length Snake sequence120
1161Longest Repeated Subsequence120
1162Compare Strings by Frequency of the Smallest Character Leetcode Solution120
1163Transform a BST to Greater sum Tree120
1164Factorial Trailing Zeroes LeetCode Solution120
1165Find Largest Value in Each Tree Row LeetCode Solution120
1166Find the smallest binary digit multiple of given number120
1167Red-Black Tree Introduction120
1168Number of Orders in the Backlog Leetcode Solution119
1169Palindromic Substrings Leetcode Solution119
1170Minimum Cost to Move Chips to The Same Position LeetCode Solution119
1171Rotate Array119
1172Count even length binary sequences with same sum of first and second half bits119
1173Swapping Nodes in a Linked List Leetcode Solution119
1174Maximize sum of consecutive differences in a circular array119
1175Search Suggestions System LeetCode Solution119
1176Priority Queue119
1177Count Pairs Whose Products Exist in Array118
1178Maximum number of segments of lengths a, b and c118
1179Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution118
1180Minimum Moves to Equal Array Elements LeetCode Solution118
1181Web Crawler LeetCode Solution118
1182K’th Largest element in BST using constant extra space118
1183Delete Nodes and Return Forest Leetcode Solution118
1184Decision Tree118
1185Graph and its representation118
1186Maximum sum bitonic subarray118
1187Decrease Elements To Make Array Zigzag LeetCode Solution118
1188Queue Reconstruction by Height117
1189Reverse a Path in BST using Queue117
1190Lowest Common Ancestor in Binary Search Tree117
1191Contiguous Array LeetCode Solution117
1192How to print maximum number of A’s using given four keys117
1193Valid Triangle Number117
1194Matchsticks to Square Leetcode Solution117
1195Sum of Left Leaves LeetCode Solution116
1196First Bad Version116
1197Kth Smallest Element in a BST116
1198Moving Stones Until Consecutive Leetcode Solution116
1199Closest Leaf in a Binary Tree LeetCode Solution116
1200Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution116
1201Maximum sum of pairs with specific difference116
1202Array Queries for multiply replacements and product116
1203Convert Sorted Array to Binary Search Tree LeetCode Solutions116
1204Concatenation of Array LeetCode Solution115
1205Guess The Word115
1206Integer Break LeetCode Solution115
1207Minimum Swaps To Make Sequences Increasing LeetCode Solution115
1208Range Queries for Longest Correct Bracket Subsequence115
1209Given a binary tree, how do you remove all the half nodes?115
1210Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution114
1211Lowest Common Ancestor of a Binary Tree Leetcode Solution114
1212Replace two consecutive equal values with one greater114
1213Flatten 2D Vector LeetCode Solution114
1214Divide Two Integers Leetcode Solution114
1215Range Sum Query using Sparse Table114
1216Largest Plus Sign Leetcode Solution113
1217Reformat Date LeetCode Solution113
1218Power of Two113
1219LRU Cache Leetcode Solution113
1220Champagne Tower LeetCode Solution113
1221Perfect Squares LeetCode Solution113
1222Check Completeness of a Binary Tree LeetCode Solution113
1223The kth Factor of n Leetcode Solution113
1224Valid Perfect Square LeetCode Solution113
1225Arithmetic Slices II – Subsequence LeetCode Solution113
1226Maximum Depth Of Binary Tree113
1227Path Crossing Leetcode Solution113
1228Find Minimum in Rotated Sorted Array II LeetCode Solution112
1229Queries on Probability of Even or Odd Number in given Ranges112
1230Maximize Elements Using Another Array112
1231Check for Identical BSTs without building the trees112
1232Mean of range in array112
1233Write a function to get the intersection point of two Linked Lists112
1234Merge Sort112
1235Print modified array after multiple array range increment operations112
1236New 21 Game112
1237Parallel Courses II LeetCode Solution112
1238Longest Common Prefix Using Word by Word Matching112
1239Bold Words in String LeetCode Solution112
1240Print n terms of Newman-Conway Sequence111
1241Check if each internal node of a BST has exactly one child111
1242Maximum Value at a Given Index in a Bounded Array LeetCode Solution111
1243BST to a Tree with Sum of all Smaller Keys111
1244Maximum sum of a path in a Right Number Triangle111
1245Symmetric Tree LeetCode Solution Leetcode Solution111
1246Graph Cloning111
1247Sliding Window Median Leetcode Solution111
1248Contiguous Array110
1249Find minimum number of merge operations to make an array palindrome110
1250Missing Number110
1251Check if all levels of two Binary Tree are anagrams or not110
1252Count Subsets Having Distinct Even Numbers110
1253Maximum Product Subarray110
1254Design Skiplist LeetCode Solution110
1255Maximum Array from Two given Arrays Keeping Order Same109
1256Smallest Range II Leetcode Solution109
1257Excel Sheet Column Title LeetCode Solution108
1258Print Ancestors of a Given Binary Tree Node Without Recursion108
1259Count and Toggle Queries on a Binary Array108
1260Merge k Sorted Lists Leetcode Solution108
1261Image Overlap LeetCode Solution108
1262Koko Eating Bananas LeetCode Solution107
1263Check if two nodes are on the same path in a Tree107
1264Number of elements less than or equal to a given number in a given subarray107
1265Min Cost Climbing Stairs LeetCode Solution107
1266Minimum Remove to Make Valid Parentheses LeetCode Solution107
1267Find k-th smallest element in BST (Order Statistics in BST)107
1268Different Ways to Add Parentheses Leetcode Solution106
1269Check If a String Can Break Another String Leetcode Solution106
1270Next greater element106
1271Verify Preorder Serialization of a Binary Tree106
1272Palindrome Partitioning106
1273Peeking Iterator LeetCode Solution105
1274Orderly Queue LeetCode Solution103
1275Merge Sorted Array103
1276Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1277Longest Substring Without Repeating Characters Leetcode Solution102
1278Check in binary array the number represented by a subarray is odd or even102
1279Newman–Shanks–Williams prime102
1280Largest Submatrix With Rearrangements LeetCode Solution101
1281Array Nesting Leetcode Solution101
1282Check if X can give change to every person in the Queue101
1283Arranging Coins Leetcode Solution101
1284Encoded String With Shortest Length LeetCode Solution100
1285Maximum Sum Increasing Subsequence100
1286Minimum Total Space Wasted With K Resizing Operations LeetCode Solution98
1287Range Minimum Query (Square Root Decomposition and Sparse Table)98
1288Number of indexes with equal elements in given range98
1289Find maximum average subarray of k length98
1290Minimum Number of People to Teach LeetCode Solution97
1291Queries for Decimal Values of Subarrays of a Binary Array97
1292Maximum product of an increasing subsequence97
1293Random Pick Index LeetCode Solution97
1294Find the Winner of the Circular Game LeetCode Solution96
1295Add Two Numbers II Leetcode Solution95
1296Binary Tree to Binary Search Tree Conversion using STL set95
1297Vertical Order Traversal of Binary Tree LeetCode Solution95
1298Convert to Base -2 LeetCode Solution95
1299Convert a BST to a Binary Tree such that sum of all greater keys is added to every key94
1300Check given array of size n can represent BST of n levels or not94
1301Continuous Subarray Sum LeetCode Solution94
1302Palindrome Number LeetCode Solution94
1303Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution94
1304Insert Delete GetRandom O(1) Leetcode Solution93
1305Queries on XOR of greatest odd divisor of the range93
1306Jump Game IV LeetCode Solution93
1307Reach a Number LeetCode Solution93
1308Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution91
1309Design Underground System Leetcode Solution89
1310Print Maximum Length Chain of Pairs87
1311Detect Capital Leetcode Solution86
1312Design A Leaderboard Leetcode Solution85
1313Substring with Concatenation of All Words Leetcode Solution82
1314Minimum Swaps to Group All 1’s Together Leetcode Solution80
1315Minimum Path Sum Leetcode Solution79
1316Count Sub Islands LeetCode Solution79
1317Top K Frequent Elements LeetCode Solution79
1318Binary Tree Inorder Traversal LeetCode Solution77
1319Shifting Letters LeetCode Solution77
1320Best Meeting Point LeetCode Solution76
1321Decode String Leetcode Solution74
1322Find the Town Judge LeetCode Solution74
1323Longest Common Subsequence LeetCode Solution74
1324Odd Even Linked List Leetcode Solution73
1325Maximum Population Year LeetCode Solution73
1326Find the Town Judge LeetCode Solution72
1327Sum Root to Leaf Numbers LeetCode Solution71
1328Shortest Unsorted Continuous Subarray LeetCode Solution71
1329Design Add and Search Words Data Structure LeetCode Solution68
1330Rectangle Overlap LeetCode Solution67
1331Score of Parenthesis LeetCode Solution66
1332Range Sum Query 2D – Immutable LeetCode Solution66
1333Maximum Population Year LeetCode Solution66
1334Stone Game IV LeetCode Solution65
1335Insert into a Sorted Circular Linked List LeetCode Solution65
1336Flatten Binary Tree to Linked List LeetCode Solution64
1337Reveal Cards In Increasing Order Leetcode Solution63
1338Is Graph Bipartite? LeetCode Solution62
1339Valid Triangle Number LeetCode Solution60
1340Divide Chocolate LeetCode Solution53
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution47
1342Range Sum of BST LeetCode Solution45
1343Sort Colors LeetCode Solution42
1344Reverse Integer Leetcode Solution41
1345Find K Closest Elements LeetCode Solution40
1346Excel Sheet Column Number LeetCode Solution37
1347Rotate String LeetCode Solution36
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution35
1349Maximum Size Subarray Sum Equals k Leetcode Solution18
1350H-Index Leetcode Solution15
1351High Five LeetCode Solution14
Translate »