Find the Town Judge LeetCode Solution

Difficulty Level Easy
Frequently asked in Adobe Amazon Apple Bloomberg Google
Arista Networks Array Graph HashingViews 65

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 and we need to find 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 trust the person labeled bi.

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


Example 1:


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



Example 2:


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



Algorithm –


In order to find the solution to find the town judge, what we will do in this question is, we have to focus on the judge(the judge doesn’t trust anyone and everybody trusts the town judge). So there are n people including the town judge and we have a 2d array so the first person of each element trusts the second person so we will focus on the count of every element(range between 1 to N)  if the count of the element will be equal to N-1 that person will be a town judge.

Approach –

  • first, create one array of length(n+1).
  • increase the count if the element is placed in the second column of each row(it doesn’t trust anybody) and increase the count of the array[element].
  •  decrease the count if the element is placed in the first column of each row(it trusts anyone) and decrease the count of array[element].
  • then check for the count if the count is equal to n-1 return that index of the array.
  • else return -1.
  • Hence, we are now able to find the town judge

Find the Town Judge LeetCode SolutionPin

Find The Town Judge Leetcode Python Solution:

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

Find The Town Judge Leetcode Java Solution:

class Solution {
    public int findJudge(int n, int[][] trust) {
        int new_ar[] = new int[n+1];
        for(int t[] : trust){
        for(int i=1;i<=n;i++){
            if(new_ar[i]==n-1) return i;
        return -1;

Time Complexity

The Time Complexity of the above solution is O(len(trust)).

Space Complexity:

The Space Complexity of the above solution is O(N).


Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2814
2Java program to find the number of Nodes in a Binary Tree2497
3Reverse a string without affecting special characters2452
4Delete a node of a linked list at given position1972
5Palindrome using Recursion1772
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 Occurrences1622
9Write a program to print all permutations of a given string1598
10Find Minimum Distance Between Two Numbers in an Array1467
11Create a Doubly Linked List1443
12Quick Sort1414
13Reverse an Array1405
14Smallest window in a string containing all characters of another string1389
15Find a Triplet That Sum to a Given Value1353
16Recursively remove all adjacent duplicates1349
17First Repeating Element1330
18Arrange Even and Odd number such that Odd comes after Even1315
19Sum of numbers in String1308
20Smallest Positive Number Missing in an Unsorted Array1276
21Check if the Elements of an Array are Consecutive1246
22Detect a loop in the Linked List1233
23Largest Sum Contiguous Subarray1224
24Quick Sort on SIngly Linked List1211
25Subarray with Given Sum1207
26Print all Possible Combinations of R Elements in a given Array of size N1197
27Recursive function to do substring search1193
28Find the Maximum Repeating Number in Array1148
29Binary Tree Level order traversal in Java1121
30Find the First and Second Smallest Elements1116
31Check if two linked lists are identical1099
32Maximum Subarray Sum using Divide and Conquer1096
33Remove characters from first string which are in second1063
34Find Leaders in an Array1057
35Swap nodes in the linked list1030
36Find the Number Occurring Odd Number of Times in an Array999
37Arrange given Numbers to Form the Biggest Number II987
38Find the second most frequent character983
39Given a string find its first non-repeating character962
40Find Triplet in Array With a Given Sum955
41Given a sorted array and a number x, find the pair in array whose sum is closest to x949
42Total number of occurrences of a given item in the linked list949
43A Program to check if strings are rotations of each other or not940
44Print all possible words from phone digits927
45Find the Missing Number920
46Rearrange Positive and Negative Numbers Alternatively in Array912
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 operations860
52Rearrange given Array in Maximum Minimum Form840
53Check rearranged string can form a palindrome840
54Count Possible Triangles816
55Iterative Implementation of Quick Sort811
56Multiplication of Two Matrices796
57Check if the linked list is palindrome792
58Count of Triplets With Sum Less than Given Value787
59Rotate a Linked List787
60Stock Buy Sell to Maximize Profit784
61Concatenation of two strings755
62Tug of War754
63Count Number of Substrings with K Distinct Character’s750
64Print all duplicates in the input string747
65Find Nearest Greater and Smaller Element740
66Find Pythagorean Triplets from Array734
67The Celebrity Problem734
68Reverse String Without Temporary Variable728
69Remove ‘b’ and ‘ac’ from a given string726
70Find all Common Elements in Given Three Sorted Arrays724
71Remove all duplicates in an unsorted linked list706
72Find the Row with Maximum Number of 1’s701
73Find the Peak Element from an Array693
74Find the subarray whose sum is equal to a given number X692
75Insertion Sort684
76Remove Minimum Characters so that Two Strings Become Anagrams683
77Find Smallest Missing Number in a Sorted Array682
78A Product Array Puzzle679
79Addition of Two Matrices677
80Implement Two Stacks in an Array671
81Generate all Binary Strings Without Consecutive 1’s669
82Maximum Sum of Non Consecutive Elements666
83Maximum Product Subarray II657
84Lexicographic rank of string648
85Multiplication of Previous and Next640
86Check if Two given Matrices are Identical640
87Subtraction of Two Matrices630
88Merge K Sorted Arrays and Print Sorted Output630
89Move All the Zeros to the End of the Given Array624
90Divide a string in N equal parts619
91Form Minimum Number from Given Sequence of D’s and I’s618
92Online Algorithm for Checking Palindrome in a Stream617
93Check whether two strings are anagram of each other610
94Remove recurring digits in a given number607
95Maximum Circular Subarray Sum606
96Sort a linked list that is sorted alternating ascending and descending606
97Sort a stack using a temporary stack603
98Move last element of the Linked List at first place600
99Find the Minimum Element in a Sorted and Rotated Array597
100First Circular Tour to Visit all the Petrol Bunks595
101Subarray and Subsequence592
102Largest Subarray with Equal Number of 0’s and 1’s591
103Flattening a linked list589
104Compare two strings(linked lists)588
105Maximum Element in an Array which is Increasing and then Decreasing588
106Palindrome Permutations of a String581
107Elements Appear more than N/K times in Array576
108Majority Element572
109Run length encoding571
110Minimum insertions to form a shortest palindrome570
111Palindromes in a given range569
112Print all permutations with repetition569
113Pangram Checking565
114Rearrange a given linked list in-place561
115Remove all duplicates in a sorted linked list560
116Merge a linked list into another at alternate positions560
117Minimum Characters to be Added at Front to Make String Palindrome559
118Minimum number of Merge Operations to make an Array Palindrome557
119Rotate string to get lexicographically minimum string555
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 Solution528
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 palindrome514
133Partition Problem513
134Remove duplicates from a string512
135Smallest Palindrome after Replacement512
136Longest Palindrome can be Formed by Removing or Rearranging Characters510
137Maximum Sum Increasing Subsequence509
138Generate all Binary Strings from Given Pattern498
139Check whether Strings are K Distance Apart or Not497
140Insert Node in the Sorted Linked List496
141Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized495
142Delete Last Occurrence494
143Length of Longest valid Substring493
1443Sum Leetcode Solution491
145Check if Two given Strings are Isomorphic to each other489
146Maximum difference between two elements such as larger element comes after smaller484
147Program to Toggle all Characters in a String480
148Given string is interleaving of two other strings or not478
149Count Minimum Steps to Get the given Array477
150Merge sort better than quick sort for linked lists473
151Number of Smaller Elements on Right Side471
152Find Pair with Given Difference469
153Check if all Rows of a Matrix are Circular Rotations of Each Other468
154Check length of a String is Equal to the Number Appended at its Last467
155Longest Common Prefix using Divide and Conquer466
156Find nth node of the Linked list from the end465
157Sort 0s 1s and 2s in an Array456
158Find a Fixed Point in a Given Array455
159Print all interleavings of given two strings454
160Merge two sorted linked lists such that merged list is in reverse order452
161Find the Subarray of given length with Least Average451
162Compare Two Version Numbers450
163Reorder Array Using Given Indexes449
164Split linked list using alternate nodes448
165Reverse words in a given string448
166Print Reverse of a string (Recursion)445
167Median of Two Sorted Arrays LeetCode Solution443
168Print string of odd length in ‘X’ format433
169Swap Kth Node from beginning with Kth Node from End430
170Find Element Using Binary Search in Sorted Array429
171Find K Length Subarray of Maximum Average429
172Print all Palindromic Partitions of a String426
173Find Duplicates in an Array in Most Efficient Way422
174print all palindromic partitions418
175Flatten a multilevel linked list414
176Shortest Superstring Problem413
177Maximum Length of Chain Pairs412
178Sorting a K Sorted Array407
179Check if String Follows Order of Characters by a Pattern or not407
180Sort a String According to Another String400
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 digits387
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)379
189Rearrange a linked list in Zig-Zag376
190Kth Non-repeating Character375
191Caesar Cipher374
192Check if String can Become Empty by Recursively Deleting given Substring373
193Pancake Sorting371
194Rotate Image by 90 degrees369
195Longest Common Prefix Word by Word Matching367
196Perfect Reversible String363
197Permutations of a Given String Using STL362
198Merging Two Sorted Arrays360
199Increasing Subsequence of Length three with Maximum Product360
200Find the point where a monotonically increasing function becomes positive first time358
201Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes357
202Sort a linked list with 0s, 1s and 2s357
2031`s and 2`s complement of binary number355
204Find First non-repeating character in a string354
205Four Elements that Sum to Given351
206Delete N nodes after M350
207List items containing all characters of a given word350
208Longest Common Prefix using Character by Character Matching347
209Count Number of Occurrences in a Sorted Array343
210Split a string338
211Minimum Characters to be Removed to Make a Binary String Alternate337
212Palindrome string (number)337
213Check if a Linked list of Strings form a Palindrome331
214Recursive Implementation of atoi()328
215Print All Distinct Elements of the Array328
216Sorting the array of strings328
217Convert a String that is Repetition of a Substring of Length K327
218Even Substring Count323
219Find the first Repeating Number in a Given Array323
220Binary Tree to Doubly linked list321
221Reverse a singly linked list recursively321
222Maximum occurring character in a string320
223Print Shortest Path to Print a String on Screen319
224Can we reverse a linked list in less than O(n) time ?318
225Valid Parentheses LeetCode Solution317
226Nth Character in Concatenated Decimal String316
227Reverse a String using Stack315
228Convert string1 to string2 in one edit315
229Sort Elements by Frequency II315
230wildcard character matching313
231Lower Case To Upper Case311
232Merge Two Sorted Arrays309
233Maximum Subarray Leetcode Solution308
234Count the number of words308
235Find the Lost Element From a Duplicated Array308
236Split Four Distinct Strings307
237Find middle of the Linked List303
238Longest Common Subsequence with Permutations298
239Count the Pairs at Same Distance as in English Alphabets297
240Next Greater Element in an Array293
241Matrix Chain Multiplication using Dynamic Programming291
242Palindrome Permutation286
243Find Nth Node282
244Find All Pairs With a Given Difference281
245Searching a node in a Binary Search Tree281
246Triplet from three linked lists with given sum279
247Roman to Integer Leetcode Solution279
248Delete a Tree278
249String(represents an integer) to value275
250Print all Possible Ways to Break a String in Bracket Form274
251Reverse a String274
252Binary Tree271
253Delete a node under given conditions270
254Change Gender of a given String270
255Reverse Bits269
256Sort an array of strings268
257Word Search Leetcode Solution267
258Number of sub-strings which recursively add up to 9265
259How to Efficiently Implement k Stacks in a Single Array?264
260Remove middle points in a linked list of line segments264
261Longest Common Extension263
262Toeplitz Matrix261
263Remove spaces from a string260
264Count Pairs With Given Sum259
265First non Repeating Element259
266Meeting Rooms II LeetCode Solution258
267Repeated Substring Pattern257
268Shuffle a given Array257
269Longest Palindromic Substring LeetCode Solution256
270Move all negative elements to one side of array255
271N queen problem252
272Min Stack251
273Find, second, frequent, character249
274Dijkstra Algorithm248
275Cuckoo sequence program246
276Number of Islands LeetCode Solution245
277Most Frequent Element in an Array244
278Clone a linked list with next and random pointer (Hashing)244
279Sort linked which is sorted on absolute values243
280Max stack243
281Minimize the maximum difference between the heights243
282House Robber Leetcode Solution241
283Fibonacci numbers238
284Search Insert Position Leetcode Solution238
285Expression Evaluation237
286How to Delete a Linked List237
287Valid Palindrome Leetcode Solution236
288Word Search234
289KMP Algorithm234
290Plus One Leetcode Solution234
291Sudoku Solver234
292Min Stack Leetcode Solution233
293Evaluation of Postfix Expression233
294Reverse words in a string232
295Combination Sum Leetcode Solution231
296Subset Leetcode231
297Number Of 1 bits231
298Backspace String Compare225
299Merge Sorted Arrays Leetcode Solution224
300Pair of Positive Negative Values in an Array223
301Rabin Karp Algorithm223
302Reversing a Queue222
303Set Matrix Zeroes222
304Tower Of Hanoi221
305Sqrt(x) Leetcode Solution221
306Subarray with 0 sum220
307Contains Duplicate II Leetcode Solution220
308Combination Sum219
309Common elements in all rows of a given matrix218
310Product of array except self217
311Intersection of Two Arrays II Leetcode Solution216
312Integer to Roman Leetcode Solution216
313Pascal Triangle Leetcode215
314Reverse individual words214
315String Compression213
316Delete middle element of a stack213
317Construct Binary Tree from Given Inorder and Preorder Traversals213
318Minimum swaps required to bring all elements less than or equal to k together212
319Sliding Window Technique211
320Count subarrays with equal number of 1’s and 0’s211
321Find Top K (or Most Frequent) Numbers in a Stream211
322Add Binary Leetcode Solution210
323Bellman Ford Algorithm210
324Pow(x, n) Leetcode Solution210
325Page Replacement Algorithms in Operating Systems209
326Arithmetic Expression Evaluation209
327Next Permutation208
328Count of index pairs with equal elements in an array208
329Single Number Leetcode Solution208
330Segregate even and odd numbers208
331Design a stack that supports getMin() in O(1) time and O(1) extra space207
332Second Most Repeated Word in a Sequence207
333Implementation of Deque using Doubly Linked List207
334Palindrome Linked List Leetcode Solution207
335Kruskal Algorithm207
336Minimum Value to Get Positive Step by Step Sum Leetcode Solution207
337Count Odd Numbers in an Interval Range Leetcode Solution206
338Contains Duplicate206
339Find sum of non-repeating elements (distinct) elements in an array206
340Postfix to Infix Conversion206
341Maximum Number of Balloons Leetcode Solution206
342Sort elements by frequency205
343Longest Common Prefix Leetcode Solution204
344Maximum Subarray203
345Group Words With Same Set of Characters203
346Third Maximum Number Leetcode Solution203
347Permutations Leetcode Solution203
348K-th Smallest Element in a Sorted Matrix202
349Find Lucky Integer in an Array Leetcode Solution202
350Convex Hull Algorithm202
351Longest Substring Without Repeating Characters LeetCode Solution201
352Top K Frequent Words201
353Find Numbers with Even Number of Digits Leetcode Solution201
354Sorting array using Stacks201
355Sum of minimum and maximum elements of all subarrays of size k200
356Minimum operation to make all elements equal in array200
357Scramble String200
358Find the Town Judge Leetcode Solution199
359Smallest Subarray with k Distinct Numbers199
360Count subarrays having total distinct elements same as original array199
361Swap Nodes in Pairs Leetcode Solutions198
362Evaluate Division198
363Spiral Matrix LeetCode Solution197
364Special Number197
365Majority Element Leetcode Solution197
366Merge Two Sorted Lists Leetcode Solutions196
367First element occurring k times in an array196
368Check if two arrays are equal or not195
369Pascal’s Triangle II Leetcode Solution195
370Given two unsorted arrays find all pairs whose sum is x195
371Reversing the First K elements of a Queue194
372Count Primes Leetcode Solutions194
373Minimum Path Sum194
374Group Anagrams194
375Prefix to Infix Conversion194
376Reverse a Number Using Stack193
377Best Time to Buy and Sell Stock  II Leetcode Solution193
378Huffman Coding193
379Search in Rotated Sorted Array Leetcode Solution193
380Missing Number Leetcode Solution192
381Power of Two Leetcode Solution192
382Minimum Absolute Difference Leetcode Solution192
383Find duplicates in a given array when elements are not limited to a range192
384Minimum Steps to reach target by a Knight192
385Number of Good Pairs Leetcode Solution192
386Sort Array by Increasing Frequency Leetcode Solution191
387House Robber II Leetcode Solution191
388Maximum Distance Between two Occurrences of Same Element in Array191
389Maximal Square191
390Maximum possible difference of two subsets of an array191
391Single Number191
392Range Sum Query 2D – Immutable Leetcode Solution190
393Fizz Buzz Leetcode190
394Sorting using trivial hash function189
395Top K Frequent Elements189
396Running Sum of 1d Array Leetcode Solution189
397Matrix Diagonal Sum Leetcode Solution189
398Unique Paths Leetcode Solution189
399Leetcode Permutations188
400Find All Numbers Disappeared in an Array Leetcode Solution188
401Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution188
402Palindrome Substring Queries188
403Subset sum problem187
404Unique Paths187
405Expression Contains Redundant Bracket or Not187
406Fibonacci Number LeetCode Solution187
407How to Implement Stack Using Priority Queue or Heap?187
408Coin Change 2 Leetcode Solution187
409Subarray Sum Equals K LeetCode Solution187
410Check if Array Contains Contiguous Integers With Duplicates Allowed187
411Happy Number Leetcode Solution187
412Zigzag Conversion187
413Max Consecutive Ones Leetcode Solution186
414Reverse Vowels of a String Leetcode Solution186
415Decode String186
416Find The Duplicate Number186
417Find Winner on a Tic Tac Toe Game Leetcode Solution186
418Difference between highest and least frequencies in an array186
419Monotonic Array LeetCode Solution185
420Smallest Element Repeated Exactly K Times185
421Convert String To Int185
422Subtract the Product and Sum of Digits of an Integer Leetcode Solution185
423Find the Closest Palindrome number185
424Nth Catalan Number185
425Cumulative Frequency of Count of Each Element in an Unsorted Array185
426How Many Numbers Are Smaller Than the Current Number Leetcode Solution185
427Letter Case Permutation185
428Sort a stack using recursion184
429Remove Duplicates from Sorted Array Leetcode Solution184
430Shuffle the Array Leetcode Solution184
431Find Number of Employees Under every Employee184
432Subarray Sum Equals k184
433Reverse Integer184
434Sort Integers by The Number of 1 Bit Leetcode Solution184
435Print All Distinct Elements of a Given Integer Array184
436Best Time to Buy and Sell Stock III Leetcode Solution184
437Find top three repeated in array184
438Bipartite Graph183
439Length of the largest subarray with contiguous elements183
440Trapping Rain Water Leetcode Solution183
441Find Median from data Stream183
442Check If N and Its Double Exist Leetcode Solution183
443Capacity To Ship Packages Within D Days Leetcode Solution182
444Find the first repeating element in an array of integers182
445LRU Cache Implementation182
446Implement Stack and Queue using Deque182
447Reverse a Stack Using Recursion181
448Find Minimum In Rotated Sorted Array181
449Generate a String With Characters That Have Odd Counts Leetcode Solution181
450Priority Queue Using Singly Linked List181
451Subarrays with distinct elements181
452Sum of Subarray Ranges Leetcode Solution181
453Maximum Depth of Binary Tree Leetcode Solution181
454Reverse Words in a String III LeetCode Solution181
455Find the Duplicate Element181
456Prim’s Algorithm181
457Integer to English words180
458Minimum Moves to Equal Array Elements Leetcode Solution180
459Find all pairs (a, b) in an array such that a % b = k180
460Merge Two Sorted Linked Lists180
461Count Substrings with equal number of 0s, 1s and 2s180
462Kth largest element in an Array Leetcode Solutions180
463Delete a Node from linked list without head pointer180
464Longest Common Subsequence179
465Count pairs from two linked lists whose sum is equal to a given value179
466The K Weakest Rows in a Matrix Leetcode Solution179
467Find elements which are present in first array and not in second179
468Sorting a Queue without Extra Space179
469Find Common Characters Leetcode Solution179
470Count and Say178
471Find the Difference Leetcode Solution178
472Reverse a linked list178
473MiniMax Algorithm178
474Reverse a String178
475Edit Distance178
476Fizz Buzz178
477Remove Minimum Number of Elements Such That no Common Element Exist in both Array178
478Degree of an array177
479Target Sum177
480Print all subarrays with 0 sum177
481Text Justification LeetCode Solution177
482Next Greater Element I Leetcode Solution177
483Floyd Warshall Algorithm177
484Concatenation of Array LeetCode Solution177
485Excel Sheet Column Number Leetcode Solution177
486Longest Common Prefix using Trie176
487Kids With the Greatest Number of Candies Leetcode Solution176
488Find First and Last Position of Element in Sorted Array Leetcode Solution176
489Balanced Binary Tree Leetcode Solution176
490Kth Largest Element in a Stream Leetcode Solution176
491Number of Steps to Reduce a Number to Zero Leetcode Solution175
492Longest subarray not having more than K distinct elements175
493Design Parking System Leetcode Solution175
494Merge Overlapping Intervals175
495Pair with given product175
496Multiply Strings Leetcode Solution175
497Iterative Tower of Hanoi175
498Flood Fill LeetCode175
499Word Ladder LeetCode Solution174
500Top View of Binary Tree174
501Shortest Palindrome174
502Priority Queue in C++174
503Valid Parenthesis String173
504Prefix to Postfix Conversion173
505Postfix to Prefix Conversion173
506Find subarray with given sum (Handles Negative Numbers)173
507Implement Stack using Queues173
508Find four elements that sum to a given value (Hashmap)173
509Find N Unique Integers Sum up to Zero Leetcode Solution173
510Max Area of Island173
511Length of Last Word Leetcode Solution173
512Count and Say Leetcode Solution173
513Peak Index in a Mountain Array173
515Mobile Numeric Keypad Problem172
516Koko Eating Bananas Leetcode Solution172
517Move Zeroes LeetCode Solution172
518Slowest Key Leetcode Solution172
519Find missing elements of a range172
520The Stock Span Problem172
521Iterative Inorder Traversal of a Binary Tree172
522Contiguous Array Leetcode172
523Intersection of Two Arrays172
524Find distinct elements common to all rows of a matrix172
525Convert array into Zig-Zag fashion172
526Implement a stack using single queue171
527Count number of triplets with product equal to given number171
528Shuffle String Leetcode Solution171
529Find Index of Closing Bracket for a Given Opening Bracket in an Expression171
530Zigzag Conversion LeetCode Solution171
531Substring With Concatenation Of All Words171
532Check if a given array contains duplicate elements within k distance from each other171
533Find any one of the multiple repeating elements in read only array170
534K-th Distinct Element in an Array170
535Jump Game Leetcode Solution170
536Longest Common Prefix using Sorting170
537Last Stone Weight170
538Container with Most Water170
539Smallest Subarray With all Occurrences of a Most Frequent Element170
540Convert a normal BST to Balanced BST170
541Next Greater Frequency Element169
542Minimum Bracket Reversals169
543Valid Sudoku169
544Relative Sort Array Leetcode Solution169
545Delete Node in a Linked List Leetcode Solution169
546Best Time to Buy and Sell Stock169
547Largest Perimeter Triangle Leetcode Solution169
548Assign Cookies Leetcode Solution168
549Build Array From Permutation Leetcode Solution168
550Excel Sheet Column Title Leetcode Solution168
551First negative integer in every window of size k168
552Sum of Left Leaves Leetcode Solutions167
553Implementation of Deque using circular array167
554Arrange given numbers to form the biggest number167
555Shuffle an Array167
556Minimum Operations to convert X to Y167
557Distribute Candies to People Leetcode Solution167
558Find Words That Can Be Formed by Characters Leetcode Solution167
559Rearrange a binary string as alternate x and y occurrences167
560Group Multiple Occurrence of Array Elements Ordered by first Occurrence167
561Isomorphic Strings Leetcode Solution167
562Check for Balanced Parentheses in an Expression167
563Is Subsequence Leetcode Solution167
564The Knapsack Problem166
565N-th Tribonacci Number Leetcode Solution166
566Maximum sum rectangle in a 2D matrix166
567Valid Anagrams166
56801 Matrix LeetCode Solution166
569Jewels and Stones Leetcode Solution166
570Integer to Roman166
571Linked List Cycle II LeetCode Solution166
572Change the Array into Permutation of Numbers From 1 to N166
573Shortest Path in a Grid with Obstacles Elimination LeetCode Solution165
574How to check if two given sets are disjoint?165
575Hamming Distance165
576Minimum Delete Operations to make all Elements of Array Same165
577Island Perimeter Leetcode Solution165
578Unique Binary Search Trees165
579Convert Sorted Array to Binary Search Tree Leetcode Solution165
580Gold Mine Problem164
581Count the number of nodes at given level in a tree using BFS164
582Decode Ways164
583Maximum path sum in a triangle164
584Find the smallest positive integer value that cannot be represented as sum of any subset of a given array164
585Rotate List Leetcode Solution164
586Remove Linked List Elements Leetcode Solution164
587Trapping Rain Water LeetCode Solution164
588Sieve of Eratosthenes163
589Combinations Leetcode Solution163
590Maximum difference between first and last indexes of an element in array163
591Maximum Distance in Array163
592LRU Cache LeetCode Solution163
593Summary Ranges Leetcode Solution163
594Same Tree LeetCode Solution163
5953Sum Closest LeetCode Solution162
596Applications of Breadth First Search and Depth First Search162
597Minimum Knight Moves LeetCode Solution162
598Minimum number of subsets with distinct elements162
599Insert Interval Leetcode Solution162
600Count all subsequences having product less than K162
601Rotate Image LeetCode Solution162
602Find minimum difference between any two elements162
603Distance Between Bus Stops Leetcode Solution162
604Find Sum of all unique sub-array sum for a given array162
605K Empty Slots LeetCode161
606Minimum number of distinct elements after removing m items161
607Best Time to Buy and Sell Stock LeetCode Solution161
608Maximum Number of Chocolates to be Distributed Equally Among k Students161
609Find if an Expression has Duplicate Parenthesis or Not161
610Minimum insertions to form a palindrome with permutations allowed161
611Printing brackets in Matrix Chain Multiplication Problem161
612Frog Jump Leetcode Solution161
613Word Pattern161
614Permutation in String Leetcode Solution160
615Sort Array By Parity LeetCode Solution160
616License Key Formatting Leetcode Solution160
617Stone Game LeetCode160
618Distance of nearest cell having 1 in a binary matrix160
619Word Wrap Problem160
620Find the Duplicate Number LeetCode Solution159
621Minimum Depth of Binary Tree Leetcode Solution159
622Minimum Cost to Hire K Workers159
623House Robber159
624XOR Operation in an Array Leetcode Solution159
625Longest Increasing Subsequence159
626Defanging an IP Address Leetcode Solution159
627Sort Characters By Frequency LeetCode Solution159
628Replace Elements with Greatest Element on Right Side Leetcode Solution159
629Smallest Good Base158
630Coin Change Problem158
631Check If It Is a Straight Line Leetcode Solution158
632Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest158
633Painting Fence Algorithm158
634Maximum Consecutive Numbers Present in an Array158
635Segregate 0s and 1s in an Array158
636Kth Missing Positive Number Leetcode Solution158
637Reverse a stack without using extra space in O(n)158
638Remove All Occurrences of a Substring LeetCode Solution158
639Reorganize String157
640Find Maximum Level sum in Binary Tree157
641Non-overlapping sum of two sets157
642Longest Substring with At Most K Distinct Characters LeetCode Solution157
643Tracking current Maximum Element in a Stack156
644Isomorphic Strings156
645Optimal Account Balancing LeetCode Solution156
646Iterative Method to find Height of Binary Tree156
647Valid Palindrome II Leetcode Solution156
648Wiggle Sort156
649Strobogrammatic Number LeetCode Solution156
650Best Time to Buy and Sell Stock with Cooldown Leetcode Solution156
651GCD Of Two Numbers156
652Employee Free Time LeetCode Solution156
653Merge Two Balanced Binary Search Trees156
654Queries for counts of array elements with values in given range156
655Partition Labels LeetCode Solution155
656Convert an array to reduced form155
657Binary Tree Zigzag Level Order Traversal LeetCode Solution155
658BFS vs DFS for Binary Tree155
659K Empty Slots155
660How to Create Mergable Stack?155
661Flipping an Image LeetCode Solution155
662Find Largest d in Array such that a + b + c = d155
663Moving Average from Data Stream Leetcode Solution155
664Power of Four Leetcode Solution155
665Number of Provinces Leetcode Solution155
666Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions155
667Largest Sum Contiguous Subarray154
668Check if a queue can be sorted into another queue using a stack154
669Delete consecutive same words in a sequence154
670Form minimum number from given sequence154
671Maximum Number of Coins You Can Get Leetcode Solution154
672Find the Distance Value Between Two Arrays Leetcode Solution154
673Count Good Nodes in Binary Tree Leetcode Solution154
674Ugly Number Leetcode Solution154
675Longest Substring with At Least K Repeating Characters LeetCode Solution154
676Inorder Successor of a node in Binary Tree154
677Path With Maximum Minimum Value LeetCode Solution154
678Check If Two String Arrays are Equivalent Leetcode Solution154
679Letter Combinations of a Phone Number154
680Maximum Number of Occurrences of a Substring Leetcode Solution154
681Find the Smallest Divisor given a Threshold Leetcode Solution153
682Lucky Numbers in a Matrix Leetcode Solution153
683Reservoir Sampling153
684Populating Next Right Pointers in Each Node153
685Sum of All Odd Length Subarrays Leetcode Solution153
686Valid Palindrome153
687Sort Array by Increasing Frequency Leetcode Solution153
688Sum of f(a[i], a[j]) over all pairs in an array of n integers153
689Subset Sum Leetcode153
690To Lower Case Leetcode Solution153
691Find pairs with given sum such that elements of pair are in different rows152
692Majority Element II Leetcode Solution152
693Factorial Trailing Zeroes Leetcode Solution152
694Increasing Decreasing String Leetcode Solution152
695Print the Fibonacci numbers in reverse order152
696Partition Array Into Three Parts With Equal Sum Leetcode Solution152
697Delete Nth node from the end of the given linked list152
698Find the node with minimum value in a Binary Search Tree152
699Reducing Dishes LeetCode Solution152
700Reverse Only Letters LeetCode Solution152
701Reversing a Queue using Recursion152
702Maximum Product of Three Numbers LeetCode Solution152
703Remove Invalid Parentheses Leetcode Solution152
704Unique Paths II Leetcode Solution152
705Add and Search Word – Data structure design LeetCode152
706Number of Dice Rolls With Target Sum LeetCode Solution152
707Construct BST from given Preorder Traversal152
708Permutation Sequence LeetCode Solution151
709Valid Perfect Square Leetcode Solution151
710Numbers with prime frequencies greater than or equal to k151
711Longest Increasing Path in a Matrix LeetCode Solution151
712Find Leaves of Binary Tree LeetCode Solution151
713Recover Binary Search Tree151
714Convert a Number to Hexadecimal Leetcode Solution151
715Edit Distance LeetCode Solution151
716String to Integer (atoi) LeetCode Solution151
717Dynamic Programming Basics150
718Restore IP Addresses Leetcode Solution150
719Find whether an array is subset of another array150
720Maximum Product of Two Elements in an Array Leetcode Solution150
721Binary Tree zigzag level order Traversal150
722Rank Transform of an Array Leetcode Solution149
723Merge Two Binary Trees LeetCode Solution149
724Bubble sort using two Stacks149
725Find Maximum Depth of Nested Parenthesis in a String149
726Largest subarray with equal number of 0s and 1s149
727Deletion in a Binary Tree149
728Longest Span with same Sum in two Binary arrays149
729Maximum 69 Number Leetcode Solution149
730Find unique character in a string149
731Hamming Distance Leetcode Solution149
732Keyboard Row Leetcode Solution149
733Binomial Coefficient149
734Decompress Run-Length Encoded List Leetcode Solution149
735Minimum Distance Between BST Nodes Leetcode Solution149
736Elements to be added so that all elements of a range are present in array148
737Bulb Switcher LeetCode Solution148
738Perform String Shifts Leetcode148
739Find the largest multiple of 3148
740Growable array based stack148
741Find Pair with Greatest Product in Array148
742Minimum Cost For Tickets Leetcode Solution148
743Finding K closest element148
744Merge K Sorted Linked Lists148
745Best Meeting Point LeetCode Solution148
746Minimum Height Trees148
747Sorted Linked List to Balanced BST148
748Stack Permutations (Check if an array is stack permutation of other)148
749Race Car LeetCode Solution147
750Count quadruples from four sorted arrays whose sum is equal to a given value x147
751Invert Binary Tree LeetCode Solution147
752Find All Duplicates in an Array LeetCode Solution147
753Kth ancestor of a node in binary tree147
754Morris Traversal147
755Robot Room Cleaner Leetcode Solution147
756k-th missing element in increasing sequence which is not present in a given sequence147
757Symmetric Tree Leetcode Solution147
758Non-decreasing Array LeetCode Solution147
759Jump Game147
760Binary Tree Maximum Path Sum LeetCode Solution147
761Student Attendance Record I Leetcode Solution147
762Largest rectangular sub-matrix whose sum is 0146
763Evaluate Reverse Polish Notation LeetCode Solution146
764Maximum Depth of N-ary Tree Leetcode Solution146
765Generate all possible sorted arrays from alternate elements of two given sorted arrays146
766Valid Number146
767Word Pattern LeetCode Solution146
768Diagonal Traversal of Binary Tree146
769Maximum Length of a Concatenated String with Unique Characters Leetcode Solution146
770Minimum time required to rot all oranges146
771Remove brackets from an algebraic string containing + and – operators146
772Snakes and Ladders LeetCode Solution146
773Special Array With X Elements Greater Than or Equal X Leetcode Solution145
774Minimize Maximum Pair Sum in Array LeetCode Solution145
775Find if Path Exists in Graph Leetcode Solution145
776Find Median from Data Stream LeetCode Solution145
777Largest Rectangle in Histogram LeetCode Solution145
778N-Queens LeetCode Solution145
779Number of NGEs to the Right145
780Search in a Binary Search Tree Leetcode Solution145
781String Compression LeetCode Solution145
782Partition to K Equal Sum Subsets Leetcode Solution145
783Interval Tree145
784Program for Bridge and Torch problem145
785Number of Islands II LeetCode Solution145
786Queue based approach for first non-repeating character in a stream145
787Tiling Problem145
788Linked List Cycle145
789First Unique Character in a String LeetCode Solution145
790Check for Palindrome after every character replacement Query144
791Sort an array according to the order defined by another array144
792Minimum swaps to make sequences increasing144
793Count items common to both the lists but with different prices144
794Maximum Difference Between Increasing Elements LeetCode Solution144
795Base 7 Leetcode Solution144
796Final Prices With a Special Discount in a Shop Leetcode Solution144
797Split a String in Balanced Strings Leetcode Solution144
798Circular Queue144
799Transpose Graph144
800Check if Two Expressions With Brackets are Same144
801Nested List Weight Sum II LeetCode Solution144
802Check If Array Pairs Are Divisible by k LeetCode Solution144
803Search a 2D Matrix II Leetcode Solution144
804Crawler Log Folder Leetcode Solution143
805Remove Duplicates from Sorted List II143
806Priority Queue using doubly linked list143
807Print a Binary Tree in Vertical Order143
808Remove Duplicates from Sorted List LeetCode Solution143
809Clone Graph LeetCode Solution143
810Total Numbers With no Repeated Digits in a Range143
811Iterative Preorder Traversal143
812Course Schedule II – LeetCode143
813Relative Ranks Leetcode Solution143
814Reorder Data in Log Files LeetCode Solution143
815Remove Nth Node From End of List Leetcode Solution143
816Permutation Coefficient143
817A Space Optimized DP solution for 0-1 Knapsack Problem143
818Number Complement Leetcode Solution143
819Get Maximum in Generated Array Leetcode Solution143
820String comparison containing wildcards143
821One Edit Distance LeetCode Solution142
822Convert BST to Min Heap142
823Last Stone Weight II LeetCode Solution142
824Longest Subarray Having Count of 1s One More than Count of 0s142
825Sort Array By Parity II Leetcode Solution142
826Nearest Exit from Entrance in Maze LeetCode Solution142
827Top K Frequent Words LeetCode Solution142
828Minimum Time Visiting All Points Leetcode Solution142
829Merge Sorted Array LeetCode Solution142
830Minimum number of jumps to reach end142
831Sort Colors141
832Maximum size subarray sum equals k141
833Design a Stack With Increment Operation Leetcode Solution141
834Brick Wall LeetCode Solution141
835Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution141
836Maximum Nesting Depth of the Parentheses Leetcode Solution141
837Alien Dictionary LeetCode Solution141
838Minimum Jumps to Reach Home LeetCode Solution141
839Friends Pairing Problem141
840Minimum Swaps to Make Strings Equal Leetcode Solution141
841Regular Expression Matching141
842Matrix Chain Multiplication141
843Find the subarray with least average141
844Path with maximum average value141
845Partition List Leetcode Solution141
846Check if a given array can represent Preorder Traversal of Binary Search Tree140
847Find All Possible Recipes from Given Supplies LeetCode Solution140
848Brightest Position on Street LeetCode Solution140
849Can Place Flowers LeetCode Solution140
850Sorted Array to Balanced BST140
851Form Minimum Number From Given Sequence140
852Minimum Number of Taps to Open to Water a Garden LeetCode Solution140
853Spiral Matrix II Leetcode Solution140
854Find all triplets with zero sum140
855Sum of nearest smaller and greater number140
856Binary Search Tree Search and Insertion140
857Subset with sum divisible by m140
858Check whether a given Binary Tree is Complete or not140
859Find the Only Repetitive Element Between 1 to N-1140
860Valid Parentheses Leetcode Solution140
861Count ways to reach the nth stair using step 1, 2 or 3140
862Check if an Array is Stack Sortable140
863Subarray Product Less Than K LeetCode Solution140
864Subsequence of Size K With the Largest Even Sum LeetCode Solution139
865Range sum queries without updates139
866Level order Traversal in Spiral Form139
867Count Distinct Elements in Every Window of Size K139
868Given an Array of Pairs Find all Symmetric Pairs in it139
869Tree Traversal (Preorder, Inorder & Postorder)139
870Insert into a Binary Search Tree Leetcode Solution139
871Maximum Profit in Job Scheduling Leetcode Solution139
872LCS (Longest Common Subsequence) of three strings139
873Find Maximum Sum Possible Equal Sum of Three Stacks138
874Union and Intersection of two Linked Lists138
875Identify and Mark Unmatched Parenthesis in an Expression138
876Minimum Sum Path in a Triangle138
877Count Negative Numbers in a Sorted Matrix LeetCode Solution138
878Destination City Leetcode Solution138
879Insert Delete GetRandom138
880Guess Number Higher or Lower LeetCode Solution138
881Sequences of given length where every element is more than or equal to twice of previous138
882Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution138
883Maximum Score After Splitting a String Leetcode Solution138
884An Interesting Method to generate Binary Numbers from 1 to n137
885Count Subarrays with Same Even and Odd Elements137
886GCDs of given index ranges in an array137
887Guess Number Higher or Lower II137
888Delete And Earn137
889Lemonade Change Leetcode Solution137
890BFS for Disconnected Graph137
891Rearrange an Array Such that arr[i] is equal to i137
892A program to check if a binary tree is BST or not137
893Water Bottles Leetcode Solution137
894Find distance between two nodes of a Binary Tree137
895Missing Element in Sorted Array LeetCode Solution137
896Set Matrix Zeroes Leetcode Solution137
897Alien Dictionary137
898Distinct adjacent elements in an array137
899Repeated Substring Pattern LeetCode Solution137
900Shortest Word Distance Leetcode Solution137
901Check if stack elements are pairwise consecutive137
902Minimum sum of multiplications of n numbers137
903Balanced Expression with Replacement137
904Range LCM Queries136
905Three way partitioning of an array around a given range136
906Find Common Characters Leetcode Solution136
907Diagonal Traverse LeetCode Solution136
908Find all permuted rows of a given row in a matrix136
909Design Browser History LeetCode Solution136
910Spiral Matrix III LeetCode Solution136
911Number of Days Between Two Dates LeetCode Solution136
912Least Number of Unique Integers after K Removals Leetcode Solution136
913Rearrange Spaces Between Words Leetcode Solution136
914Merge Two Sorted Lists Leetcode136
915Convert Sorted List to Binary Search Tree136
916Diagonal Traversal LeetCode Solution136
918Check if the given array can represent Level Order Traversal of Binary Search Tree136
919Maximum Subarray Sum Excluding Certain Elements135
920Construct the Rectangle Leetcode Solution135
921Palindrome Partitioning Leetcode Solution135
922Special Positions in a Binary Matrix Leetcode Solution135
923Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i135
924Number of Equivalent Domino Pairs Leetcode Solution135
925Longest Palindromic Subsequence135
926Queue using Stacks135
927Averages of Levels in Binary Tree135
928Robot Bounded In Circle LeetCode Solution135
929Vertical sum in a given binary tree135
930K’th Largest Element in BST when modification to BST is not allowed135
931Construct Complete Binary Tree from its Linked List Representation135
932Infix to Postfix134
933Print Fibonacci sequence using 2 variables134
9343 Sum134
935Largest area rectangular sub-matrix with equal number of 1’s and 0’s134
936Median of Two Sorted Arrays134
937Stone Game II Leetcode134
938Trim a Binary Search Tree134
939Lexicographical Numbers Leetcode Solution134
940Queries for GCD of all numbers of an array except elements in a given range134
941Daily Temperatures Leetcode Solution134
942Dividing Array into Pairs With Sum Divisible by K134
943Can Make Arithmetic Progression From Sequence Leetcode Solution133
944Remove Duplicates from Sorted List II LeetCode Solution133
945Merging Intervals133
946Pattern Occurrences using Stack133
947Construct BST from its given Level Order Traversal133
948Strongly Connected Component133
949Maximum Frequency Stack Leetcode Solution133
950Three Consecutive Odds Leetcode Solution133
951Analyze User Website Visit Pattern LeetCode Solution133
952Number of Distinct Islands Leetcode Solution133
953Binary array after M range toggle operations133
954Maximize Sum of Array after K Negations Leetcode Solution133
955Check if any two intervals overlap among a given set of intervals133
956Largest Substring Between Two Equal Characters Leetcode Solution133
957Time Based Key-Value Store LeetCode Solution133
958Palindrome Partitioning132
959Symmetric Tree132
960Create Maximum Number132
961Shuffle 2n integers as without using extra space132
962Word Break132
963Newman-Conway Sequence132
964Count Submatrices With All Ones LeetCode Solution132
965Segment Tree132
966All Unique Triplets that Sum up to a Given Value132
967Depth First Search (DFS) for a Graph132
968Binary Tree Longest Consecutive Sequence LeetCode Solution132
969Iterative Postorder Traversal Using Two Stacks132
970Split Array Into Consecutive Subsequences132
971Sliding Window Maximum132
972Minimum Height Trees LeetCode Solution131
973Difference Array | Range update query in O(1)131
974Binary Search Tree Delete Operation131
975Count Primes in Ranges131
976Climbing stairs131
977Length of Longest Fibonacci Subsequence131
978Intersection of Two Linked Lists LeetCode Solution131
979Breadth First Search (BFS) for a Graph131
980My Calendar I LeetCode Solution131
981Maximum subsequence sum such that no three are consecutive130
982Find postorder traversal of BST from preorder traversal130
983Sign of the Product of an Array LeetCode Solution130
984Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution130
985Find Maximum of Minimum for Every Window Size in a Given Array130
986Find the Difference Leetcode Solution130
987Count pair with Given Sum130
988Maximum Product Subarray130
989Reverse Nodes in K-Group130
990Insertion in a Binary Tree129
991Count subarrays where second highest lie before highest129
992Level Order Traversal of Binary Tree129
993The Painter’s Partition Problem129
994Height of a generic tree from parent array129
995Find the First Circular Tour that visits all the Petrol Pumps129
996Boundary Traversal of binary tree129
997Asteroid Collision LeetCode Solution129
998Serialize and Deserialize Binary Tree129
999Largest divisible pairs subset129
1000Minesweeper LeetCode Solution129
1001Compute nCr % p129
1002Kth Smallest Element in a BST Leetcode Solution129
1003Valid Boomerang Leetcode Solution129
1004Unique Paths II128
1005Longest Nice Substring LeetCode Solution128
1006Product of Array Except Self LeetCode Solution128
1007Collect maximum points in a grid using two traversals128
1008Friends Of Appropriate Ages LeetCode Solution128
1009Rearrange array such that even positioned are greater than odd128
1010Number Of Longest Increasing Subsequence128
1011First missing positive128
1012Find Duplicate Subtrees128
1013The Maze III LeetCode Solution128
1014Maximum Length of Repeated Subarray128
1015Decrypt String from Alphabet to Integer Mapping Leetcode Solution128
1016Level order traversal using two Queues128
1017Find number of pairs in an array such that their XOR is 0128
1018Scramble String LeetCode Solution128
1019Binary Search Tree127
1020Balanced Binary Tree127
1021Graph Valid Tree LeetCode Solution127
1022Construction of Longest Increasing Subsequence (N log N)127
1023Next Greater Element III LeetCode Solution127
1024Boolean Parenthesization Problem127
1025Partition Equal Subset Sum127
1026Maximum Number of Ways to Partition an Array LeetCode Solution127
1027String Matching in an Array Leetcode Solution127
1028Shortest Completing Word Leetcode Solution127
1029Advantages of BST over Hash Table127
1030Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1031Ugly Numbers127
1032Make The String Great Leetcode Solution127
1033Construct Binary Tree from given Parent Array representation127
1034Build an Array With Stack Operations Leetcode Solution127
1035Longest subsequence such that difference between adjacents is one126
1036Design Hit Counter LeetCode Solution126
1037Morris Inorder Traversal126
1038Find whether a subarray is in form of a mountain or not126
1039Maximum weight transformation of a given string126
1040Invalid Transactions LeetCode Solution126
1041Kill Process LeetCode Solution126
1042Kth Smallest Element in a Sorted Matrix LeetCode Solution126
1043Implement Trie (Prefix Tree) Leetcode Solution126
1044Largest Number Leetcode Solution126
1045Double the first element and move zero to end126
1046Number of palindromic paths in a matrix126
1047Minimum Size Subarray Sum126
1048Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’126
1049Lowest Common Ancestor125
1050Minimum Index Sum of Two Lists125
1051Maximum Product of Indexes of Next Greater on Left and Right125
1052Maximum Sum of 3 Non-Overlapping Subarrays125
1053Validate Binary Search Tree125
1054K Closest Points to Origin Leetcode Solution125
1055Custom Sort String Leetcode Solution125
1056Path Sum II LeetCode Solution125
1057Iterative Depth First Traversal of Graph125
1058Find Peak Element124
1059Bitwise AND of Numbers Range LeetCode Solution124
1060Defanging an IP Address LeetCode Solution124
1061Employee Importance LeetCode Solution124
1062Recover Binary Search Tree Leetcode Solution124
1063Ugly Number II LeetCode Solution124
1064Move all negative elements to end in order with extra space allowed124
1065Regular Expression Matching Regular Expression Matching LeetCode Solution124
1066Find a Peak Element II LeetCode Solution124
1067Add two numbers124
1068Available Captures for Rook Leetcode Solution124
1069Remove Duplicates from Sorted Array II Leetcode Solution123
1070Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution123
1071Largest BST Subtree LeetCode Solution123
1072Maximum difference between frequency of two elements such that element having greater frequency is also greater123
1073Count minimum steps to get the given desired array123
1074Day of the Year Leetcode Solution123
1075Rearrange array such that even index elements are smaller and odd index elements are greater123
1076Super Ugly Number123
1077Types of Binary Tree123
1078Binary Tree Right Side View LeetCode Solution123
1079Divisible Pairs Counting123
1080Binary Tree Data Structure123
1081Number of Students Doing Homework at a Given Time Leetcode Solution122
1082Path Sum122
1083Print Next Greater Number of Q queries122
1084Number of Closed Islands Leetcode Solution122
1085Search in Sorted Rotated Array122
1086Populating Next Right Pointers in Each Node Leetcode Solution122
1087Subarrays with K Different Integers Leetcode Solution122
1088Find Smallest Range Containing Elements from k Lists122
1089Find the minimum distance between two numbers122
1090Smallest Common Region Leetcode Solution122
1091Number of siblings of a given Node in n-ary Tree122
1092Generate Parentheses Leetcode Solution122
1093Count pairs from two sorted arrays whose sum is equal to a given value x122
1094Print all triplets in sorted array that form AP122
1095Remove Palindromic Subsequences Leetcode Solution121
1096Root to Leaf path with target sum Leetcode Solutions121
1097Serialize and Deserialize Binary Tree LeetCode Solution121
1098Clone a Binary Tree with Random Pointers121
1099Remove duplicates from sorted array121
1100Constant time range add operation on an array121
1101Longest Bitonic Subsequence121
1102Kth Smallest Product of Two Sorted Arrays LeetCode Solution121
1103Combination Sum IV LeetCode Solution121
1104Level of Each node in a Tree from source node120
1105Search Insert Position120
1106Valid Tic-Tac-Toe State LeetCode Solution120
1107Maximize Distance to Closest Person LeetCode Solution120
1108Write Code to Determine if Two Trees are Identical120
1109Bottom View of a Binary Tree120
1110Palindrome Permutation LeetCode Solution120
1111Minimum sum of squares of character counts in a given string after removing k characters120
1112Find maximum difference between nearest left and right smaller elements120
1113Distinct Subsequences120
1114Third Maximum Number Leetcode Solution120
1115Convert BST into a Min-Heap without using array120
1116Print Right View of a Binary Tree120
1117Find Three Element From Different Three Arrays Such That a + b + c = sum119
1118Print modified array after executing the commands of addition and subtraction119
1119Prime Palindrome LeetCode Solution119
1120Next Permutation Leetcode Solution119
1121Cutting a Rod119
1122Increasing Triplet Subsequence LeetCode Solution119
1123Minimum Score Triangulation of Polygon Leetcode Solution119
1124Thousand Separator Leetcode Solution119
1125Count Largest Group Leetcode Solution119
1126Maximum Product Subarray118
1127Consecutive Characters LeetCode Solution118
1128Maximum Binary Tree118
1129Moser-de Bruijn Sequence118
1130Mean of Array After Removing Some Elements Leetcode Solution118
1131Cells with Odd Values in a Matrix LeetCode Solution118
1132Golomb sequence118
1133Topological Sorting118
1134Reformat The String Leetcode Solution118
1135Products of ranges in an array118
1136Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution118
1137Iterative method to find ancestors of a given binary tree118
1138Construct K Palindrome Strings LeetCode Solution117
1139Red-Black Tree Introduction117
1140Search an Element in Sorted Rotated Array117
1141Minimum Absolute Difference in BST Leetcode Solution117
1142Transform a BST to Greater sum Tree117
1143Sum of Even Numbers After Queries117
1144Longest Increasing Consecutive Subsequence117
1145Longest Subarray of 1’s After Deleting One Element LeetCode Solution117
1146Count even length binary sequences with same sum of first and second half bits116
1147Maximum Product of Splitted Binary Tree LeetCode Solution116
1148Swap Nodes In Pairs116
1149Find maximum length Snake sequence116
1150Palindromic Substrings Leetcode Solution116
1151Rotate Array116
1152Check Array Formation Through Concatenation Leetcode Solution116
1153Kth Smallest Number in Multiplication Table Leetcode Solution116
1154Factorial Trailing Zeroes LeetCode Solution116
1155Binary Tree to Binary Search Tree Conversion116
1156Queries for Number of Distinct Elements in a Subarray116
1157Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution116
1158K maximum sums of overlapping contiguous sub-arrays116
1159Delete Nodes and Return Forest Leetcode Solution115
1160K’th Largest element in BST using constant extra space115
1161Decision Tree115
1162Merge two BSTs with limited extra space115
1163Maximize sum of consecutive differences in a circular array115
1164Priority Queue115
1165Possible Bipartition LeetCode Solution115
1166Compare Strings by Frequency of the Smallest Character Leetcode Solution115
1167Subset Sum Problem in O(sum) space115
1168Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1169Find the smallest binary digit multiple of given number114
1170Minimum Moves to Equal Array Elements LeetCode Solution114
1171Closest Binary Search Tree Value Leetcode Solution114
1172Minimum Sideway Jumps LeetCode Solution114
1173Search Suggestions System LeetCode Solution114
1174Count Pairs Whose Products Exist in Array113
1175First Bad Version113
1176Find a sorted subsequence of size 3 in linear time113
1177Minimum Cost to Move Chips to The Same Position LeetCode Solution113
1178Given a binary tree, how do you remove all the half nodes?113
1179Number of Orders in the Backlog Leetcode Solution113
1180Diameter of N-Ary Tree LeetCode Solution113
1181Bus Routes Leetcode Solution113
1182Decrease Elements To Make Array Zigzag LeetCode Solution112
1183Lowest Common Ancestor in Binary Search Tree112
1184Reverse a Path in BST using Queue112
1185Maximum number of segments of lengths a, b and c112
1186Longest Repeated Subsequence112
1187Web Crawler LeetCode Solution112
1188Queue Reconstruction by Height112
1189Contiguous Array LeetCode Solution112
1190Swapping Nodes in a Linked List Leetcode Solution111
1191Moving Stones Until Consecutive Leetcode Solution111
1192Find Largest Value in Each Tree Row LeetCode Solution111
1193Convert Sorted Array to Binary Search Tree LeetCode Solutions111
1194Champagne Tower LeetCode Solution111
1195Closest Leaf in a Binary Tree LeetCode Solution111
1196Matchsticks to Square Leetcode Solution111
1197How to print maximum number of A’s using given four keys110
1198Sum of Left Leaves LeetCode Solution110
1199Maximum sum of pairs with specific difference110
1200New 21 Game110
1201Valid Perfect Square LeetCode Solution110
1202Valid Triangle Number110
1203Maximum sum bitonic subarray110
1204Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution110
1205Reformat Date LeetCode Solution110
1206Graph and its representation110
1207Write a function to get the intersection point of two Linked Lists109
1208Print modified array after multiple array range increment operations109
1209Replace two consecutive equal values with one greater109
1210Range Sum Query using Sparse Table109
1211Maximum Depth Of Binary Tree109
1212Path Crossing Leetcode Solution109
1213Kth Smallest Element in a BST109
1214Array Queries for multiply replacements and product109
1215The kth Factor of n Leetcode Solution109
1216Integer Break LeetCode Solution109
1217Concatenation of Array LeetCode Solution108
1218Range Queries for Longest Correct Bracket Subsequence108
1219Check if each internal node of a BST has exactly one child108
1220Maximum Value at a Given Index in a Bounded Array LeetCode Solution108
1221Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1222Guess The Word108
1223BST to a Tree with Sum of all Smaller Keys108
1224Lowest Common Ancestor of a Binary Tree Leetcode Solution108
1225Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution108
1226Maximum sum of a path in a Right Number Triangle108
1227Merge Sort108
1228Arithmetic Slices II – Subsequence LeetCode Solution108
1229Design Skiplist LeetCode Solution108
1230Divide Two Integers Leetcode Solution107
1231Check for Identical BSTs without building the trees107
1232Count Subsets Having Distinct Even Numbers107
1233Check if all levels of two Binary Tree are anagrams or not107
1234Queries on Probability of Even or Odd Number in given Ranges107
1235Flatten 2D Vector LeetCode Solution107
1236Graph Cloning106
1237Sliding Window Median Leetcode Solution106
1238Power of Two106
1239Perfect Squares LeetCode Solution106
1240Longest Common Prefix Using Word by Word Matching106
1241Check Completeness of a Binary Tree LeetCode Solution106
1242Mean of range in array105
1243Print n terms of Newman-Conway Sequence105
1244Symmetric Tree LeetCode Solution Leetcode Solution105
1245Bold Words in String LeetCode Solution105
1246Largest Plus Sign Leetcode Solution105
1247Find minimum number of merge operations to make an array palindrome105
1248Contiguous Array105
1249Maximum Array from Two given Arrays Keeping Order Same105
1250Find Minimum in Rotated Sorted Array II LeetCode Solution105
1251Maximize Elements Using Another Array105
1252Missing Number104
1253Verify Preorder Serialization of a Binary Tree104
1254LRU Cache Leetcode Solution104
1255Find k-th smallest element in BST (Order Statistics in BST)104
1256Print Ancestors of a Given Binary Tree Node Without Recursion103
1257Next greater element103
1258Check If a String Can Break Another String Leetcode Solution103
1259Parallel Courses II LeetCode Solution103
1260Minimum Remove to Make Valid Parentheses LeetCode Solution102
1261Maximum Product Subarray102
1262Merge k Sorted Lists Leetcode Solution102
1263Excel Sheet Column Title LeetCode Solution102
1264Image Overlap LeetCode Solution102
1265Smallest Range II Leetcode Solution102
1266Count and Toggle Queries on a Binary Array101
1267Minimum Time to Collect All Apples in a Tree LeetCode Solution101
1268Koko Eating Bananas LeetCode Solution100
1269Orderly Queue LeetCode Solution100
1270Palindrome Partitioning100
1271Check if two nodes are on the same path in a Tree100
1272Check in binary array the number represented by a subarray is odd or even100
1273Check if X can give change to every person in the Queue98
1274Merge Sorted Array98
1275Min Cost Climbing Stairs LeetCode Solution98
1276Newman–Shanks–Williams prime98
1277Number of elements less than or equal to a given number in a given subarray97
1278Different Ways to Add Parentheses Leetcode Solution97
1279Peeking Iterator LeetCode Solution97
1280Largest Submatrix With Rearrangements LeetCode Solution97
1281Maximum Sum Increasing Subsequence96
1282Number of indexes with equal elements in given range95
1283Range Minimum Query (Square Root Decomposition and Sparse Table)95
1284Find maximum average subarray of k length95
1285Queries for Decimal Values of Subarrays of a Binary Array94
1286Longest Substring Without Repeating Characters Leetcode Solution93
1287Maximum product of an increasing subsequence93
1288Array Nesting Leetcode Solution93
1289Binary Tree to Binary Search Tree Conversion using STL set92
1290Check given array of size n can represent BST of n levels or not92
1291Arranging Coins Leetcode Solution92
1292Encoded String With Shortest Length LeetCode Solution91
1293Minimum Number of People to Teach LeetCode Solution91
1294Convert a BST to a Binary Tree such that sum of all greater keys is added to every key90
1295Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1296Reach a Number LeetCode Solution90
1297Minimum Total Space Wasted With K Resizing Operations LeetCode Solution90
1298Random Pick Index LeetCode Solution90
1299Queries on XOR of greatest odd divisor of the range89
1300Convert to Base -2 LeetCode Solution89
1301Jump Game IV LeetCode Solution88
1302Find the Winner of the Circular Game LeetCode Solution88
1303Insert Delete GetRandom O(1) Leetcode Solution86
1304Add Two Numbers II Leetcode Solution86
1305Vertical Order Traversal of Binary Tree LeetCode Solution85
1306Palindrome Number LeetCode Solution85
1307Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution84
1308Design Underground System Leetcode Solution83
1309Print Maximum Length Chain of Pairs83
1310Continuous Subarray Sum LeetCode Solution81
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
1315Minimum Path Sum Leetcode Solution72
1316Top K Frequent Elements LeetCode Solution71
1317Maximum Population Year LeetCode Solution70
1318Binary Tree Inorder Traversal LeetCode Solution70
1319Odd Even Linked List Leetcode Solution70
1320Count Sub Islands LeetCode Solution69
1321Find the Town Judge LeetCode Solution68
1322Shifting Letters LeetCode Solution68
1323Shortest Unsorted Continuous Subarray LeetCode Solution68
1324Best Meeting Point LeetCode Solution68
1325Decode String Leetcode Solution68
1326Longest Common Subsequence LeetCode Solution67
1327Sum Root to Leaf Numbers LeetCode Solution67
1328Design Add and Search Words Data Structure LeetCode Solution65
1329Find the Town Judge LeetCode Solution65
1330Rectangle Overlap LeetCode Solution62
1331Maximum Population Year LeetCode Solution62
1332Flatten Binary Tree to Linked List LeetCode Solution59
1333Score of Parenthesis LeetCode Solution59
1334Insert into a Sorted Circular Linked List LeetCode Solution59
1335Stone Game IV LeetCode Solution59
1336Range Sum Query 2D – Immutable LeetCode Solution58
1337Is Graph Bipartite? LeetCode Solution57
1338Valid Triangle Number 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 Solution35
1344Reverse Integer Leetcode Solution35
1345Find K Closest Elements LeetCode Solution32
1346Excel Sheet Column Number LeetCode Solution29
1347Rotate String LeetCode Solution29
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution27
Translate »