DDSA Solutions
POTD Solutions

GeeksforGeeks Java Solutions

Java solutions for GeeksforGeeks problems with step-by-step explanations on 605+ problems, plus approach notes and complexity analysis across the full archive.

606
Solved
605
Explained
Advertisement

606 problemsFull explanation available

#Title
10 - 1 Knapsack Problem
21s Surrounded by 0s
32D Difference Array
42D Submatrix Sum Queries
5Activity Selection
6Add 1 to a Linked List Number
7Add Binary Strings
8Add Number Linked Lists
9Aggressive Cows
10Alien Dictionary
11All numbers with specific difference
12All Subsets Xor Sum
13All Unique Permutations of an array
14Allocate Minimum Pages
15Alternate positive and negative numbers
16Alternative Sorting
17Anagram
18Anagram Palindrome
19Ancestors in Binary Tree
20AND In Range
21Array Duplicates
22Array to BST
23Articulation Point - II
24ASCII Range Sum
25Assign Mice Holes
26Balancing Consonants and Vowels Ratio
27Bellman-Ford
28BFS of graph
29Binary Searchable Count
30Binary Strings with Equal Sum of Two Halves
31Binary Tree to DLL
32Bitonic Point
33Boolean Parenthesization
34Bottom View of Binary Tree
35Brackets in Matrix Chain Multiplication
36Bridge edge in a graph
37BST to greater sum tree
38BST with Dead End
39Buildings with Sunlight
40Burning Tree
41Bus Conductor
42Bus Ticket Change
43Buy Stock with Transaction Fee
44Candy
45Case-specific Sorting of Strings
46Check for BST
47Check for Power
48Check if a String is Subsequence of Other
49Check if an Array is Max Heap
50Check if frequencies can be equal
51Check if subtree
52Check If two Line segments Intersect
53Check Repeated Substring with K Replacements
54Chocolate Distribution Problem
55Chocolate Pickup II
56Chocolates Pickup
57Circle of strings
58Clone a linked list with next and random pointer
59Clone an Undirected Graph
60Clone List with Next and Random
61Closest Neighbour in BST
62Closest Three Sum
63Coin Change (Count Ways)
64Coin Change (Minimum Coins)
65Coin Piles
66Common in 3 Sorted Arrays
67Compare two fractions
68Consecutive 1's not allowed
69Construct an array from its pair-sum array
70Construct Binary Tree from Parent Array
71Construct List using XOR Queries
72Construct Tree from Inorder & Preorder
73Construct Tree from Preorder & Postorder
74Container With Most Water
75Count all triplets with given sum in sorted array
76Count Derangements
77Count distinct elements in every window
78Count elements less than or equal to k in a sorted rotated array
79Count increasing Subarrays
80Count Indices to Balance Even and Odd Sums
81Count Inversions
82Count Linked List Nodes
83Count Numbers Containing Specific Digits
84Count of distinct substrings
85Count pairs Sum in matrices
86Count Pairs whose sum is less than target
87Count pairs with given sum
88Count Reverse Pairs
89Count set bits
90Count Smaller elements
91Count Sorted Digit Groupings
92Count Spanning Trees in a Graph
93Count Subarray with k odds
94Count Subarrays with given XOR
95Count Subset With Target Sum II
96Count the Coprimes
97Count the number of possible triangles
98Count the paths
99Count Unique Vowel Strings
100Count ways to N'th Stair(Order does not matter)
101Count X in Range of a Sorted Array
102Counting elements in two arrays
103Course Schedule I
104Course Schedule II
105Coverage of all Zeros in a Binary Matrix
106Cut rope to maximise product
107Cutting Binary String
108Decode the string
109Delete Alternate Nodes
110Delete node in Doubly Linked List
111Delete Nodes with Greater on Right
112Deletion and Reverse in Circular Linked List
113Design MinMax Queue
114Detect Loop in linked list
115DFS of Graph
116Diameter of a Binary Tree
117Dice throw
118Difference Check
119Dijkstra Algorithm
120Directed Graph Cycle
121Distance of nearest cell having 1
122Distribute Candies
123Divisible by 13
124Duplicate Subtrees
125Edit Distance
126Elements in range [a, b]
127Elements in the Range
128Equal Point in Brackets
129Equalize All Prefix Sums
130Equalize the Towers
131Equilibrium Point
132Evaluation of Postfix Expression
133Exactly one swap
134Exit Point in a Matrix
135Express as Consecutive Number Sum
136Expression Add Operators
137Expression contains redundant bracket or not
138Extract the Number from the String
139Facing the sun
140Farthest Smaller Right
141Find all possible palindromic partitions of a String
142Find All Triplets with Zero Sum
143Find H-Index
144Find K Smallest Sum Pairs
145Find Kth Rotation
146Find length of Loop
147Find maximum volume of a cuboid
148Find median in a stream
149Find Only Repetitive Element from 1 to n-1
150Find rectangle with corners as 1
151Find the closest pair from two arrays
152Find the first node of loop in linked list
153Find the longest string
154Find the number of islands
155Find the Sum of Last N nodes of the Linked List
156Finding Profession
157Fixing Two nodes of a BST
158Flattening a Linked List
159Flip to Maximize 1s
160Flood fill Algorithm
161Floyd Warshall
162Form a palindrome
163Form the Largest Number
164Frog Jump
165Game of XOR
166Game with String
167Gas Station
168Generate all binary strings
169Generate Binary Numbers
170Generate IP Addresses
171Generate Permutations of an array
172Get Min from Stack
173Get Minimum Squares
174Gold Mine Problem
175Graph Diameter
176Gray Code
177Group Balls by Sequence
178Happiest Triplet
179Height of Binary Tree
180Histogram Max Rectangular Area
181Huffman Encoding
182Identical Linked Lists
183Implement Atoi
184Implement k Queues in a Single Array
185Implement Pow
186Implement Trie
187Indexes of Subarray Sum
188Inorder Traversal
189Insert in Sorted Circular Linked List
190Insert in Sorted way in a Sorted DLL
191Insert Interval
192Integral Points Inside Triangle
193Interleave the First Half of the Queue with Second Half
194Interleaved Strings
195Intersection in Y Shaped Lists
196Intersection of Two arrays with Duplicate Elements
197Intersection of Two Sorted Arrays
198Intersection Point in Y Shaped Linked Lists
199Is Binary Tree Heap
200Is Linked List Length Even
201Job Sequencing Problem
202Josephus problem
203K closest elements
204K Closest Points to Origin
205K closest Values
206k largest elements
207K Sized Subarray Maximum
208K Sum Paths
209K-Pangrams
210K-th element of two Arrays
211K-th Largest Sum Contiguous Subarray
212k-th Smallest in BST
213Kadane's Algorithm
214Koko Eating Bananas
215Kth distance
216Kth element in Matrix
217Kth Largest in a Stream
218Kth Missing Positive Number in a Sorted Array
219Kth Smallest
220Kth Smallest Number in Multiplication Table
221Largest BST
222Largest Divisible Subset
223Largest number in K swaps
224Largest number in one swap
225Largest Pair Sum
226Largest square formed in a matrix
227Largest subarray of 0's and 1's
228Last Coin in a Game of Alternates
229Last Digit of a^b
230Last Moment Before All Ants Fall Out
231LCM Triplet
232LCS of three strings
233Left Rotate Matrix K times
234Left View of Binary Tree
235Length of Longest Cycle in a Graph
236Level Order in spiral form
237Level order traversal
238Lexicographically Largest String After Deleting K Characters
239Lexicographically smallest after removing k
240Linked List Group Reverse
241Linked List Matrix
242Linked list of strings forms a palindrome
243Longest alternating subsequence
244Longest Bounded-Difference Subarray
245Longest Common Increasing Subsequence
246Longest Common Prefix of Strings
247Longest Common Subsequence
248Longest Common Substring
249Longest Consecutive Subsequence
250Longest Increasing Subsequence
251Longest Palindrome in a String
252Longest Palindromic Subsequence
253Longest Periodic Proper Prefix
254Longest Prefix Suffix
255Longest Repeating Character Replacement
256Longest Span in two Binary Arrays
257Longest String Chain
258Longest Subarray Length
259Longest subarray with Atmost two distinct integers
260Longest Subarray with Majority Greater than K
261Longest Subarray with Sum K
262Longest substring with distinct characters
263Longest Substring with K Uniques
264Longest valid Parentheses
265Look and Say Pattern
266Lowest Common Ancestor in a BST
267LRU Cache
268Majority Element
269Majority Element II
270Majority Vote
271Make array elements unique
272Make Binary Tree From Linked List
273Make Matrix Beautiful
274Make Strings Equal
275Make the array beautiful
276Matrix Chain Multiplication
277Max Circular Subarray Sum
278Max DAG Edges
279Max distance between same elements
280Max min Height
281Max of min for every window size
282Max Product Subset
283Max Profit from Two Machines
284Max rectangle
285Max Score from Subarray Mins
286Max sum in the configuration
287Max Sum Increasing Subsequence
288Max sum path in two arrays
289Max Sum Subarray of size K
290Max Xor Subarray of size K
291Maximise String Score
292Maximize Array Value After Rearrangement
293Maximize median after doing k addition operation
294Maximize Number of 1's
295Maximize partitions in a String
296Maximize The Cut Segments
297Maximize the minimum difference between k elements
298Maximum Connected group
299Maximum Difference
300Maximum Non-Adjacent Nodes Sum
301Maximum Non-Overlapping Odd Palindrome Sum
302Maximum number of overlapping Intervals
303Maximum of minimum for every window size
304Maximum path sum
305Maximum path sum from any node
306Maximum People Visible in a Line
307Maximum Product Subarray
308Maximum product subset of an array
309Maximum Stone Removal
310Maximum subarray sum 2
311Maximum Sum Combination
312Maximum sum of elements not part of LIS
313Maximum sum of Non-adjacent nodes
314Maximum Sum Problem
315Maximum sum Rectangle
316Maximum XOR of two numbers in an array
317Mean of range in array
318Median in a row-wise sorted Matrix
319Median of BST
320Median of two sorted arrays
321Meeting Rooms
322Meeting Rooms III
323Merge K sorted linked lists
324Merge Sort for Linked List
325Merge two BST 's
326Merge two sorted linked lists
327Merge Without Extra Space
328Middle of a Linked List
329Min Add to Make Parentheses Valid
330Min Chars to Add for Palindrome
331Min Cost Climbing Stairs
332Min Swaps to Group 1s
333Minimal Cost
334Minimize the Heights I
335Minimize the Heights II
336Minimum Cost of ropes
337Minimum Cost Path
338Minimum cost to connect all houses in a city
339Minimum Cost to cut a board into squares
340Minimum Cost to Cut a Stick of length N
341Minimum Cost to Fill Given Weight
342Minimum Cost to Merge Stones
343Minimum days to make M bouquets
344Minimum Deletions
345Minimum height roots
346Minimum Jumps
347Minimum K Consecutive Bit Flips
348Minimum Multiplications to reach End
349Minimum number of deletions and insertions
350Minimum Number of Workers
351Minimum Operations to Connect Hospitals
352Minimum Platforms
353Minimum repeat to make substring
354Minimum Steps to Halve Sum
355Minimum sum
356Minimum Toggle to Partition
357Minimum Weight Cycle
358Minimum Window Subsequence
359Mirror Tree
360Missing And Repeating
361Missing Element in Range
362Missing element of AP
363Missing in Array
364Mobile numeric keypad
365Modify the Array
366Mother Vertex
367Move All Zeroes to End
368Multiply two linked lists
369Multiply two strings
370N meetings in one room
371N-Queen Problem
372nCr
373Nearest multiple of 10
374Nearly sorted
375Next element with greater frequency
376Next Greater Element
377Next Greater Element in Circular Array
378Next Permutation
379Next Smallest Palindrome
380Nine Divisors
381Non Repeating Character
382Non-Attacking Black and White Knights
383Non-overlapping Intervals
384Not a subset sum
385Nth Natural Number
386Number of BST From Array
387Number of distinct subsequences
388Number of occurrence
389Number of pairs
390Number of paths in a matrix with k coins
391Number of Rectangles in a Circle
392Number of Ways to Arrive at Destination
393Occurence of an integer in a Linked List
394Opposite Sign Pair Reduction
395Optimal binary search tree
396Optimal Strategy For A Game
397Overlapping Intervals
398Painting the Fence
399Pair Sum in BST
400Pair with given sum in a sorted array
401Pairs with certain difference
402Pairs with difference k
403Palindrome Linked List
404Palindrome Pairs
405Palindrome Sentence
406Palindrome SubStrings
407Parenthesis Checker
408Partition Equal Subset Sum
409Partitions with Given Difference
410Pascal Triangle
411Path With Minimum Effort
412Peak element
413Permutations of a String
414Police and Thieves
415Populate Inorder Successor for all nodes
416Possible Words From Phone Digits
417Postfix Evaluation
418Postorder Traversal
419Power of k in factorial of n
420Powerful Integer
421Predecessor and Successor
422Prime List
423Prime Pair with Target Sum
424Print Anagrams Together
425Print Bracket Number
426Print Diagonally
427Print leaf nodes from preorder traversal of BST
428Product array puzzle
429Product Pair
430Pythagorean Triplet
431Queue Reversal
432Quick Sort on Linked List
433Range LCM Queries
434Rat in a Maze
435Rat in a Maze Problem - I
436Remaining String
437Remove all occurences of duplicates in a linked list
438Remove BST keys outside given range
439Remove Duplicates
440Remove duplicates in array
441Remove Half Nodes
442Remove Invalid Parentheses
443Remove loop in Linked List
444Remove Spaces
445Remove the balls
446Reorganize The Array
447Replace O's with X's
448Replace with XOR of Adjacent
449Reverse a Doubly Linked List
450Reverse a linked list
451Reverse an Array
452Reverse Words
453Roman Number to Integer
454Roof Top
455Root to leaf path sum
456Root to Leaf Paths
457Root to leaf paths sum
458Rotate a Linked List
459Rotate and delete
460Rotate Array
461Rotate by 90 degree
462Rotate Deque By K
463Rotten Oranges
464Row with max 1s
465Safe States
466Search for Subarray
467Search in a Row-Column sorted matrix
468Search in a row-wise sorted matrix
469Search in a sorted Matrix
470Search in an almost Sorted Array
471Search in fully rotated sorted 2D matrix
472Search in Rotated Sorted Array
473Search insert position of K in a sorted array
474Search Pattern (KMP-Algorithm)
475Search Pattern (Rabin-Karp Algorithm)
476Seating Arrangement
477Second Best Minimum Spanning Tree
478Second Largest
479Segregate 0s and 1s
480Serialize and deserialize a binary tree
481Set Matrix Zeroes
482Set Matrix Zeros
483Shop in Candy Store
484Shortest Common Supersequence
485Shortest Cycle
486Shortest path in Undirected Graph
487Shortest Path in Weighted undirected graph
488Shortest Path Using Atmost One Curved Edge
489Single Number
490Size of Binary Tree
491Smallest distinct window
492Smallest Divisor
493Smallest number
494Smallest Positive Missing
495Smallest Positive Missing Number
496Smallest range in K lists
497Smallest window containing 0, 1 and 2
498Smallest window containing all characters
499Smallest window in a string containing all the characters of another string
500Solve the Sudoku
501Sort 0s, 1s and 2s
502Sort a k sorted doubly linked list
503Sort a linked list of 0s, 1s and 2s
504Sort by Absolute Difference
505Sort in specific order
506Sort the given array after applying the given equation
507Sorted and Rotated Minimum
508Sorted subsequence of size 3
509Sorting Elements of an Array by Frequency
510Spirally traversing a matrix
511Split an array into two equal Sum subarrays
512Split array in three equal sum subarrays
513Split Array Largest Sum
514Split Array Subsequences
515Split Linked List Alternatingly
516Split the Array
517Square root of a number
518Stable Marriage Problem
519Stickler Thief
520Stickler Thief II
521Stock Buy and Sell – Max 2 Transactions Allowed
522Stock Buy and Sell – Max K Transactions Allowed
523Stock Buy and Sell – Max one Transaction Allowed
524Stock Buy and Sell – Multiple Transaction Allowed
525Stock Buy and Sell with Cooldown
526Stock span problem
527Stream First Non-repeating
528String stack
529Strings Rotations of Each Other
530Sub-arrays with equal number of occurences
531Subarray Frequency Count Queries
532Subarray range with given sum
533Subarrays With At Most K Distinct Integers
534Subarrays with First Element Minimum
535Subarrays with sum K
536Subset Sum Problem
537Subset XOR
538Substring with Max Zero-One Diff
539Substrings of length k with k-1 distinct elements
540Substrings with K Distinct
541Substrings with same first and last characters
542Sum of all substrings of a number
543Sum of Mode
544Sum of Nodes in BST Range
545Sum of nodes on the longest path
546Sum of subarray minimum
547Sum of subarray minimums
548Sum of subarray ranges
549Sum of Subarrays
550Sum of XOR of all pairs
551Sum Pair closest to target
552Sum Tree
553Sum-string
554Summed Matrix
555Swap and Maximize
556Swap diagonals
557Swap Kth nodes from ends
558Symmetric Tree
559Target Sum
560The Celebrity Problem
561The Knight's tour problem
562The Painter's Partition Problem-II
563The Palindrome Pattern
564Toeplitz matrix
565Top K Frequent in Array
566Top View of Binary Tree
567Topological sort
568Total count
569Total Decoding Messages
570Trail of ones
571Transform to Sum Tree
572Transpose of Matrix
573Trapping Rain Water
574Travelling Salesman Problem
575Tree Boundary Traversal
576Triplet Family
577Two Equal Sum Subarrays
578Two Smallests in Every Subarray
579Two Sum - Pair with Given Sum
580Two Swaps
581Two water Jug problem
582Tywin's War Strategy
583Undirected Graph Cycle
584Union of Arrays with Duplicates
585Union of Two Sorted Arrays with Distinct Elements
586Unique K-Number Sum
587Unique Number I
588Unique Number II
589Unique Number III
590Unique Paths in a Grid
591URLify a given string
592Validate an IP Address
593Vertical Sum
594Vertical Tree Traversal
595Vertical Width of a Binary Tree
596Walls Coloring II
597Ways to Reach the n'th Stair
598Ways To Tile A Floor
599Weighted Job Scheduling
600Wifi Range
601Wildcard Pattern Matching
602Word Break
603Word Search
604XOR Linked List
605XOR Pairs less than K
606ZigZag Tree Traversal