DDSA Solutions
POTD Solutions

GeeksforGeeks Java Solutions

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

695
Solved
185
Explained

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