DDSA Solutions
POTD Solutions

GeeksforGeeks Java Solutions

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

652
Solved
143
Explained

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