Score of Parenthesis LeetCode Solution

Difficulty Level Medium
Frequently asked in Adobe Amazon Apple Bloomberg ByteDance Facebook Google Infosys VMware
Stack String tiktokViews 60

Problem Statement

The score of Parenthesis LeetCode Solution says –

Given a balanced parentheses string s and return the maximum score.

The score of a balanced parenthesis string is based on the following rules:

  • "()" has score 1.
  • AB has score A + B, where A and B are balanced parenthesis strings.
  • (A) has score 2 * A, where A is a balanced parenthesis string.


Example 1:


 s = "()"



Example 2:


 s = "(())"



Example 3:


 s = "()()"




Constraints – 

  • s is a balanced parenthesis string.
  • s only contains “(” and “)”.


Algorithm –


– In order to find the Score of Balanced Parenthesis. What we will do in this question. At first, we will focus on the balanced parenthesis if they are balanced then the count will be 1.

  • if the balanced parenthesis is inside the balanced parenthesis then our answer will be 2*balanced parenthesis. so first we will create one stack and one answer variable = 0.
  • after that will iterate through the whole string if i == “(” then we will push the answer into the stack and update the answer as 0.
  •  if i == “)” then we will check for the answer variable if it is zero then we will update answer = 1 else will update the answer as 2* answer and add the last element of the stack into the answer.


Approach –

– Create one stack and one variable and set it as 0.

– Iterate through the string and check for the condition if i == “(“. Then append variable into stack and update variable = 0.

–  if i = “)” then will check for two condition if variable != 0 then update variable as variable = 2*variable else variable = 1 and at last add the popped element in variable.

  • Hence we will calculate the Score Of Parenthesis.

Score of Parenthesis LeetCode SolutionPin



class Solution {
    public int scoreOfParentheses(String s) {
        int ans = 0;
        Stack<Integer> stack = new Stack<>();
        for(char i:s.toCharArray()){
            if(i == '('){
                ans = 0;
            else if(i == ')'){
                if(ans != 0)
                   ans = 2*ans;
                    ans = 1;
                ans += stack.pop();
        return ans;
class Solution:
    def scoreOfParentheses(self, s: str) -> int:
        stack = []
        ans = 0
        for i in s:
            if i == "(":
                ans = 0
            elif i == ")":
                if ans:
                    ans = 2*ans
                    ans = 1
                ans += stack.pop()
        return ans

Complexity Analysis of The Score of Parentheses Leetcode Solution:

Time complexity:

The Time Complexity of the above solution is O(N) as we have traversed the whole string only once.

Space complexity:

The Space Complexity of the above solution is O(N) as we have created one stack.


Some more questions related to stack –









Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2815
2Java program to find the number of Nodes in a Binary Tree2499
3Reverse a string without affecting special characters2456
4Delete a node of a linked list at given position1973
5Palindrome using Recursion1777
6Insert nodes in a linked list in a sorted way (Ascending Order)1659
7Find elements pair from array whose sum equal to number1644
8Sort Elements by Frequency of Occurrences1628
9Write a program to print all permutations of a given string1601
10Find Minimum Distance Between Two Numbers in an Array1470
11Create a Doubly Linked List1443
12Quick Sort1415
13Reverse an Array1412
14Smallest window in a string containing all characters of another string1394
15Find a Triplet That Sum to a Given Value1355
16Recursively remove all adjacent duplicates1351
17First Repeating Element1335
18Arrange Even and Odd number such that Odd comes after Even1319
19Sum of numbers in String1313
20Smallest Positive Number Missing in an Unsorted Array1278
21Check if the Elements of an Array are Consecutive1252
22Detect a loop in the Linked List1234
23Largest Sum Contiguous Subarray1228
24Quick Sort on SIngly Linked List1213
25Subarray with Given Sum1211
26Print all Possible Combinations of R Elements in a given Array of size N1202
27Recursive function to do substring search1196
28Find the Maximum Repeating Number in Array1153
29Binary Tree Level order traversal in Java1122
30Find the First and Second Smallest Elements1118
31Check if two linked lists are identical1100
32Maximum Subarray Sum using Divide and Conquer1098
33Remove characters from first string which are in second1066
34Find Leaders in an Array1058
35Swap nodes in the linked list1034
36Find the Number Occurring Odd Number of Times in an Array999
37Arrange given Numbers to Form the Biggest Number II993
38Find the second most frequent character984
39Given a string find its first non-repeating character965
40Find Triplet in Array With a Given Sum964
41Given a sorted array and a number x, find the pair in array whose sum is closest to x950
42Total number of occurrences of a given item in the linked list950
43A Program to check if strings are rotations of each other or not943
44Print all possible words from phone digits929
45Find the Missing Number923
46Rearrange Positive and Negative Numbers Alternatively in Array916
47Longest Palindromic Substring904
48Segregate even and odd nodes in a linked list881
49Print Longest common subsequence878
50Union and Intersection of Two Linked Lists870
51Transform one string to another using minimum number of given operations866
52Check rearranged string can form a palindrome842
53Rearrange given Array in Maximum Minimum Form842
54Count Possible Triangles819
55Iterative Implementation of Quick Sort813
56Multiplication of Two Matrices798
57Check if the linked list is palindrome794
58Count of Triplets With Sum Less than Given Value788
59Rotate a Linked List788
60Stock Buy Sell to Maximize Profit786
61Tug of War758
62Concatenation of two strings757
63Count Number of Substrings with K Distinct Character’s752
64Print all duplicates in the input string751
65Find Nearest Greater and Smaller Element744
66Find Pythagorean Triplets from Array736
67The Celebrity Problem735
68Reverse String Without Temporary Variable732
69Remove ‘b’ and ‘ac’ from a given string727
70Find all Common Elements in Given Three Sorted Arrays727
71Remove all duplicates in an unsorted linked list708
72Find the Row with Maximum Number of 1’s702
73Find the Peak Element from an Array696
74Find the subarray whose sum is equal to a given number X694
75Remove Minimum Characters so that Two Strings Become Anagrams686
76Insertion Sort685
77Find Smallest Missing Number in a Sorted Array684
78Addition of Two Matrices682
79A Product Array Puzzle682
80Implement Two Stacks in an Array675
81Generate all Binary Strings Without Consecutive 1’s671
82Maximum Sum of Non Consecutive Elements667
83Maximum Product Subarray II658
84Lexicographic rank of string652
85Multiplication of Previous and Next643
86Check if Two given Matrices are Identical641
87Merge K Sorted Arrays and Print Sorted Output631
88Subtraction of Two Matrices631
89Move All the Zeros to the End of the Given Array626
90Divide a string in N equal parts621
91Online Algorithm for Checking Palindrome in a Stream621
92Form Minimum Number from Given Sequence of D’s and I’s621
93Check whether two strings are anagram of each other613
94Maximum Circular Subarray Sum610
95Remove recurring digits in a given number608
96Sort a linked list that is sorted alternating ascending and descending607
97Sort a stack using a temporary stack605
98Find the Minimum Element in a Sorted and Rotated Array603
99Move last element of the Linked List at first place601
100Subarray and Subsequence599
101First Circular Tour to Visit all the Petrol Bunks596
102Largest Subarray with Equal Number of 0’s and 1’s596
103Compare two strings(linked lists)591
104Flattening a linked list590
105Maximum Element in an Array which is Increasing and then Decreasing588
106Palindrome Permutations of a String582
107Elements Appear more than N/K times in Array580
108Majority Element574
109Print all permutations with repetition572
110Minimum insertions to form a shortest palindrome572
111Run length encoding572
112Palindromes in a given range570
113Pangram Checking567
114Minimum Characters to be Added at Front to Make String Palindrome563
115Merge a linked list into another at alternate positions563
116Rearrange a given linked list in-place562
117Remove all duplicates in a sorted linked list562
118Minimum number of Merge Operations to make an Array Palindrome557
119Most repeating character in a string557
120Rotate string to get lexicographically minimum string557
121Repeated Subsequence of Length Two or More554
122Print all anagrams together in a sequence of words550
123Reorder an Array According to the Given Indexes549
124Pancake Sorting Problem540
125Clone a Linked List with next and random pointer536
126Merge Overlapping Intervals II536
127Two Sum Leetcode Solution534
128Size of The Subarray With Maximum Sum527
129Transpose of a Matrix522
130Removing Spaces from a String using stringstream519
131Remove Extra Spaces from a String519
132Smallest Palindrome after Replacement517
133Check if a given string is a rotation of a palindrome516
134Partition Problem515
135Remove duplicates from a string514
136Longest Palindrome can be Formed by Removing or Rearranging Characters513
137Maximum Sum Increasing Subsequence512
138Check whether Strings are K Distance Apart or Not502
139Generate all Binary Strings from Given Pattern501
140Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized499
141Length of Longest valid Substring498
142Insert Node in the Sorted Linked List498
1433Sum Leetcode Solution497
144Delete Last Occurrence495
145Check if Two given Strings are Isomorphic to each other492
146Maximum difference between two elements such as larger element comes after smaller486
147Program to Toggle all Characters in a String482
148Given string is interleaving of two other strings or not481
149Count Minimum Steps to Get the given Array478
150Merge sort better than quick sort for linked lists475
151Number of Smaller Elements on Right Side475
152Find Pair with Given Difference472
153Check length of a String is Equal to the Number Appended at its Last469
154Check if all Rows of a Matrix are Circular Rotations of Each Other469
155Longest Common Prefix using Divide and Conquer467
156Find nth node of the Linked list from the end466
157Find a Fixed Point in a Given Array460
158Sort 0s 1s and 2s in an Array457
159Print all interleavings of given two strings455
160Compare Two Version Numbers454
161Merge two sorted linked lists such that merged list is in reverse order453
162Find the Subarray of given length with Least Average452
163Reorder Array Using Given Indexes450
164Reverse words in a given string449
165Split linked list using alternate nodes449
166Print Reverse of a string (Recursion)447
167Median of Two Sorted Arrays LeetCode Solution446
168Print string of odd length in ‘X’ format435
169Find K Length Subarray of Maximum Average434
170Find Element Using Binary Search in Sorted Array431
171Swap Kth Node from beginning with Kth Node from End430
172Print all Palindromic Partitions of a String427
173Find Duplicates in an Array in Most Efficient Way425
174print all palindromic partitions420
175Maximum Length of Chain Pairs415
176Flatten a multilevel linked list415
177Shortest Superstring Problem414
178Check if String Follows Order of Characters by a Pattern or not411
179Sorting a K Sorted Array408
180Sort a String According to Another String402
181Longest Span with same Sum in two Binary Arrays II397
182Reverse a Linked List in groups395
183Find a Sorted Subsequence of size 3392
184Program to add two binary digits390
185Recursively print all the sentences that can be formed from list of word lists387
186Find the two Numbers with Odd Occurrences in an Unsorted Array386
187Longest Common Prefix Using Binary Search II384
188Reverse a Singly Linked List (Iterative/Non-Recursive)381
189Rearrange a linked list in Zig-Zag377
190Check if String can Become Empty by Recursively Deleting given Substring377
191Kth Non-repeating Character377
192Caesar Cipher376
193Pancake Sorting373
194Rotate Image by 90 degrees370
195Longest Common Prefix Word by Word Matching369
196Perfect Reversible String365
197Permutations of a Given String Using STL364
198Increasing Subsequence of Length three with Maximum Product361
199Merging Two Sorted Arrays361
200Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes360
201Find the point where a monotonically increasing function becomes positive first time358
202Sort a linked list with 0s, 1s and 2s357
203Find First non-repeating character in a string356
2041`s and 2`s complement of binary number356
205Four Elements that Sum to Given353
206List items containing all characters of a given word351
207Delete N nodes after M351
208Longest Common Prefix using Character by Character Matching348
209Count Number of Occurrences in a Sorted Array344
210Palindrome string (number)341
211Split a string340
212Minimum Characters to be Removed to Make a Binary String Alternate339
213Check if a Linked list of Strings form a Palindrome332
214Recursive Implementation of atoi()331
215Sorting the array of strings330
216Print All Distinct Elements of the Array330
217Convert a String that is Repetition of a Substring of Length K329
218Even Substring Count325
219Find the first Repeating Number in a Given Array325
220Maximum occurring character in a string325
221Valid Parentheses LeetCode Solution324
222Reverse a singly linked list recursively323
223Can we reverse a linked list in less than O(n) time ?322
224Binary Tree to Doubly linked list322
225Print Shortest Path to Print a String on Screen321
226Nth Character in Concatenated Decimal String318
227Convert string1 to string2 in one edit318
228Sort Elements by Frequency II316
229Reverse a String using Stack316
230wildcard character matching314
231Lower Case To Upper Case314
232Maximum Subarray Leetcode Solution313
233Count the number of words310
234Merge Two Sorted Arrays310
235Find the Lost Element From a Duplicated Array310
236Split Four Distinct Strings308
237Find middle of the Linked List305
238Longest Common Subsequence with Permutations302
239Count the Pairs at Same Distance as in English Alphabets300
240Matrix Chain Multiplication using Dynamic Programming294
241Next Greater Element in an Array294
242Palindrome Permutation287
243Find Nth Node283
244Searching a node in a Binary Search Tree283
245Find All Pairs With a Given Difference281
246Triplet from three linked lists with given sum280
247Delete a Tree279
248Roman to Integer Leetcode Solution279
249Reverse a String276
250String(represents an integer) to value276
251Print all Possible Ways to Break a String in Bracket Form276
252Binary Tree272
253Delete a node under given conditions272
254Reverse Bits272
255Change Gender of a given String271
256Word Search Leetcode Solution269
257Sort an array of strings269
258Number of sub-strings which recursively add up to 9266
259Count Pairs With Given Sum265
260Remove middle points in a linked list of line segments265
261Longest Common Extension265
262How to Efficiently Implement k Stacks in a Single Array?265
263First non Repeating Element263
264Meeting Rooms II LeetCode Solution263
265Toeplitz Matrix262
266Longest Palindromic Substring LeetCode Solution262
267Remove spaces from a string262
268Repeated Substring Pattern261
269Move all negative elements to one side of array259
270Shuffle a given Array258
271Min Stack255
272N queen problem254
273Find, second, frequent, character251
274Number of Islands LeetCode Solution249
275House Robber Leetcode Solution249
276Dijkstra Algorithm249
277Cuckoo sequence program248
278Clone a linked list with next and random pointer (Hashing)246
279Most Frequent Element in an Array246
280Max stack245
281Minimize the maximum difference between the heights244
282Expression Evaluation244
283Search Insert Position Leetcode Solution243
284Sort linked which is sorted on absolute values243
285Fibonacci numbers240
286Valid Palindrome Leetcode Solution239
287How to Delete a Linked List238
288Subset Leetcode238
289Plus One Leetcode Solution238
290KMP Algorithm237
291Sudoku Solver237
292Min Stack Leetcode Solution236
293Word Search236
294Reverse words in a string235
295Evaluation of Postfix Expression234
296Combination Sum Leetcode Solution233
297Number Of 1 bits232
298Sqrt(x) Leetcode Solution228
299Subarray with 0 sum227
300Pair of Positive Negative Values in an Array227
301Rabin Karp Algorithm227
302Backspace String Compare227
303Merge Sorted Arrays Leetcode Solution227
304Set Matrix Zeroes226
305Reversing a Queue225
306Contains Duplicate II Leetcode Solution224
307Combination Sum224
308Tower Of Hanoi222
309Integer to Roman Leetcode Solution222
310Common elements in all rows of a given matrix221
311Product of array except self220
312Intersection of Two Arrays II Leetcode Solution219
313Delete middle element of a stack219
314Pascal Triangle Leetcode218
315Count subarrays with equal number of 1’s and 0’s217
316Reverse individual words217
317Add Binary Leetcode Solution217
318String Compression216
319Minimum swaps required to bring all elements less than or equal to k together215
320Second Most Repeated Word in a Sequence215
321Single Number Leetcode Solution214
322Construct Binary Tree from Given Inorder and Preorder Traversals214
323Palindrome Linked List Leetcode Solution214
324Find Top K (or Most Frequent) Numbers in a Stream214
325Bellman Ford Algorithm214
326Sliding Window Technique213
327Next Permutation212
328Count of index pairs with equal elements in an array212
329Pow(x, n) Leetcode Solution212
330Arithmetic Expression Evaluation212
331Segregate even and odd numbers211
332Design a stack that supports getMin() in O(1) time and O(1) extra space211
333Implementation of Deque using Doubly Linked List210
334Page Replacement Algorithms in Operating Systems210
335Count Odd Numbers in an Interval Range Leetcode Solution210
336Kruskal Algorithm209
337Contains Duplicate209
338Postfix to Infix Conversion209
339Sort elements by frequency209
340Find sum of non-repeating elements (distinct) elements in an array209
341Maximum Number of Balloons Leetcode Solution208
342Minimum Value to Get Positive Step by Step Sum Leetcode Solution208
343Longest Common Prefix Leetcode Solution207
344K-th Smallest Element in a Sorted Matrix207
345Third Maximum Number Leetcode Solution206
346Maximum Subarray206
347Permutations Leetcode Solution206
348Group Words With Same Set of Characters205
349Convex Hull Algorithm205
350Find Lucky Integer in an Array Leetcode Solution205
351Longest Substring Without Repeating Characters LeetCode Solution204
352Majority Element Leetcode Solution204
353Top K Frequent Words203
354Find Numbers with Even Number of Digits Leetcode Solution203
355Find the Town Judge Leetcode Solution203
356Sum of minimum and maximum elements of all subarrays of size k203
357Count subarrays having total distinct elements same as original array202
358Smallest Subarray with k Distinct Numbers202
359Swap Nodes in Pairs Leetcode Solutions202
360Count Primes Leetcode Solutions202
361Spiral Matrix LeetCode Solution202
362Minimum operation to make all elements equal in array202
363Sorting array using Stacks201
364Scramble String201
365First element occurring k times in an array201
366Evaluate Division200
367Merge Two Sorted Lists Leetcode Solutions199
368Given two unsorted arrays find all pairs whose sum is x199
369Special Number199
370Search in Rotated Sorted Array Leetcode Solution198
371Reverse a Number Using Stack198
372Prefix to Infix Conversion197
373Check if two arrays are equal or not197
374Group Anagrams196
375Minimum Path Sum196
376Maximum possible difference of two subsets of an array196
377Best Time to Buy and Sell Stock  II Leetcode Solution196
378Fizz Buzz Leetcode196
379Pascal’s Triangle II Leetcode Solution196
380Reversing the First K elements of a Queue196
381Maximum Distance Between two Occurrences of Same Element in Array195
382Number of Good Pairs Leetcode Solution195
383Power of Two Leetcode Solution195
384Find duplicates in a given array when elements are not limited to a range195
385Leetcode Permutations195
386Huffman Coding194
387House Robber II Leetcode Solution194
388Missing Number Leetcode Solution194
389Minimum Absolute Difference Leetcode Solution194
390Running Sum of 1d Array Leetcode Solution194
391Minimum Steps to reach target by a Knight193
392Unique Paths Leetcode Solution193
393Top K Frequent Elements193
394Single Number193
395Coin Change 2 Leetcode Solution192
396Range Sum Query 2D – Immutable Leetcode Solution192
397Find All Numbers Disappeared in an Array Leetcode Solution192
398Sort Array by Increasing Frequency Leetcode Solution192
399Maximal Square192
400Find The Duplicate Number191
401Matrix Diagonal Sum Leetcode Solution191
402Sorting using trivial hash function191
403Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution191
404How to Implement Stack Using Priority Queue or Heap?191
405Check if Array Contains Contiguous Integers With Duplicates Allowed191
406Expression Contains Redundant Bracket or Not190
407Smallest Element Repeated Exactly K Times190
408Unique Paths190
409Subarray Sum Equals K LeetCode Solution190
410How Many Numbers Are Smaller Than the Current Number Leetcode Solution190
411Max Consecutive Ones Leetcode Solution190
412Find Number of Employees Under every Employee189
413Fibonacci Number LeetCode Solution189
414Subset sum problem189
415Zigzag Conversion189
416Remove Duplicates from Sorted Array Leetcode Solution188
417Find the Closest Palindrome number188
418Subarray Sum Equals k188
419Cumulative Frequency of Count of Each Element in an Unsorted Array188
420Nth Catalan Number188
421Palindrome Substring Queries188
422Happy Number Leetcode Solution188
423Decode String188
424Find Winner on a Tic Tac Toe Game Leetcode Solution187
425Convert String To Int187
426Subtract the Product and Sum of Digits of an Integer Leetcode Solution187
427Sort Integers by The Number of 1 Bit Leetcode Solution187
428Difference between highest and least frequencies in an array187
429Reverse Integer187
430Reverse Vowels of a String Leetcode Solution187
431Find Median from data Stream187
432Letter Case Permutation187
433Print All Distinct Elements of a Given Integer Array186
434Find top three repeated in array186
435Monotonic Array LeetCode Solution186
436Check If N and Its Double Exist Leetcode Solution186
437Length of the largest subarray with contiguous elements186
438Shuffle the Array Leetcode Solution186
439Sort a stack using recursion185
440Capacity To Ship Packages Within D Days Leetcode Solution185
441Best Time to Buy and Sell Stock III Leetcode Solution185
442Integer to English words185
443Find all pairs (a, b) in an array such that a % b = k185
444Reverse Words in a String III LeetCode Solution185
445Trapping Rain Water Leetcode Solution185
446Subarrays with distinct elements184
447Implement Stack and Queue using Deque184
448LRU Cache Implementation184
449Delete a Node from linked list without head pointer184
450Find the first repeating element in an array of integers184
451Bipartite Graph184
452Count Substrings with equal number of 0s, 1s and 2s184
453Minimum Moves to Equal Array Elements Leetcode Solution183
454Kth largest element in an Array Leetcode Solutions183
455Reverse a Stack Using Recursion183
456Maximum Depth of Binary Tree Leetcode Solution183
457The K Weakest Rows in a Matrix Leetcode Solution183
458Find the Duplicate Element183
459Count pairs from two linked lists whose sum is equal to a given value182
460Priority Queue Using Singly Linked List182
461Find Minimum In Rotated Sorted Array182
462Sorting a Queue without Extra Space182
463Generate a String With Characters That Have Odd Counts Leetcode Solution182
464Longest Common Subsequence182
465Prim’s Algorithm182
466Reverse a String182
467Concatenation of Array LeetCode Solution181
468Sum of Subarray Ranges Leetcode Solution181
469Find elements which are present in first array and not in second181
470Merge Two Sorted Linked Lists181
471Excel Sheet Column Number Leetcode Solution181
472Find Common Characters Leetcode Solution180
473Next Greater Element I Leetcode Solution180
474Longest Common Prefix using Trie180
475Count and Say180
476Remove Minimum Number of Elements Such That no Common Element Exist in both Array180
477Iterative Tower of Hanoi180
478Text Justification LeetCode Solution180
479Find the Difference Leetcode Solution180
480Edit Distance180
481Fizz Buzz180
482Target Sum179
483Print all subarrays with 0 sum179
484Multiply Strings Leetcode Solution179
485Find First and Last Position of Element in Sorted Array Leetcode Solution179
486Kth Largest Element in a Stream Leetcode Solution179
487Flood Fill LeetCode179
488Slowest Key Leetcode Solution178
489Word Ladder LeetCode Solution178
490Reverse a linked list178
491Degree of an array178
492Floyd Warshall Algorithm178
493Number of Steps to Reduce a Number to Zero Leetcode Solution178
494Balanced Binary Tree Leetcode Solution178
495MiniMax Algorithm178
496Kids With the Greatest Number of Candies Leetcode Solution178
497Move Zeroes LeetCode Solution177
498Merge Overlapping Intervals177
499Top View of Binary Tree177
500Priority Queue in C++177
501Count and Say Leetcode Solution176
502Zigzag Conversion LeetCode Solution176
503Peak Index in a Mountain Array176
504Design Parking System Leetcode Solution176
505Pair with given product176
506Longest subarray not having more than K distinct elements176
507Shortest Palindrome176
508Intersection of Two Arrays175
509Convert array into Zig-Zag fashion175
510Find four elements that sum to a given value (Hashmap)175
511Valid Parenthesis String175
512Koko Eating Bananas Leetcode Solution175
513Max Area of Island175
514Prefix to Postfix Conversion175
515Smallest Subarray With all Occurrences of a Most Frequent Element174
516Mobile Numeric Keypad Problem174
517Shuffle String Leetcode Solution174
518Check if a given array contains duplicate elements within k distance from each other174
519Find any one of the multiple repeating elements in read only array174
520Find N Unique Integers Sum up to Zero Leetcode Solution174
521Postfix to Prefix Conversion174
522The Stock Span Problem174
523Find subarray with given sum (Handles Negative Numbers)174
524Substring With Concatenation Of All Words174
525Find missing elements of a range174
526Jump Game Leetcode Solution173
527Find distinct elements common to all rows of a matrix173
528Implement Stack using Queues173
529Implement a stack using single queue173
530Length of Last Word Leetcode Solution173
532Find Index of Closing Bracket for a Given Opening Bracket in an Expression173
533Container with Most Water173
534Count number of triplets with product equal to given number173
535Longest Common Prefix using Sorting172
536K-th Distinct Element in an Array172
537Contiguous Array Leetcode172
538Excel Sheet Column Title Leetcode Solution172
539Iterative Inorder Traversal of a Binary Tree172
540Relative Sort Array Leetcode Solution172
541Next Greater Frequency Element172
542Find Words That Can Be Formed by Characters Leetcode Solution171
543Maximum sum rectangle in a 2D matrix171
544Largest Perimeter Triangle Leetcode Solution171
545Last Stone Weight171
546Build Array From Permutation Leetcode Solution171
547Delete Node in a Linked List Leetcode Solution171
548Best Time to Buy and Sell Stock171
549Minimum Bracket Reversals170
550Valid Sudoku170
551Sum of Left Leaves Leetcode Solutions170
552First negative integer in every window of size k170
553Convert a normal BST to Balanced BST170
554Is Subsequence Leetcode Solution170
555Minimum Operations to convert X to Y170
556Isomorphic Strings Leetcode Solution170
55701 Matrix LeetCode Solution170
558Implementation of Deque using circular array169
559Gold Mine Problem169
560Arrange given numbers to form the biggest number169
561Valid Anagrams169
562Jewels and Stones Leetcode Solution169
563Rearrange a binary string as alternate x and y occurrences169
564Integer to Roman169
565Count all subsequences having product less than K169
566Shuffle an Array169
567Remove Linked List Elements Leetcode Solution168
568Count the number of nodes at given level in a tree using BFS168
569Assign Cookies Leetcode Solution168
570Group Multiple Occurrence of Array Elements Ordered by first Occurrence168
571Distribute Candies to People Leetcode Solution168
572Check for Balanced Parentheses in an Expression168
573Change the Array into Permutation of Numbers From 1 to N168
574The Knapsack Problem168
575Maximum path sum in a triangle167
576Linked List Cycle II LeetCode Solution167
5773Sum Closest LeetCode Solution167
578Shortest Path in a Grid with Obstacles Elimination LeetCode Solution167
579Insert Interval Leetcode Solution167
580Island Perimeter Leetcode Solution167
581Minimum Delete Operations to make all Elements of Array Same167
582Unique Binary Search Trees166
583Hamming Distance166
584Find the smallest positive integer value that cannot be represented as sum of any subset of a given array166
585How to check if two given sets are disjoint?166
586N-th Tribonacci Number Leetcode Solution166
587Sieve of Eratosthenes166
588Convert Sorted Array to Binary Search Tree Leetcode Solution166
589Decode Ways166
590Rotate List Leetcode Solution165
591Maximum difference between first and last indexes of an element in array165
592Same Tree LeetCode Solution165
593K Empty Slots LeetCode165
594Trapping Rain Water LeetCode Solution165
595Minimum Knight Moves LeetCode Solution164
596Maximum Distance in Array164
597Word Pattern164
598Permutation in String Leetcode Solution164
599Minimum number of distinct elements after removing m items164
600Find minimum difference between any two elements164
601Combinations Leetcode Solution164
602LRU Cache LeetCode Solution164
603Summary Ranges Leetcode Solution164
604Minimum number of subsets with distinct elements164
605XOR Operation in an Array Leetcode Solution163
606Distance Between Bus Stops Leetcode Solution163
607Find Sum of all unique sub-array sum for a given array163
608Smallest Good Base163
609Minimum insertions to form a palindrome with permutations allowed163
610Rotate Image LeetCode Solution163
611Sort Array By Parity LeetCode Solution163
612Word Wrap Problem163
613Frog Jump Leetcode Solution163
614Replace Elements with Greatest Element on Right Side Leetcode Solution162
615Printing brackets in Matrix Chain Multiplication Problem162
616Applications of Breadth First Search and Depth First Search162
617Maximum Number of Chocolates to be Distributed Equally Among k Students162
618Find if an Expression has Duplicate Parenthesis or Not162
619Best Time to Buy and Sell Stock LeetCode Solution162
620Painting Fence Algorithm162
621Coin Change Problem162
622Distance of nearest cell having 1 in a binary matrix162
623Minimum Depth of Binary Tree Leetcode Solution162
624Remove All Occurrences of a Substring LeetCode Solution162
625Kth Missing Positive Number Leetcode Solution161
626Stone Game LeetCode161
627Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
628Find the Duplicate Number LeetCode Solution161
629Minimum Cost to Hire K Workers161
630Defanging an IP Address Leetcode Solution160
631License Key Formatting Leetcode Solution160
632Find Maximum Level sum in Binary Tree160
633Sort Characters By Frequency LeetCode Solution160
634Maximum Consecutive Numbers Present in an Array160
635House Robber160
636Optimal Account Balancing LeetCode Solution160
637Longest Increasing Subsequence159
638Iterative Method to find Height of Binary Tree159
639Reverse a stack without using extra space in O(n)159
640Isomorphic Strings159
641Delete consecutive same words in a sequence159
642Sum of All Odd Length Subarrays Leetcode Solution159
643Count Good Nodes in Binary Tree Leetcode Solution159
644Power of Four Leetcode Solution159
645Valid Palindrome II Leetcode Solution159
646Binary Tree Zigzag Level Order Traversal LeetCode Solution159
647Segregate 0s and 1s in an Array159
648Non-overlapping sum of two sets159
649Best Time to Buy and Sell Stock with Cooldown Leetcode Solution158
650Tracking current Maximum Element in a Stack158
651Number of Provinces Leetcode Solution158
652Longest Substring with At Most K Distinct Characters LeetCode Solution158
653Check If It Is a Straight Line Leetcode Solution158
654Queries for counts of array elements with values in given range158
655Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions158
656Merge Two Balanced Binary Search Trees157
657Longest Increasing Path in a Matrix LeetCode Solution157
658GCD Of Two Numbers157
659Convert an array to reduced form157
660Flipping an Image LeetCode Solution157
661Reorganize String157
662Strobogrammatic Number LeetCode Solution157
663K Empty Slots157
664Check If Two String Arrays are Equivalent Leetcode Solution157
665Maximum Number of Coins You Can Get Leetcode Solution157
666Letter Combinations of a Phone Number157
667Find Largest d in Array such that a + b + c = d157
668Employee Free Time LeetCode Solution157
669Sum of f(a[i], a[j]) over all pairs in an array of n integers156
670Find whether an array is subset of another array156
671Partition Labels LeetCode Solution156
672Increasing Decreasing String Leetcode Solution156
673How to Create Mergable Stack?156
674Wiggle Sort156
675Longest Substring with At Least K Repeating Characters LeetCode Solution156
676Moving Average from Data Stream Leetcode Solution156
677Reverse Only Letters LeetCode Solution156
678Reducing Dishes LeetCode Solution156
679String to Integer (atoi) LeetCode Solution156
680Check if a queue can be sorted into another queue using a stack156
681Number of Dice Rolls With Target Sum LeetCode Solution155
682Inorder Successor of a node in Binary Tree155
683Lucky Numbers in a Matrix Leetcode Solution155
684To Lower Case Leetcode Solution155
685Maximum Number of Occurrences of a Substring Leetcode Solution155
686Largest Sum Contiguous Subarray155
687Reservoir Sampling155
688Find the Distance Value Between Two Arrays Leetcode Solution155
689Permutation Sequence LeetCode Solution155
690BFS vs DFS for Binary Tree155
691Path With Maximum Minimum Value LeetCode Solution155
692Form minimum number from given sequence155
693Ugly Number Leetcode Solution155
694Valid Palindrome154
695Reversing a Queue using Recursion154
696Find pairs with given sum such that elements of pair are in different rows154
697Subset Sum Leetcode154
698Populating Next Right Pointers in Each Node154
699Find Leaves of Binary Tree LeetCode Solution154
700Hamming Distance Leetcode Solution154
701Edit Distance LeetCode Solution153
702Construct BST from given Preorder Traversal153
703Find the node with minimum value in a Binary Search Tree153
704Valid Perfect Square Leetcode Solution153
705Sort Array by Increasing Frequency Leetcode Solution153
706Find the Smallest Divisor given a Threshold Leetcode Solution153
707Delete Nth node from the end of the given linked list153
708Maximum Product of Three Numbers LeetCode Solution153
709Majority Element II Leetcode Solution153
710Print the Fibonacci numbers in reverse order153
711Keyboard Row Leetcode Solution153
712Recover Binary Search Tree153
713Unique Paths II Leetcode Solution153
714Partition Array Into Three Parts With Equal Sum Leetcode Solution152
715Remove Invalid Parentheses Leetcode Solution152
716Decompress Run-Length Encoded List Leetcode Solution152
717Rank Transform of an Array Leetcode Solution152
718Dynamic Programming Basics152
719Binary Tree zigzag level order Traversal152
720Numbers with prime frequencies greater than or equal to k152
721Factorial Trailing Zeroes Leetcode Solution152
722Merge Two Binary Trees LeetCode Solution152
723Add and Search Word – Data structure design LeetCode152
724Longest Span with same Sum in two Binary arrays151
725Convert a Number to Hexadecimal Leetcode Solution151
726Largest subarray with equal number of 0s and 1s151
727String Compression LeetCode Solution151
728Stack Permutations (Check if an array is stack permutation of other)151
729Binomial Coefficient150
730Find Maximum Depth of Nested Parenthesis in a String150
731Find Pair with Greatest Product in Array150
732Maximum Product of Two Elements in an Array Leetcode Solution150
733Binary Tree Maximum Path Sum LeetCode Solution150
734Find the largest multiple of 3150
735Bubble sort using two Stacks150
736Queue based approach for first non-repeating character in a stream150
737Find unique character in a string150
738Deletion in a Binary Tree150
739Restore IP Addresses Leetcode Solution150
740Bulb Switcher LeetCode Solution150
741Remove Nth Node From End of List Leetcode Solution150
742Minimum Cost For Tickets Leetcode Solution150
743Non-decreasing Array LeetCode Solution149
744Minimum Height Trees149
745Best Meeting Point LeetCode Solution149
746Search in a Binary Search Tree Leetcode Solution149
747Sorted Linked List to Balanced BST149
748Diagonal Traversal of Binary Tree149
749Student Attendance Record I Leetcode Solution149
750Elements to be added so that all elements of a range are present in array149
751Count quadruples from four sorted arrays whose sum is equal to a given value x149
752Finding K closest element149
753Robot Room Cleaner Leetcode Solution149
754Merge K Sorted Linked Lists149
755Minimum Distance Between BST Nodes Leetcode Solution149
756Maximum 69 Number Leetcode Solution149
757k-th missing element in increasing sequence which is not present in a given sequence149
758Symmetric Tree Leetcode Solution149
759Growable array based stack149
760Race Car LeetCode Solution149
761Number of Islands II LeetCode Solution149
762Word Pattern LeetCode Solution148
763Perform String Shifts Leetcode148
764Snakes and Ladders LeetCode Solution148
765Valid Number148
766Minimize Maximum Pair Sum in Array LeetCode Solution148
767Find if Path Exists in Graph Leetcode Solution148
768Maximum Length of a Concatenated String with Unique Characters Leetcode Solution148
769Kth ancestor of a node in binary tree148
770Morris Traversal148
771Jump Game148
772Remove brackets from an algebraic string containing + and – operators148
773Generate all possible sorted arrays from alternate elements of two given sorted arrays148
774Invert Binary Tree LeetCode Solution148
775N-Queens LeetCode Solution147
776Largest rectangular sub-matrix whose sum is 0147
777Evaluate Reverse Polish Notation LeetCode Solution147
778Minimum time required to rot all oranges147
779Largest Rectangle in Histogram LeetCode Solution147
780Find All Duplicates in an Array LeetCode Solution147
781Number of NGEs to the Right147
782Find Median from Data Stream LeetCode Solution147
783Program for Bridge and Torch problem147
784Nearest Exit from Entrance in Maze LeetCode Solution147
785Maximum Depth of N-ary Tree Leetcode Solution147
786Relative Ranks Leetcode Solution147
787Check for Palindrome after every character replacement Query147
788Sort an array according to the order defined by another array147
789First Unique Character in a String LeetCode Solution147
790Nested List Weight Sum II LeetCode Solution146
791Count items common to both the lists but with different prices146
792Minimum Time Visiting All Points Leetcode Solution146
793String comparison containing wildcards146
794Partition to K Equal Sum Subsets Leetcode Solution146
795Transpose Graph146
796Get Maximum in Generated Array Leetcode Solution146
797Sort Colors146
798Search a 2D Matrix II Leetcode Solution146
799Linked List Cycle146
800Tiling Problem146
801Minimum number of jumps to reach end146
802Merge Sorted Array LeetCode Solution146
803Special Array With X Elements Greater Than or Equal X Leetcode Solution146
804Remove Duplicates from Sorted List LeetCode Solution146
805Path with maximum average value145
806Reorder Data in Log Files LeetCode Solution145
807A Space Optimized DP solution for 0-1 Knapsack Problem145
808Maximum Difference Between Increasing Elements LeetCode Solution145
809Minimum swaps to make sequences increasing145
810Friends Pairing Problem145
811Final Prices With a Special Discount in a Shop Leetcode Solution145
812Number Complement Leetcode Solution145
813Print a Binary Tree in Vertical Order145
814Base 7 Leetcode Solution145
815Alien Dictionary LeetCode Solution145
816Remove Duplicates from Sorted List II145
817Crawler Log Folder Leetcode Solution145
818Interval Tree145
819Check If Array Pairs Are Divisible by k LeetCode Solution145
820Sort Array By Parity II Leetcode Solution145
821Check if Two Expressions With Brackets are Same145
822Split a String in Balanced Strings Leetcode Solution144
823Clone Graph LeetCode Solution144
824Convert BST to Min Heap144
825Total Numbers With no Repeated Digits in a Range144
826Iterative Preorder Traversal144
827Circular Queue144
828One Edit Distance LeetCode Solution144
829Last Stone Weight II LeetCode Solution143
830Regular Expression Matching143
831Top K Frequent Words LeetCode Solution143
832Longest Subarray Having Count of 1s One More than Count of 0s143
833Level order Traversal in Spiral Form143
834Subsequence of Size K With the Largest Even Sum LeetCode Solution143
835Permutation Coefficient143
836Course Schedule II – LeetCode143
837Priority Queue using doubly linked list143
838Design a Stack With Increment Operation Leetcode Solution143
839Subset with sum divisible by m143
840Find all triplets with zero sum143
841Minimum Number of Taps to Open to Water a Garden LeetCode Solution142
842Can Place Flowers LeetCode Solution142
843Minimum Swaps to Make Strings Equal Leetcode Solution142
844Find All Possible Recipes from Given Supplies LeetCode Solution142
845Maximum Nesting Depth of the Parentheses Leetcode Solution142
846Partition List Leetcode Solution142
847Brightest Position on Street LeetCode Solution142
848Valid Parentheses Leetcode Solution142
849Maximum Profit in Job Scheduling Leetcode Solution142
850Find the Only Repetitive Element Between 1 to N-1142
851Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution142
852Subarray Product Less Than K LeetCode Solution142
853Minimum Jumps to Reach Home LeetCode Solution142
854Find the subarray with least average142
855Guess Number Higher or Lower LeetCode Solution142
856Maximum size subarray sum equals k142
857Given an Array of Pairs Find all Symmetric Pairs in it141
858Count ways to reach the nth stair using step 1, 2 or 3141
859Check if a given array can represent Preorder Traversal of Binary Search Tree141
860Binary Search Tree Search and Insertion141
861Check if an Array is Stack Sortable141
862Check whether a given Binary Tree is Complete or not141
863Spiral Matrix II Leetcode Solution141
864Sum of nearest smaller and greater number141
865Sorted Array to Balanced BST141
866Brick Wall LeetCode Solution141
867Form Minimum Number From Given Sequence141
868LCS (Longest Common Subsequence) of three strings141
869Count Distinct Elements in Every Window of Size K141
870Matrix Chain Multiplication141
871GCDs of given index ranges in an array140
872Daily Temperatures Leetcode Solution140
873Insert into a Binary Search Tree Leetcode Solution140
874Tree Traversal (Preorder, Inorder & Postorder)140
875Insert Delete GetRandom140
876Count Subarrays with Same Even and Odd Elements140
877Guess Number Higher or Lower II140
878Distinct adjacent elements in an array139
879Minimum Sum Path in a Triangle139
880Find all permuted rows of a given row in a matrix139
881Rearrange an Array Such that arr[i] is equal to i139
882Union and Intersection of two Linked Lists139
883Missing Element in Sorted Array LeetCode Solution139
884Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution139
885Find Maximum Sum Possible Equal Sum of Three Stacks139
886Destination City Leetcode Solution139
887Water Bottles Leetcode Solution139
888Range sum queries without updates139
889Sequences of given length where every element is more than or equal to twice of previous139
890Shortest Word Distance Leetcode Solution139
891Number of Days Between Two Dates LeetCode Solution139
892Identify and Mark Unmatched Parenthesis in an Expression139
893Find distance between two nodes of a Binary Tree138
895Check if stack elements are pairwise consecutive138
896Robot Bounded In Circle LeetCode Solution138
897Maximum Score After Splitting a String Leetcode Solution138
898Delete And Earn138
899Balanced Expression with Replacement138
900Repeated Substring Pattern LeetCode Solution138
901Three way partitioning of an array around a given range138
902Count Negative Numbers in a Sorted Matrix LeetCode Solution138
903Least Number of Unique Integers after K Removals Leetcode Solution138
904Find Common Characters Leetcode Solution138
905A program to check if a binary tree is BST or not138
906Set Matrix Zeroes Leetcode Solution138
907Rearrange Spaces Between Words Leetcode Solution138
908BFS for Disconnected Graph138
909An Interesting Method to generate Binary Numbers from 1 to n138
910Convert Sorted List to Binary Search Tree138
911Lemonade Change Leetcode Solution138
912Minimum sum of multiplications of n numbers138
913Diagonal Traversal LeetCode Solution138
914Construct Complete Binary Tree from its Linked List Representation138
915Alien Dictionary138
916Check if the given array can represent Level Order Traversal of Binary Search Tree137
917Merge Two Sorted Lists Leetcode137
918Diagonal Traverse LeetCode Solution137
919Spiral Matrix III LeetCode Solution137
920Design Browser History LeetCode Solution137
921Special Positions in a Binary Matrix Leetcode Solution137
922Range LCM Queries137
923Number of Distinct Islands Leetcode Solution136
924Vertical sum in a given binary tree136
925Stone Game II Leetcode136
926K’th Largest Element in BST when modification to BST is not allowed136
927Averages of Levels in Binary Tree136
928Queue using Stacks136
929Maximum Subarray Sum Excluding Certain Elements136
930Infix to Postfix136
931Number of Equivalent Domino Pairs Leetcode Solution136
932Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i136
933Maximum Frequency Stack Leetcode Solution136
934Palindrome Partitioning Leetcode Solution136
935Longest Palindromic Subsequence136
936Largest area rectangular sub-matrix with equal number of 1’s and 0’s135
937Queries for GCD of all numbers of an array except elements in a given range135
938Construct BST from its given Level Order Traversal135
939Lexicographical Numbers Leetcode Solution135
940Trim a Binary Search Tree135
941Three Consecutive Odds Leetcode Solution135
942Print Fibonacci sequence using 2 variables135
943Dividing Array into Pairs With Sum Divisible by K135
944Can Make Arithmetic Progression From Sequence Leetcode Solution135
945Construct the Rectangle Leetcode Solution135
946Time Based Key-Value Store LeetCode Solution134
947Strongly Connected Component134
948Largest divisible pairs subset134
949Median of Two Sorted Arrays134
950Difference Array | Range update query in O(1)134
951Pattern Occurrences using Stack134
952Intersection of Two Linked Lists LeetCode Solution134
953Check if any two intervals overlap among a given set of intervals134
9543 Sum134
955Remove Duplicates from Sorted List II LeetCode Solution134
956Largest Substring Between Two Equal Characters Leetcode Solution134
957All Unique Triplets that Sum up to a Given Value134
958Word Break134
959Analyze User Website Visit Pattern LeetCode Solution134
960Binary array after M range toggle operations134
961Merging Intervals134
962Binary Tree Longest Consecutive Sequence LeetCode Solution134
963Create Maximum Number133
964Split Array Into Consecutive Subsequences133
965Symmetric Tree133
966Iterative Postorder Traversal Using Two Stacks133
967Find Maximum of Minimum for Every Window Size in a Given Array133
968Palindrome Partitioning133
969Depth First Search (DFS) for a Graph133
970Newman-Conway Sequence133
971Sliding Window Maximum133
972Count Submatrices With All Ones LeetCode Solution133
973Maximize Sum of Array after K Negations Leetcode Solution133
974My Calendar I LeetCode Solution132
975Length of Longest Fibonacci Subsequence132
976Breadth First Search (BFS) for a Graph132
977Climbing stairs132
978Reverse Nodes in K-Group132
979Product of Array Except Self LeetCode Solution132
980Sign of the Product of an Array LeetCode Solution132
981Shuffle 2n integers as without using extra space132
982Count Primes in Ranges132
983Maximum subsequence sum such that no three are consecutive132
984Segment Tree132
985Minimum Height Trees LeetCode Solution132
986Maximum Product Subarray132
987Minesweeper LeetCode Solution132
988Binary Search Tree Delete Operation132
989Find postorder traversal of BST from preorder traversal132
990First missing positive131
991Height of a generic tree from parent array131
992Find the Difference Leetcode Solution131
993Count pair with Given Sum131
994Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution131
995Level Order Traversal of Binary Tree131
996Find Duplicate Subtrees131
997Asteroid Collision LeetCode Solution131
998Boundary Traversal of binary tree131
999Find number of pairs in an array such that their XOR is 0130
1000Partition Equal Subset Sum130
1001Largest Number Leetcode Solution130
1002Serialize and Deserialize Binary Tree130
1003Maximum Length of Repeated Subarray130
1004The Painter’s Partition Problem130
1005Kth Smallest Element in a BST Leetcode Solution130
1006Double the first element and move zero to end130
1007Level order traversal using two Queues130
1008Insertion in a Binary Tree130
1009Make The String Great Leetcode Solution130
1010Find the First Circular Tour that visits all the Petrol Pumps130
1011Kill Process LeetCode Solution130
1012Graph Valid Tree LeetCode Solution130
1013Unique Paths II129
1014Longest Nice Substring LeetCode Solution129
1015Valid Boomerang Leetcode Solution129
1016Shortest Completing Word Leetcode Solution129
1017Rearrange array such that even positioned are greater than odd129
1018Compute nCr % p129
1019Number Of Longest Increasing Subsequence129
1020Count subarrays where second highest lie before highest129
1021K Closest Points to Origin Leetcode Solution129
1022Friends Of Appropriate Ages LeetCode Solution129
1023Boolean Parenthesization Problem128
1024Collect maximum points in a grid using two traversals128
1025String Matching in an Array Leetcode Solution128
1026Maximum Number of Ways to Partition an Array LeetCode Solution128
1027The Maze III LeetCode Solution128
1028Minimum Size Subarray Sum128
1029Scramble String LeetCode Solution128
1030Binary Search Tree128
1031Invalid Transactions LeetCode Solution128
1032Balanced Binary Tree128
1033Decrypt String from Alphabet to Integer Mapping Leetcode Solution128
1034Longest subsequence such that difference between adjacents is one128
1035Construction of Longest Increasing Subsequence (N log N)128
1036Number of palindromic paths in a matrix128
1037Ugly Number II LeetCode Solution128
1038Advantages of BST over Hash Table128
1039Construct Binary Tree from given Parent Array representation127
1040Build an Array With Stack Operations Leetcode Solution127
1041Design Hit Counter LeetCode Solution127
1042Defanging an IP Address LeetCode Solution127
1043Add two numbers127
1044Employee Importance LeetCode Solution127
1045Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1046Find Peak Element127
1047Next Greater Element III LeetCode Solution127
1048Find whether a subarray is in form of a mountain or not127
1049Maximum Product of Indexes of Next Greater on Left and Right127
1050Ugly Numbers127
1051Morris Inorder Traversal127
1052Maximum weight transformation of a given string127
1053Regular Expression Matching Regular Expression Matching LeetCode Solution126
1054Count minimum steps to get the given desired array126
1055Populating Next Right Pointers in Each Node Leetcode Solution126
1056Implement Trie (Prefix Tree) Leetcode Solution126
1057Kth Smallest Element in a Sorted Matrix LeetCode Solution126
1058Find the minimum distance between two numbers126
1059Available Captures for Rook Leetcode Solution126
1060Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’126
1061Lowest Common Ancestor126
1062Minimum Index Sum of Two Lists126
1063Iterative Depth First Traversal of Graph126
1064Validate Binary Search Tree126
1065Maximum Sum of 3 Non-Overlapping Subarrays126
1066Super Ugly Number125
1067Find a Peak Element II LeetCode Solution125
1068Move all negative elements to end in order with extra space allowed125
1069Binary Tree Right Side View LeetCode Solution125
1070Number of Closed Islands Leetcode Solution125
1071Maximize Distance to Closest Person LeetCode Solution125
1072Path Sum II LeetCode Solution125
1073Recover Binary Search Tree Leetcode Solution125
1074Bitwise AND of Numbers Range LeetCode Solution125
1075Custom Sort String Leetcode Solution125
1076Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution125
1077Longest Bitonic Subsequence125
1078Subarrays with K Different Integers Leetcode Solution124
1079Rearrange array such that even index elements are smaller and odd index elements are greater124
1080Types of Binary Tree124
1081Largest BST Subtree LeetCode Solution124
1082Day of the Year Leetcode Solution124
1083Remove Duplicates from Sorted Array II Leetcode Solution124
1084Binary Tree Data Structure124
1085Divisible Pairs Counting124
1086Maximum difference between frequency of two elements such that element having greater frequency is also greater124
1087Next Permutation Leetcode Solution123
1088Smallest Common Region Leetcode Solution123
1089Count pairs from two sorted arrays whose sum is equal to a given value x123
1090Generate Parentheses Leetcode Solution123
1091Path Sum123
1092Serialize and Deserialize Binary Tree LeetCode Solution123
1093Clone a Binary Tree with Random Pointers123
1094Combination Sum IV LeetCode Solution123
1095Print Next Greater Number of Q queries123
1096Print all triplets in sorted array that form AP123
1097Consecutive Characters LeetCode Solution123
1098Number of Students Doing Homework at a Given Time Leetcode Solution123
1099Kth Smallest Product of Two Sorted Arrays LeetCode Solution123
1100Search in Sorted Rotated Array123
1101Find Smallest Range Containing Elements from k Lists123
1102Maximum Product Subarray122
1103Number of siblings of a given Node in n-ary Tree122
1104Level of Each node in a Tree from source node122
1105Root to Leaf path with target sum Leetcode Solutions122
1106Topological Sorting122
1107Remove Palindromic Subsequences Leetcode Solution122
1108Distinct Subsequences121
1109Write Code to Determine if Two Trees are Identical121
1110Third Maximum Number Leetcode Solution121
1111Convert BST into a Min-Heap without using array121
1112Print Right View of a Binary Tree121
1113Bottom View of a Binary Tree121
1114Remove duplicates from sorted array121
1115Find maximum difference between nearest left and right smaller elements121
1116Valid Tic-Tac-Toe State LeetCode Solution121
1117Constant time range add operation on an array121
1118Minimum sum of squares of character counts in a given string after removing k characters120
1119Count Largest Group Leetcode Solution120
1120Products of ranges in an array120
1121Mean of Array After Removing Some Elements Leetcode Solution120
1122Search Insert Position120
1123Cutting a Rod120
1124Find Three Element From Different Three Arrays Such That a + b + c = sum120
1125Iterative method to find ancestors of a given binary tree120
1126Palindrome Permutation LeetCode Solution120
1127Minimum Absolute Difference in BST Leetcode Solution119
1128Print modified array after executing the commands of addition and subtraction119
1129Prime Palindrome LeetCode Solution119
1130Reformat The String Leetcode Solution119
1131Minimum Score Triangulation of Polygon Leetcode Solution119
1132Longest Subarray of 1’s After Deleting One Element LeetCode Solution119
1133Increasing Triplet Subsequence LeetCode Solution119
1134Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution119
1135Thousand Separator Leetcode Solution119
1136Maximum Binary Tree119
1137Moser-de Bruijn Sequence119
1138Cells with Odd Values in a Matrix LeetCode Solution119
1139Longest Increasing Consecutive Subsequence119
1140Golomb sequence118
1141Construct K Palindrome Strings LeetCode Solution118
1142Sum of Even Numbers After Queries118
1143Search an Element in Sorted Rotated Array118
1144Kth Smallest Number in Multiplication Table Leetcode Solution117
1145Count even length binary sequences with same sum of first and second half bits117
1146K maximum sums of overlapping contiguous sub-arrays117
1147Swap Nodes In Pairs117
1148Transform a BST to Greater sum Tree117
1149Binary Tree to Binary Search Tree Conversion117
1150Queries for Number of Distinct Elements in a Subarray117
1151Maximum Product of Splitted Binary Tree LeetCode Solution117
1152Find maximum length Snake sequence117
1153Possible Bipartition LeetCode Solution117
1154Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1155Longest Repeated Subsequence117
1156Factorial Trailing Zeroes LeetCode Solution117
1157Red-Black Tree Introduction117
1158Delete Nodes and Return Forest Leetcode Solution116
1159Priority Queue116
1160Merge two BSTs with limited extra space116
1161Decision Tree116
1162K’th Largest element in BST using constant extra space116
1163Maximize sum of consecutive differences in a circular array116
1164Palindromic Substrings Leetcode Solution116
1165Minimum Cost to Move Chips to The Same Position LeetCode Solution116
1166Rotate Array116
1167Subset Sum Problem in O(sum) space116
1168Check Array Formation Through Concatenation Leetcode Solution116
1169Search Suggestions System LeetCode Solution115
1170Bus Routes Leetcode Solution115
1171Find the smallest binary digit multiple of given number115
1172Closest Binary Search Tree Value Leetcode Solution115
1173Web Crawler LeetCode Solution115
1174Compare Strings by Frequency of the Smallest Character Leetcode Solution115
1175First Bad Version115
1176Minimum Sideway Jumps LeetCode Solution115
1177Find a sorted subsequence of size 3 in linear time115
1178Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1179Count Pairs Whose Products Exist in Array114
1180Diameter of N-Ary Tree LeetCode Solution114
1181Minimum Moves to Equal Array Elements LeetCode Solution114
1182Number of Orders in the Backlog Leetcode Solution114
1183Maximum number of segments of lengths a, b and c113
1184Swapping Nodes in a Linked List Leetcode Solution113
1185Decrease Elements To Make Array Zigzag LeetCode Solution113
1186Given a binary tree, how do you remove all the half nodes?113
1187Reverse a Path in BST using Queue113
1188Contiguous Array LeetCode Solution113
1189Maximum sum bitonic subarray112
1190Find Largest Value in Each Tree Row LeetCode Solution112
1191Kth Smallest Element in a BST112
1192Queue Reconstruction by Height112
1193Lowest Common Ancestor in Binary Search Tree112
1194Matchsticks to Square Leetcode Solution112
1195Convert Sorted Array to Binary Search Tree LeetCode Solutions112
1196Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution112
1197Moving Stones Until Consecutive Leetcode Solution112
1198Champagne Tower LeetCode Solution112
1199Valid Triangle Number111
1200New 21 Game111
1201Reformat Date LeetCode Solution111
1202Array Queries for multiply replacements and product111
1203Closest Leaf in a Binary Tree LeetCode Solution111
1204Range Sum Query using Sparse Table110
1205Maximum sum of pairs with specific difference110
1206How to print maximum number of A’s using given four keys110
1207Range Queries for Longest Correct Bracket Subsequence110
1208Maximum Depth Of Binary Tree110
1209Replace two consecutive equal values with one greater110
1210Write a function to get the intersection point of two Linked Lists110
1211Integer Break LeetCode Solution110
1212Graph and its representation110
1213Sum of Left Leaves LeetCode Solution110
1214Valid Perfect Square LeetCode Solution110
1215Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1216Concatenation of Array LeetCode Solution110
1217Maximum sum of a path in a Right Number Triangle109
1218Lowest Common Ancestor of a Binary Tree Leetcode Solution109
1219Divide Two Integers Leetcode Solution109
1220Print modified array after multiple array range increment operations109
1221BST to a Tree with Sum of all Smaller Keys109
1222Guess The Word109
1223The kth Factor of n Leetcode Solution109
1224Merge Sort109
1225Arithmetic Slices II – Subsequence LeetCode Solution109
1226Path Crossing Leetcode Solution109
1227Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution109
1228Count Subsets Having Distinct Even Numbers108
1229Check for Identical BSTs without building the trees108
1230Check if each internal node of a BST has exactly one child108
1231Design Skiplist LeetCode Solution108
1232Flatten 2D Vector LeetCode Solution108
1233Queries on Probability of Even or Odd Number in given Ranges108
1234Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1235Check Completeness of a Binary Tree LeetCode Solution108
1236Check if all levels of two Binary Tree are anagrams or not108
1237Largest Plus Sign Leetcode Solution107
1238Perfect Squares LeetCode Solution107
1239Graph Cloning107
1240Parallel Courses II LeetCode Solution107
1241Mean of range in array107
1242Longest Common Prefix Using Word by Word Matching107
1243Power of Two107
1244Sliding Window Median Leetcode Solution107
1245Bold Words in String LeetCode Solution106
1246Count and Toggle Queries on a Binary Array106
1247Symmetric Tree LeetCode Solution Leetcode Solution106
1248Print n terms of Newman-Conway Sequence106
1249Find Minimum in Rotated Sorted Array II LeetCode Solution106
1250Maximize Elements Using Another Array106
1251Maximum Array from Two given Arrays Keeping Order Same106
1252LRU Cache Leetcode Solution106
1253Missing Number106
1254Find minimum number of merge operations to make an array palindrome106
1255Verify Preorder Serialization of a Binary Tree105
1256Excel Sheet Column Title LeetCode Solution105
1257Find k-th smallest element in BST (Order Statistics in BST)105
1258Contiguous Array105
1259Maximum Product Subarray104
1260Print Ancestors of a Given Binary Tree Node Without Recursion104
1261Next greater element104
1262Check If a String Can Break Another String Leetcode Solution103
1263Merge k Sorted Lists Leetcode Solution103
1264Image Overlap LeetCode Solution103
1265Minimum Remove to Make Valid Parentheses LeetCode Solution103
1266Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1267Smallest Range II Leetcode Solution103
1268Check if two nodes are on the same path in a Tree102
1269Palindrome Partitioning101
1270Check in binary array the number represented by a subarray is odd or even101
1271Orderly Queue LeetCode Solution101
1272Koko Eating Bananas LeetCode Solution100
1273Min Cost Climbing Stairs LeetCode Solution100
1274Merge Sorted Array100
1275Check if X can give change to every person in the Queue99
1276Newman–Shanks–Williams prime99
1277Different Ways to Add Parentheses Leetcode Solution98
1278Number of elements less than or equal to a given number in a given subarray98
1279Peeking Iterator LeetCode Solution98
1280Range Minimum Query (Square Root Decomposition and Sparse Table)97
1281Maximum Sum Increasing Subsequence97
1282Largest Submatrix With Rearrangements LeetCode Solution97
1283Number of indexes with equal elements in given range96
1284Find maximum average subarray of k length96
1285Queries for Decimal Values of Subarrays of a Binary Array96
1286Longest Substring Without Repeating Characters Leetcode Solution95
1287Maximum product of an increasing subsequence95
1288Array Nesting Leetcode Solution94
1289Check given array of size n can represent BST of n levels or not94
1290Minimum Total Space Wasted With K Resizing Operations LeetCode Solution94
1291Binary Tree to Binary Search Tree Conversion using STL set93
1292Arranging Coins Leetcode Solution93
1293Random Pick Index LeetCode Solution92
1294Encoded String With Shortest Length LeetCode Solution92
1295Minimum Number of People to Teach LeetCode Solution92
1296Find the Winner of the Circular Game LeetCode Solution91
1297Queries on XOR of greatest odd divisor of the range91
1298Jump Game IV LeetCode Solution90
1299Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1300Reach a Number LeetCode Solution90
1301Convert to Base -2 LeetCode Solution90
1302Convert a BST to a Binary Tree such that sum of all greater keys is added to every key90
1303Insert Delete GetRandom O(1) Leetcode Solution89
1304Add Two Numbers II Leetcode Solution87
1305Palindrome Number LeetCode Solution87
1306Vertical Order Traversal of Binary Tree LeetCode Solution86
1307Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution85
1308Print Maximum Length Chain of Pairs84
1309Design Underground System Leetcode Solution84
1310Continuous Subarray Sum LeetCode Solution82
1311Detect Capital Leetcode Solution81
1312Design A Leaderboard Leetcode Solution79
1313Top K Frequent Elements LeetCode Solution76
1314Substring with Concatenation of All Words Leetcode Solution76
1315Minimum Swaps to Group All 1’s Together Leetcode Solution75
1316Minimum Path Sum Leetcode Solution73
1317Odd Even Linked List Leetcode Solution72
1318Decode String Leetcode Solution71
1319Binary Tree Inorder Traversal LeetCode Solution71
1320Shifting Letters LeetCode Solution71
1321Count Sub Islands LeetCode Solution70
1322Maximum Population Year LeetCode Solution70
1323Find the Town Judge LeetCode Solution69
1324Shortest Unsorted Continuous Subarray LeetCode Solution69
1325Best Meeting Point LeetCode Solution69
1326Longest Common Subsequence LeetCode Solution68
1327Sum Root to Leaf Numbers LeetCode Solution68
1328Find the Town Judge LeetCode Solution66
1329Design Add and Search Words Data Structure LeetCode Solution65
1330Rectangle Overlap LeetCode Solution63
1331Maximum Population Year LeetCode Solution63
1332Stone Game IV LeetCode Solution61
1333Insert into a Sorted Circular Linked List LeetCode Solution61
1334Score of Parenthesis LeetCode Solution60
1335Flatten Binary Tree to Linked List LeetCode Solution59
1336Valid Triangle Number LeetCode Solution59
1337Range Sum Query 2D – Immutable LeetCode Solution59
1338Is Graph Bipartite? LeetCode Solution57
1339Reveal Cards In Increasing Order Leetcode Solution53
1340Divide Chocolate LeetCode Solution50
1341Range Sum of BST LeetCode Solution41
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution39
1343Reverse Integer Leetcode Solution38
1344Sort Colors LeetCode Solution36
1345Find K Closest Elements LeetCode Solution33
1346Excel Sheet Column Number LeetCode Solution31
1347Rotate String LeetCode Solution30
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution28
Translate »