Practice Data Structures & Algorithms in Java
Master essential DSA patterns including Two Pointers, Sliding Window, Dynamic Programming, Trees, Graphs, and more. Learn the patterns that will help you solve any coding problem.
Work through 60 exercises with starter code, expected output, test cases, and hints.
Data Structures & Algorithms exercises
- Two Sum (Sorted Array) Java exercise — Find two numbers in a sorted array that add up to target
- Remove Duplicates from Sorted Array Java exercise — Remove duplicates in-place and return new length
- Container With Most Water Java exercise — Find two lines that form container with most water
- Three Sum Java exercise — Find all unique triplets that sum to zero
- Valid Palindrome Java exercise — Check if string is palindrome considering only alphanumeric
- Maximum Sum Subarray of Size K Java exercise — Find maximum sum of any contiguous subarray of size k
- Longest Substring with K Distinct Characters Java exercise — Find longest substring with at most k distinct characters
- Minimum Window Substring Java exercise — Find minimum window containing all characters of pattern
- Longest Repeating Character Replacement Java exercise — Longest substring with same letter after k replacements
- Fruit Into Baskets Java exercise — Maximum fruits you can collect with two baskets
- Fibonacci with DP Java exercise — Calculate nth Fibonacci number efficiently
- Climbing Stairs Java exercise — Count distinct ways to climb n stairs (1 or 2 steps)
- House Robber Java exercise — Maximum money without robbing adjacent houses
- Coin Change Java exercise — Minimum coins needed to make amount
- Longest Increasing Subsequence Java exercise — Find length of longest strictly increasing subsequence
- 0/1 Knapsack Java exercise — Maximum value with limited weight capacity
- Unique Paths in Grid Java exercise — Count paths from top-left to bottom-right
- Longest Common Subsequence Java exercise — Find length of longest common subsequence of two strings
- Edit Distance (Levenshtein) Java exercise — Minimum operations to convert one string to another
- Maximum Subarray (Kadane's Algorithm) Java exercise — Find contiguous subarray with largest sum
- Two Sum (Unsorted) Java exercise — Find two numbers that add up to target using HashMap
- Group Anagrams Java exercise — Group strings that are anagrams of each other
- Subarray Sum Equals K Java exercise — Count subarrays with sum equal to k
- Longest Consecutive Sequence Java exercise — Find length of longest consecutive elements sequence
- Valid Anagram Java exercise — Check if two strings are anagrams
- Valid Parentheses Java exercise — Check if parentheses string is valid
- Next Greater Element Java exercise — Find next greater element for each array element
- Daily Temperatures Java exercise — Days until warmer temperature
- Largest Rectangle in Histogram Java exercise — Find largest rectangular area in histogram
- Min Stack Java exercise — Design stack that supports getMin in O(1)
- Binary Tree Inorder Traversal Java exercise — Traverse tree in Left-Root-Right order
- Maximum Depth of Binary Tree Java exercise — Find the maximum depth (height) of a binary tree
- Binary Tree Level Order Traversal Java exercise — Traverse tree level by level (BFS)
- Validate Binary Search Tree Java exercise — Check if a binary tree is a valid BST
- Lowest Common Ancestor Java exercise — Find lowest common ancestor of two nodes
- Number of Islands Java exercise — Count number of islands in a 2D grid
- Clone Graph Java exercise — Create a deep copy of an undirected graph
- Course Schedule (Cycle Detection) Java exercise — Check if all courses can be finished
- Word Ladder (Shortest Path) Java exercise — Find shortest transformation sequence
- Rotting Oranges (Multi-source BFS) Java exercise — Minimum time for all oranges to rot
- Jump Game Java exercise — Can you reach the last index?
- Activity Selection (Interval Scheduling) Java exercise — Select maximum non-overlapping activities
- Gas Station Java exercise — Find starting station to complete circuit
- Partition Labels Java exercise — Partition string so each letter appears in at most one part
- Task Scheduler Java exercise — Minimum time to complete all tasks with cooldown
- Binary Search Java exercise — Find target in sorted array
- Search in Rotated Sorted Array Java exercise — Binary search in rotated array
- Find Minimum in Rotated Sorted Array Java exercise — Find the minimum element in rotated array
- Koko Eating Bananas Java exercise — Minimum eating speed to finish in h hours
- Capacity To Ship Packages Java exercise — Minimum ship capacity to ship all in D days
- Subsets (Power Set) Java exercise — Generate all subsets of a set
- Permutations Java exercise — Generate all permutations of an array
- Combination Sum Java exercise — Find combinations that sum to target
- N-Queens Java exercise — Place N queens on NxN board with no attacks
- Word Search Java exercise — Find if word exists in grid
- Kth Largest Element Java exercise — Find the kth largest element in array
- Merge K Sorted Lists Java exercise — Merge k sorted linked lists
- Top K Frequent Elements Java exercise — Find k most frequent elements
- Find Median from Data Stream Java exercise — Track median as numbers are added
- Meeting Rooms II Java exercise — Minimum number of conference rooms required
Browse the complete Java practice path · Open the online Java compiler