DDSA Solutions
POTD Solutions

GeeksforGeeks Java Solutions

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

689
Solved
179
Explained

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