Update running total

Easy
4 views 23 Jan 2026
Task: given array, compute running total array where res[i]=sum upto i....

Count positives and negatives

Easy
4 views 23 Jan 2026
Task: return [posCount, negCount, zeroCount] for the array....

Find min and max together

Easy
5 views 23 Jan 2026
Task: return [min,max] in one pass using two variables....

Swap without temp using arithmetic

Medium
4 views 23 Jan 2026
Task: swap two ints without temp using + and - and return [b,a]....

Track best score with index

Medium
5 views 23 Jan 2026
Task: return index of maximum value (first occurrence)....

Sliding sum of size k

Medium
5 views 23 Jan 2026
Task: return sum of every window of size k as long array....

Balance tracker

Medium
4 views 23 Jan 2026
Task: starting balance and transactions array (+credit, -debit). Return first index where balance becomes negative, else -1....

Compute prefix min array

Medium
5 views 23 Jan 2026
Task: return prefix minimum array where res[i]=min(a[0..i])....

Variable scope demo (return value)

Hard
4 views 23 Jan 2026
Task: show variable shadowing safely by computing result with local variables only....

Count distinct in range queries (offline)

Hard
6 views 23 Jan 2026
Task: answer queries (l,r) for number of distinct values. Use Mo's algorithm outline....

Event counter with rollback (savepoint idea)

Hard
4 views 23 Jan 2026
Task: apply updates (+x) but also handle rollback to previous savepoint index. Return final value....

Rate limiter counter

Hard
6 views 23 Jan 2026
Task: given timestamps in seconds, allow at most limit events in last window seconds. Return allowed count....

Compute max profit with two transactions

Hard
5 views 23 Jan 2026
Task: return max profit with at most 2 buy-sell transactions. Use variables for DP states....

Reverse an array in-place

Easy
4 views 23 Jan 2026
Task: reverse the given int array without using another array. Try using two pointers (start/end) and swap....

Count even numbers

Easy
4 views 23 Jan 2026
Task: return how many values are even in the given int array. Keep it simple with one loop....

Check array sorted (non-decreasing)

Easy
5 views 23 Jan 2026
Task: return true if the array is sorted in non-decreasing order. Compare adjacent elements....

Find maximum element

Easy
4 views 23 Jan 2026
Task: return the maximum value from a non-empty array....

Sum of array elements

Easy
5 views 23 Jan 2026
Task: return sum of all elements in the array....

Move zeros to end (stable)

Medium
9 views 23 Jan 2026
Task: move all zeros to the end while keeping the relative order of non-zero elements....

Rotate right by k

Medium
5 views 23 Jan 2026
Task: rotate the array to the right by k steps without extra array. Use reverse trick....

Second largest distinct

Medium
6 views 23 Jan 2026
Task: return the second largest distinct value. If it does not exist, return Integer.MIN_VALUE....

Find missing number 1..n

Medium
6 views 23 Jan 2026
Task: array has n-1 numbers from 1..n without duplicates. Return the missing number....

Two sum in sorted array

Medium
3 views 23 Jan 2026
Task: array is sorted. Return indices of two numbers that sum to target, else [-1,-1]. Use two pointers....

Count subarrays with sum = k

Hard
5 views 23 Jan 2026
Task: return how many subarrays have sum exactly k (negative numbers allowed). Use prefix sum + hashmap....

Maximum product of any pair

Hard
4 views 23 Jan 2026
Task: values can be negative. Return maximum product of any two elements....

Merge two sorted arrays into first

Hard
4 views 23 Jan 2026
Task: a has size m+n, first m elements valid. b has n elements. Merge b into a in sorted order (in-place)....

Longest consecutive sequence length

Hard
4 views 23 Jan 2026
Task: return length of the longest consecutive sequence (order in array does not matter). Use HashSet....

Range add queries (difference array)

Hard
5 views 23 Jan 2026
Task: start with zeros of size n. Each query (l,r,add) adds add to every index in [l,r]. Return final array....

Build a list from input values

Easy
5 views 23 Jan 2026
Task: create a List and add all given numbers in the same order....

Remove duplicates but keep order

Easy
5 views 23 Jan 2026
Task: remove duplicates from a list but keep first-seen order. Return the cleaned list....

Count frequency of numbers

Easy
5 views 23 Jan 2026
Task: return a map of number -> frequency from the given int array....

Use Deque as stack

Easy
6 views 23 Jan 2026
Task: implement a small stack using Deque and support push/pop/peek....

Queue simulation

Easy
4 views 23 Jan 2026
Task: process operations on a queue (offer and poll). Return final size....

First unique number in list

Medium
8 views 23 Jan 2026
Task: return the first number that appears exactly once in the list, else return null....

Top K frequent numbers

Medium
5 views 23 Jan 2026
Task: return k numbers with highest frequency. If tie, any order is fine....

Group numbers by remainder

Medium
5 views 23 Jan 2026
Task: group numbers by (value % m) and return a map remainder -> list of numbers....

Sliding window max using deque

Medium
4 views 23 Jan 2026
Task: for each window of size k, return max. Use deque of indices....

Sort objects by two fields

Medium
5 views 23 Jan 2026
Task: sort Student by marks (desc), then id (asc)....

LRU cache (basic)

Hard
4 views 23 Jan 2026
Task: implement a small LRU cache using LinkedHashMap. Support get/put with capacity....

Detect cycle in directed graph

Hard
6 views 23 Jan 2026
Task: given n and edges, detect if there is a cycle (directed). Use DFS + recursion stack....

Merge intervals

Hard
5 views 23 Jan 2026
Task: given intervals, merge overlapping ones and return merged list....

K-way merge of sorted lists

Hard
5 views 23 Jan 2026
Task: merge k sorted int arrays into one sorted array using a priority queue....

Most common within window

Hard
3 views 23 Jan 2026
Task: for each i, consider last k numbers ending at i. Return the max frequency seen in any window....

Sum numbers divisible by 3

Easy
5 views 23 Jan 2026
Task: return sum of numbers from 1..n that are divisible by 3. Use loop and if condition....

Count digits in a number

Easy
4 views 23 Jan 2026
Task: return how many digits are in an integer. Handle 0 properly....

Reverse digits

Easy
4 views 23 Jan 2026
Task: reverse digits of a number and return result (ignore overflow for now)....

Check leap year

Easy
4 views 23 Jan 2026
Task: return true if year is leap year using correct rules (divisible by 400, or divisible by 4 but not 100)....

Print star pattern count

Easy
5 views 23 Jan 2026
Task: return total stars printed in a triangle of height n (1+2+...+n)....

FizzBuzz count

Medium
5 views 23 Jan 2026
Task: count how many numbers in 1..n would print FizzBuzz (div by 3 and 5)....

Nth Fibonacci (iterative)

Medium
4 views 23 Jan 2026
Task: return nth Fibonacci number (0-indexed) using iterative loop....

GCD using Euclid

Medium
5 views 23 Jan 2026
Task: return gcd(a,b) using while loop (Euclid algorithm)....

Find first prime >= n

Medium
3 views 23 Jan 2026
Task: return the first prime number that is >= n....

Simulate simple ATM steps

Medium
4 views 23 Jan 2026
Task: given balance and withdrawals array, process in order. If withdrawal > balance skip it. Return final balance....

Minimum steps to reach target (1 or 2)

Hard
4 views 23 Jan 2026
Task: you can add 1 or 2 each move. Return minimum moves to reach exactly n....

Count paths in grid with obstacles

Hard
5 views 23 Jan 2026
Task: grid has 0 (free) and 1 (blocked). Return number of paths from (0,0) to (m-1,n-1) moving right/down....

Validate parentheses string

Hard
5 views 23 Jan 2026
Task: given a char array containing '(', ')', return true if it is balanced....

Binary search first >= target

Hard
4 views 23 Jan 2026
Task: return the first index where a[i] >= target in a sorted array, else return n....

Max subarray sum (Kadane)

Hard
4 views 23 Jan 2026
Task: return maximum subarray sum (at least one element)....

Check if value fits in byte

Easy
4 views 23 Jan 2026
Task: return true if x can fit in a signed byte (-128..127)....

Convert char digit to int

Easy
4 views 23 Jan 2026
Task: given a digit character '0'..'9', return its integer value....

Absolute difference as long

Easy
4 views 23 Jan 2026
Task: return absolute difference between two ints as a long (avoid overflow)....

Check if string is numeric (no sign)

Easy
7 views 23 Jan 2026
Task: return true if all characters are digits and length > 0....

Parse binary string to int

Easy
5 views 23 Jan 2026
Task: parse a binary string (like 10110) and return integer value....

Clamp value in range

Medium
6 views 23 Jan 2026
Task: clamp x into [low, high] and return clamped value....

Compare doubles with epsilon

Medium
6 views 23 Jan 2026
Task: return true if two doubles are almost equal using epsilon....

Count set bits in int

Medium
5 views 23 Jan 2026
Task: return number of set bits (1s) in binary representation of x....

Safe average without overflow

Medium
4 views 23 Jan 2026
Task: return average of two ints without overflow....

Detect overflow on add

Medium
6 views 23 Jan 2026
Task: return true if a+b overflows 32-bit int....

Convert seconds to hh:mm:ss parts

Hard
6 views 23 Jan 2026
Task: given total seconds, return [hours, minutes, seconds]....

Fast power (pow)

Hard
6 views 23 Jan 2026
Task: compute a^b using fast exponentiation (b >= 0)....

Encode two ints into one long

Hard
6 views 23 Jan 2026
Task: pack two 32-bit ints (a,b) into one long and unpack later....

Compute checksum mod 1e9+7

Hard
7 views 23 Jan 2026
Task: compute checksum = sum(i*value) mod 1e9+7 for array values....

Split integer into digits array

Hard
5 views 23 Jan 2026
Task: return digits of a non-negative number in correct order....

Safe divide

Easy
4 views 23 Jan 2026
Task: divide a by b and throw ArithmeticException when b is 0....

Validate positive input

Easy
6 views 23 Jan 2026
Task: if x is negative, throw IllegalArgumentException. Else return x....

Parse int with fallback

Easy
7 views 23 Jan 2026
Task: parse integer from string; if invalid, return fallback value....

Array access safe read

Easy
5 views 23 Jan 2026
Task: return a[index] if valid else throw IndexOutOfBoundsException....

Ensure object not null

Easy
4 views 23 Jan 2026
Task: if obj is null throw NullPointerException else return it....

Try-with-resources style (concept)

Medium
3 views 23 Jan 2026
Task: show a method that closes a Closeable safely in finally without hiding original exception....

Custom exception for business rule

Medium
4 views 23 Jan 2026
Task: create a custom exception InsufficientBalanceException and throw it when withdraw > balance....

Validate age range

Medium
5 views 23 Jan 2026
Task: age must be 1..120. If not, throw IllegalArgumentException....

Convert checked to unchecked

Medium
6 views 23 Jan 2026
Task: wrap IOException into RuntimeException and rethrow....

Multiple validations with one throw

Medium
4 views 23 Jan 2026
Task: validate (nameLength > 0) and (score between 0..100). Throw IllegalArgumentException if any fails....

Transactional-like update with rollback

Hard
5 views 23 Jan 2026
Task: update two array positions. If any index is invalid, keep array unchanged and throw exception....

Retry operation 3 times

Hard
7 views 23 Jan 2026
Task: call a risky operation and retry up to 3 times on exception. If still fails, throw last exception....

Validate sorted input or fail fast

Hard
5 views 23 Jan 2026
Task: if array is not sorted, throw IllegalStateException. Else return true....

Propagate cause chain

Hard
5 views 23 Jan 2026
Task: wrap exception with cause and rethrow as RuntimeException keeping original cause....

Fail-safe resource close with primary exception

Hard
4 views 23 Jan 2026
Task: simulate primary exception and also close exception; ensure primary is thrown....

Swap two elements

Easy
4 views 23 Jan 2026
Task: swap a[i] and a[j] in an int array....

Copy array manually

Easy
4 views 23 Jan 2026
Task: create and return a new array copy without using Arrays.copyOf....

Find first occurrence

Easy
4 views 23 Jan 2026
Task: return first index of target in array, else -1....

Count occurrences

Easy
4 views 23 Jan 2026
Task: return how many times target appears in array....

Find minimum value

Easy
4 views 23 Jan 2026
Task: return minimum value from non-empty array....

Reverse a subrange

Medium
5 views 23 Jan 2026
Task: reverse elements between l and r inclusive....

Remove element (new length)

Medium
4 views 23 Jan 2026
Task: remove all occurrences of val in-place and return new length (order can change)....

Merge two arrays alternately

Medium
4 views 23 Jan 2026
Task: merge a and b alternately into a new array. Extra tail should be appended at end....

Prefix sum array

Medium
5 views 23 Jan 2026
Task: return prefix sums where pref[i] = sum of a[0..i]....

Find majority element (Boyer-Moore)

Medium
4 views 23 Jan 2026
Task: assume there is a majority element (> n/2). Return it using O(1) space....

Find intersection of two arrays (unique)

Hard
3 views 23 Jan 2026
Task: return unique intersection of a and b....

Minimum window size for sum >= target

Hard
4 views 23 Jan 2026
Task: given positive integers, return min length subarray with sum >= target. If not found return 0....

Rearrange array by sign (stable)

Hard
4 views 23 Jan 2026
Task: place negative numbers first then non-negative, keeping relative order inside each group....

Count inversions (merge sort)

Hard
5 views 23 Jan 2026
Task: return number of inversions in array using merge sort....

Product of array except self

Hard
7 views 23 Jan 2026
Task: return array where res[i] = product of all elements except a[i] (no division)....

Check if number is palindrome

Easy
4 views 23 Jan 2026
Task: return true if integer reads same from left to right....

Count vowels in char array

Easy
5 views 23 Jan 2026
Task: return count of vowels (a,e,i,o,u) in given char array (lowercase)....

Check anagram (letters only)

Easy
6 views 23 Jan 2026
Task: return true if two char arrays are anagrams (same letters with same counts)....

Compute factorial

Easy
4 views 23 Jan 2026
Task: return factorial of n (n>=0) using loop....

Check power of two

Easy
5 views 23 Jan 2026
Task: return true if x is power of two....

Implement lowerBound utility

Medium
5 views 23 Jan 2026
Task: write a reusable method lowerBound for sorted array. Return first index with value >= target....

Implement upperBound utility

Medium
5 views 23 Jan 2026
Task: return first index where a[i] > target in sorted array....

String compression (count runs)

Medium
5 views 23 Jan 2026
Task: compress chars by counting consecutive same characters. Return new length....

Find first non-repeating char

Medium
5 views 23 Jan 2026
Task: given lowercase letters, return index of first non-repeating char, else -1....

Validate IPv4 (basic)

Medium
4 views 23 Jan 2026
Task: validate 4 parts (0..255) without leading plus. Input as int[4]....

LRU-like method using LinkedHashMap

Hard
5 views 23 Jan 2026
Task: build a helper method that returns a LinkedHashMap with accessOrder enabled....

Run-length decode

Hard
4 views 23 Jan 2026
Task: decode pairs (value,count) into an array....

Evaluate postfix expression

Hard
5 views 23 Jan 2026
Task: evaluate postfix expression given as int tokens and ops codes. Use stack....

KMP prefix table

Hard
5 views 23 Jan 2026
Task: build prefix function (lps) for pattern char array (classic KMP)....

Find median of two sorted arrays (merge approach)

Hard
4 views 23 Jan 2026
Task: return median of two sorted arrays using merge-like walk (O(n+m))....

Encapsulation with getter/setter

Easy
7 views 23 Jan 2026
Task: create a class Account with private balance and methods deposit/withdraw....

Constructor overloading

Easy
5 views 23 Jan 2026
Task: create Point with (x,y) and also default constructor (0,0)....

Method overriding basics

Easy
6 views 23 Jan 2026
Task: create Shape base and Rectangle child overriding area()....

Interface usage

Easy
4 views 23 Jan 2026
Task: create interface Computation and a class Add that implements it....

Immutable value object

Easy
4 views 23 Jan 2026
Task: create immutable Pair (a,b) with equals and hashCode....

Copy constructor and defensive copy

Medium
6 views 23 Jan 2026
Task: create a class Team holding int[] scores. Use defensive copy in constructor....

Comparable implementation

Medium
5 views 23 Jan 2026
Task: implement Comparable for Student by marks desc then id asc....

Factory method pattern

Medium
4 views 23 Jan 2026
Task: create static factory for Rectangle to validate inputs (w,h > 0)....

Composition over inheritance

Medium
5 views 23 Jan 2026
Task: create Logger used inside Service (composition). Provide method logCount....

Polymorphic billing

Medium
4 views 23 Jan 2026
Task: create interface Billable and two implementations. Return total bill for array of Billable....

Strategy pattern for sorting key

Hard
5 views 23 Jan 2026
Task: implement strategy to pick sort key from object and sort list accordingly....

Thread-safe counter (synchronized)

Hard
6 views 23 Jan 2026
Task: implement a Counter class with increment and get methods thread-safe using synchronized....

Deep clone object graph (simple)

Hard
4 views 23 Jan 2026
Task: clone a linked list node chain without sharing nodes....

Builder pattern (basic)

Hard
4 views 23 Jan 2026
Task: implement a Builder for User with optional fields id and age....

Equals/HashCode with inheritance (safe)

Hard
4 views 23 Jan 2026
Task: design equals for base class without breaking symmetry (use final class)....

Bitwise AND of two numbers

Easy
5 views 23 Jan 2026
Task: return a & b....

Check odd using bit operator

Easy
4 views 23 Jan 2026
Task: return true if x is odd using bitwise operator....

Swap using XOR

Easy
4 views 23 Jan 2026
Task: swap a[i] and a[j] using XOR (only if i!=j)....

Set k-th bit

Easy
5 views 23 Jan 2026
Task: set k-th bit (0-indexed) in x and return result....

Clear k-th bit

Easy
5 views 23 Jan 2026
Task: clear k-th bit (0-indexed) in x and return result....

Toggle k-th bit

Medium
7 views 23 Jan 2026
Task: toggle k-th bit and return result....

Extract lowest set bit

Medium
7 views 23 Jan 2026
Task: return lowest set bit value (like x & -x). If x==0 return 0....

Count bits using Kernighan

Medium
5 views 23 Jan 2026
Task: count set bits using x &= (x-1) loop....

Check if kth bit is set

Medium
5 views 23 Jan 2026
Task: return true if k-th bit is set....

Build mask between l..r

Medium
4 views 23 Jan 2026
Task: create bitmask with bits l..r set (inclusive)....

Reverse bits in 32-bit int

Hard
5 views 23 Jan 2026
Task: reverse bits of int and return result....

Find single number (others twice)

Hard
4 views 23 Jan 2026
Task: in array where every number appears twice except one, return the single number using XOR....

Find two single numbers

Hard
4 views 23 Jan 2026
Task: every number appears twice except two numbers. Return the two unique numbers....

Subset check using bitmask

Hard
5 views 23 Jan 2026
Task: given masks a and b, return true if b is subset of a (all bits in b also set in a)....

Compute parity bit

Hard
5 views 23 Jan 2026
Task: return 0 if number of set bits is even, 1 if odd....

Swap two variables using temp

Easy
4 views 23 Jan 2026
Task: swap two integers a and b and return as array [b,a]....

Increment and return

Easy
6 views 23 Jan 2026
Task: increment x by 1 and return the new value....