DDSA Solutions
POTD Solutions

GeeksforGeeks Java Solutions

Daily Problem of the Day solutions — clean Java code with explanations and complexity analysis for every GFG POTD.

Advertisement

565 problemsFull explanation available

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