DDSA Solutions
POTD Solutions

GeeksforGeeks Java Solutions

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

627
Solved
120
Explained

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