Java Zero to Hero Practice Roadmap
A structured practice roadmap. Solve foundational logic, array algorithms, data structures, recursion, dynamic programming, and system design problems.
Keep going! Master these to reach hero status.
Basic Programming(1–20)
Fundamental control flow, math, and number manipulation.
Print 'Hello World'
ActiveWrite a standard Java program that prints 'Hello, World!' to the console output.
Swap two numbers without using a third variable
ActiveSwap two integer variables `a` and `b` without introducing a temporary third variable.
Check if a number is even or odd
ActiveGiven an integer `n`, determine if it is Even or Odd using arithmetic operators.
Find the largest of three numbers
ActiveWrite a program to determine and print the largest of three integers `a`, `b`, and `c`.
Check if a number is positive, negative, or zero
ActiveDetermine whether a given number is positive (> 0), negative (< 0), or zero (== 0).
Calculate the factorial of a number
ActiveCalculate n! (n factorial) for a non-negative integer n.
Generate the Fibonacci series
ActiveGenerate the first N terms of the Fibonacci sequence starting from 0, 1.
Reverse a number
ActiveGiven an integer n, reverse its digits (e.g. 1234 -> 4321).
Check if a number is a palindrome
ActiveCheck whether a given integer reads the same backwards as forwards.
Check if a number is prime
ActiveDetermine if a number n > 1 is a prime number (divisible only by 1 and itself).
Print all prime numbers in a range
ActivePrint all prime numbers between a given range [start, end].
Find the GCD (HCF) of two numbers
ActiveFind the Greatest Common Divisor (GCD) of two integers `a` and `b` using Euclidean algorithm.
Find the LCM of two numbers
ActiveCalculate the Least Common Multiple (LCM) of two numbers `a` and `b`.
Count the digits in a number
ActiveCount the total number of digits in an integer n.
Find the sum of digits
ActiveCalculate the sum of all digits of a given integer n.
Check if a number is an Armstrong number
ActiveCheck if a number of k digits equals the sum of its digits each raised to the k-th power (e.g. 153 = 1^3 + 5^3 + 3^3).
Check if a number is a perfect number
ActiveCheck if a number equals the sum of its proper positive divisors (excluding itself e.g. 6 = 1 + 2 + 3).
Print multiplication tables
ActivePrint the multiplication table for a given integer n up to 10.
Generate a number pyramid
ActivePrint a centered number pyramid pattern of height N.
Print various star patterns
ActivePrint a right-angled star triangle pattern of N rows.
Arrays(21–45)
Traversal, searching, sorting, and core 1D array operations.
Find the largest element in an array
ActiveFind and return the maximum element present in an integer array.
Find the smallest element in an array
ActiveFind and return the minimum element present in an integer array.
Find the second largest element in an array
ActiveFind the second largest distinct element in an array in O(n) time.
Find duplicate elements in an array
ActiveFind all duplicate values present in an array.
Remove duplicates from an array
ActiveRemove duplicate values from a sorted array in-place or return a clean distinct array.
Reverse an array
ActiveReverse an array of N integers in-place and print the reversed elements space-separated.
Rotate an array left
ActiveRotate an array of N integers to the left by K positions.
Rotate an array right
ActiveRotate an array of N integers to the right by K positions.
Merge two sorted arrays
ActiveMerge two sorted arrays into a single sorted sequence.
Sort an array
ActiveSort an array of N integers in ascending order.
Find missing number
ActiveGiven array of N-1 distinct integers in range 1 to N, find the missing integer.
Find common elements between arrays
ActiveFind common elements present in array A (size N) and array B (size M).
Find intersection of arrays
ActiveCompute the intersection of two integer arrays preserving duplicates.
Find union of arrays
ActiveFind the union of two integer arrays (distinct sorted elements).
Move all zeros to the end
ActiveMove all zeros to end while maintaining relative order of non-zero elements.
Find maximum subarray sum (Kadane's Algorithm)
ActiveFind the contiguous subarray with the largest sum using Kadane's algorithm.
Find pair with a given sum
ActiveFind a pair of numbers in array adding up to target sum S.
Find triplet with a given sum
ActiveFind three elements whose sum equals target sum S.
Find equilibrium index
ActiveFind index where sum of lower indices equals sum of higher indices.
Find frequency of elements
ActiveCount frequency of each distinct element and print as 'x: count' in ascending order.
Count even and odd numbers
ActiveCount how many even and odd integers are present in array.
Find majority element
ActiveFind element appearing strictly more than N/2 times or print -1.
Rearrange positive and negative numbers
ActiveRearrange array so all positive numbers appear before negative numbers.
Find leaders in an array
ActiveAn element is a leader if it is >= all elements to its right.
Find the longest consecutive sequence
ActiveFind length of the longest consecutive sequence in unsorted array.
2D Arrays(46–55)
Matrix creation, traversal, searching, rotation, transpose, spiral order, and more.
Create and print a 2D matrix
ActiveRead a 2D matrix of size R×C from stdin and print it row by row, with elements separated by spaces.
Find the sum of each row and column in a matrix
ActiveGiven a 2D matrix, compute and print the sum of each row and the sum of each column.
Transpose a matrix
ActiveCompute the transpose of a given N×N square matrix (swap rows with columns).
Search for an element in a matrix
ActiveSearch for a target value in an R×C matrix and print its position, or 'Not found' if absent.
Find the diagonal sum of a matrix
ActiveCompute the sum of primary and secondary diagonals of an N×N matrix.
Print a matrix in spiral order
ActivePrint all elements of an R×C matrix in clockwise spiral order.
Rotate a matrix 90 degrees clockwise
ActiveRotate an N×N square matrix 90 degrees clockwise in-place.
Find the maximum element in each row
ActiveFor each row in an R×C matrix, find and print the maximum element.
Check if a matrix is symmetric
ActiveCheck if given N×N matrix is symmetric (matrix[i][j] == matrix[j][i]).
Multiply two matrices
ActiveMultiply two matrices A (R×K) and B (K×C) and print product matrix.
Strings(56–80)
String manipulation, pattern matching, sliding window on text.
Reverse a string
ActiveReverse the given string.
Check if a string is a palindrome
ActiveCheck if input string reads the same forwards and backwards.
Count vowels and consonants
ActiveCount vowels and consonants in string (alphabetic characters only).
Count words
ActiveCount whitespace-separated words in sentence.
Remove whitespace
ActiveRemove all whitespace characters from input string.
Remove duplicate characters
ActiveRemove duplicate characters keeping only first occurrence.
Find duplicate characters
ActiveFind characters that appear more than once in string.
Check if two strings are anagrams
ActiveCheck if two strings are anagrams (contain same characters).
Find the first non-repeated character
ActiveFind first non-repeated character or print 'None'.
Find the first repeated character
ActiveFind first character that repeats or print 'None'.
Find the longest word
ActiveFind the longest word in a sentence.
Count character frequency
ActiveCount frequency of each character in alphabetical order as 'char: count'.
Compress a string
ActiveRun-length compression: 'aabcccccaaa' becomes 'a2b1c5a3'.
Reverse words in a sentence
ActiveReverse the order of words in a sentence.
Check if one string is a rotation of another
ActiveCheck if string B is a rotation of string A.
Convert lowercase to uppercase
ActiveConvert all lowercase characters to uppercase without built-in toUpperCase().
Find all substrings
ActiveGenerate all non-empty substrings of string space-separated.
Find the longest common prefix
ActiveFind longest common prefix string among N strings.
Validate parentheses
ActiveDetermine if parentheses '()', '[]', '{}' are properly closed.
Remove special characters
ActiveRemove non-alphanumeric characters from string.
Find the longest palindrome substring
ActiveFind longest palindromic substring in S.
Check if a string contains only digits
ActiveCheck if string consists exclusively of digits (0-9).
Find the most frequent character
ActiveFind character with highest frequency in string.
Replace spaces with %20
ActiveURL-encode string by replacing spaces with '%20'.
Check if two strings are isomorphic
ActiveCheck if characters in string s can be replaced to get string t.
Object-Oriented Programming(81–95)
Classes, encapsulation, inheritance, polymorphism, abstraction, interfaces, exception handling, and deep copy.
Class and Constructor
ActiveCreate a class Student with fields name and roll. Read name and roll, instantiate a Student, and print details.
Encapsulation with Getters and Setters
ActiveCreate BankAccount with private balance. Support deposit(amount) and withdraw(amount) only if balance >= amount.
Method Overloading
ActiveImplement a Calculator with overloaded add methods for (int, int), (int, int, int), and (double, double).
Single Inheritance
ActiveCreate Animal with method sound() and derived class Dog with method bark(). Call both methods.
Method Overriding (Runtime Polymorphism)
ActiveBase Shape has method draw(). Derived Circle and Square override draw(). Call draw() using a Shape reference.
Using the super Keyword
ActivePerson has constructor taking name. Employee extends Person, calls super(name), and adds id. Print employee details.
Static Variables and Methods
ActiveMaintain a static counter that increments every time an instance of Item is created. Instantiate N items and print count.
Abstract Classes and Methods
ActiveAbstract class Vehicle has abstract speed() and concrete fuel(). Car extends Vehicle. Print outputs of both.
Interfaces and Implementation
ActiveDefine interface Playable with method play(). Guitar and Piano implement Playable. Call play() on selected instrument.
Multiple Interfaces Implementation
ActiveSmartPhone implements Camera (takePhoto) and MusicPlayer (playMusic). Call both methods.
Interface Default and Static Methods
ActiveInterface Logger has static info(msg) and default log(msg). Implement in ConsoleLogger and invoke both.
Composition (HAS-A Relationship)
ActiveEngine has horsepower. Car HAS-A Engine. Instantiate Car with an Engine and print car status.
Exception Handling (Try-Catch-Finally)
ActiveRead a and b. Compute a / b. Catch ArithmeticException if b == 0 and print error. Always print 'Execution completed' in finally.
Custom Exception
ActiveDefine InvalidAgeException extends Exception. Throw it if age < 18. Catch and print 'InvalidAgeException: Underage'. Else print 'Eligible for voting'.
Copy Constructor and Deep Copy
ActiveImplement Point with copy constructor Point(Point other). Create p1, copy to p2, mutate p1.x += 10, print both points.
Linked List(96–110)
Singly/doubly linked lists, cycle detection, multi-pointer strategies.
Create a singly linked list
ActiveRead N integers, create a singly linked list, and print elements space-separated.
Reverse a linked list
ActiveReverse a singly linked list iteratively and print elements.
Detect a loop in a linked list
ActiveDetect if linked list contains a cycle using Floyd's algorithm.
Find the middle node of a linked list
ActiveFind middle node value using slow and fast pointers.
Remove duplicates from a sorted linked list
ActiveDelete duplicate nodes from a sorted linked list.
Merge two sorted linked lists
ActiveMerge two sorted linked lists into one sorted linked list.
Delete a node without the head pointer
ActiveGiven access only to that node, delete it from linked list.
Find the nth node from the end
ActiveFind value of K-th node from end of linked list.
Check if a linked list is a palindrome
ActiveDetermine if linked list values form a palindrome.
Reverse in groups of K
ActiveReverse nodes of linked list K at a time.
Find the intersection point of two linked lists
ActiveFind value of node where two singly linked lists merge.
Detect and remove a cycle
ActiveRemove cycle from linked list if present.
Flatten a linked list
ActiveFlatten a multi-level linked list with next and child pointers.
Sort a linked list
ActiveSort linked list in ascending order in O(N log N) using merge sort.
Clone a linked list with random pointers
ActiveCreate a deep copy of a linked list with next and random pointers.
Stack & Queue(111–125)
LIFO & FIFO structures, expression evaluation, monotonic stacks.
Implement a stack using an array
ActiveSimulate stack push and pop operations.
Implement a stack using a linked list
ActiveSimulate linked list backed stack push and pop.
Implement a queue using an array
ActiveSimulate queue enqueue and dequeue operations.
Implement a queue using a linked list
ActiveSimulate linked list backed FIFO queue.
Implement a queue using two stacks
ActiveImplement FIFO queue semantics using two LIFO stacks.
Implement a stack using two queues
ActiveImplement LIFO stack semantics using two queues.
Reverse a stack
ActiveReverse a stack of N integers and print elements from top to bottom.
Reverse a queue
ActiveReverse elements in a queue using a stack.
Check balanced parentheses
ActiveCheck if string of parentheses is balanced.
Next greater element
ActiveFor each element, find the first greater element to its right, or -1.
Stock span problem
ActiveCalculate span of stock prices (consecutive days price was <= today).
Min Stack
ActiveDesign a stack that retrieves the minimum element in O(1) time.
Circular queue
ActiveSimulate circular buffer queue with fixed capacity K.
Evaluate postfix expression
ActiveEvaluate value of postfix (Reverse Polish Notation) arithmetic expression.
Infix to postfix conversion
ActiveConvert valid infix expression with single-letter operands to postfix.
Trees & BST(126–140)
Binary trees, traversals, BST properties, ancestor problems.
Create a binary tree
ActiveBuild binary tree from level order array and print root value.
Inorder traversal
ActivePrint inorder traversal (left, root, right) of binary tree.
Preorder traversal
ActivePrint preorder traversal (root, left, right) of binary tree.
Postorder traversal
ActivePrint postorder traversal (left, right, root) of binary tree.
Level-order traversal
ActivePrint binary tree nodes in breadth-first level order.
Find tree height
ActiveCalculate max depth (height) of binary tree.
Count leaf nodes
ActiveCount number of leaf nodes in a complete binary tree.
Check if two trees are identical
ActiveCheck if two binary trees are structurally identical with same values.
Check if a tree is balanced
ActiveA balanced binary tree has depth difference of subtrees <= 1.
Find the Lowest Common Ancestor (LCA)
ActiveFind Lowest Common Ancestor (LCA) of nodes p and q in a BST.
Validate a Binary Search Tree (BST)
ActiveValidate if binary tree satisfies BST invariants.
Find the kth smallest element in a BST
ActiveFind K-th smallest element in a Binary Search Tree.
Mirror a binary tree
ActiveConvert binary tree into its mirror image.
Diameter of a binary tree
ActiveFind length of longest path between any two nodes in tree.
Serialize and deserialize a binary tree
ActiveConvert binary tree to string and back to identical tree.
Hashing(141–150)
HashMaps, HashSets, frequency counting, fast O(1) lookups.
Two Sum problem
ActiveFind 0-based indices of two numbers that add up to target.
Find duplicates using a HashSet
ActiveCheck if array contains any duplicate values.
Count frequencies using a HashMap
ActiveCount frequency of each element and print sorted.
Group anagrams
ActiveGroup an array of strings into anagram clusters.
Find the first unique element
ActiveFind first non-repeating element in array or -1.
Find the longest consecutive sequence
ActiveFind length of longest consecutive elements sequence.
Detect duplicate values
ActiveReturn true if any value appears at least twice in array.
Find subarrays with sum K
ActiveCount total contiguous subarrays whose sum equals K.
Find common elements
ActiveFind intersection of elements in arrays A and B.
LRU Cache implementation
ActiveSimulate Least Recently Used (LRU) Cache get and put operations.
Recursion & Backtracking(151–160)
Subsets, permutations, N-Queens, maze traversal.
Factorial using recursion
ActiveCalculate N! using recursion.
Fibonacci using recursion
ActiveCompute N-th Fibonacci number recursively (0-indexed).
Generate all subsets
ActiveGenerate all 2^N subsets of an integer array.
Generate permutations
ActiveCalculate total distinct permutations of array of N distinct integers.
Solve the N-Queens problem
ActiveFind number of distinct valid solutions to place N non-attacking queens on an N×N board.
Solve Sudoku
ActiveCheck if a 9x9 Sudoku board state is valid.
Rat in a Maze
ActiveCheck if path exists from top-left (0,0) to bottom-right (N-1,N-1) in maze.
Word Search
ActiveDetermine if word exists in 2D character grid by adjacent cells.
Tower of Hanoi
ActiveCalculate minimum moves required to solve Tower of Hanoi with N disks (2^N - 1).
Generate balanced parentheses
ActiveCalculate total valid combinations of N pairs of balanced parentheses (Catalan number).
Dynamic Programming(161–170)
Memoization, tabulation, subproblem optimization.
Climbing stairs
ActiveCount distinct ways to climb N steps taking 1 or 2 steps at a time.
Coin change
ActiveFind fewest number of coins needed to make up amount A.
Knapsack (0/1)
ActiveFind maximum value that can be put in a knapsack of capacity W.
Longest Common Subsequence (LCS)
ActiveFind length of longest common subsequence of two strings.
Longest Increasing Subsequence (LIS)
ActiveFind length of longest strictly increasing subsequence in array.
Edit distance
ActiveFind minimum operations (insert, delete, replace) to convert word1 to word2.
House Robber
ActiveMaximize robbery amount without robbing adjacent houses.
Maximum Product Subarray
ActiveFind contiguous subarray that has largest product.
Minimum Path Sum
ActiveFind path from top left to bottom right of R×C grid minimizing sum of numbers.
Partition Equal Subset Sum
ActiveDetermine if array can be partitioned into two subsets with equal sum.
Advanced Problems(171–175)
System design basics, LRU caches, multithreading, system architectures.
Implement an LRU Cache
ActiveImplement LRU Cache data structure supporting get and put in O(1).
Design a Parking Lot system
ActiveDesign parking lot with parking spots for small, medium, and big cars.
Design a Library Management System
ActiveManage book checkouts and returns tracking availability.
Implement a URL Shortener
ActiveDesign Base62 URL shortener converting integer IDs to short URLs.
Design a Multi-threaded Producer-Consumer system
ActiveSimulate thread-safe bounded buffer producer and consumer.