Arrays
100 Java Array Programming Questions
A curated list of 100 array-focused programming questions in Java — arranged Basic → Medium → Difficult. Paste this into your Blogger post and edit the colors/font variables in the <style> block.
Java • Arrays • Practice
A. Basic Array Programs (1–40)
- Write a program to read and print elements of an array.
- Write a program to find the length of an array.
- Write a program to print array elements in reverse order.
- Write a program to find the sum of array elements.
- Write a program to find the average of array elements.
- Write a program to find the maximum element in an array.
- Write a program to find the minimum element in an array.
- Write a program to search for an element in an array (linear search).
- Write a program to count even numbers in an array.
- Write a program to count odd numbers in an array.
- Write a program to count positive numbers in an array.
- Write a program to count negative numbers in an array.
- Write a program to count zeros in an array.
- Write a program to find the sum of even elements in an array.
- Write a program to find the sum of odd elements in an array.
- Write a program to find the second largest element in an array.
- Write a program to find the second smallest element in an array.
- Write a program to find both the largest and smallest element in an array.
- Write a program to copy all elements of one array to another array.
- Write a program to merge two arrays into a third array.
- Write a program to reverse an array without using a second array.
- Write a program to sort an array in ascending order.
- Write a program to sort an array in descending order.
- Write a program to check if an array is sorted in ascending order.
- Write a program to remove duplicate elements from an array.
- Write a program to find the frequency of each element in an array.
- Write a program to print unique elements in an array.
- Write a program to print duplicate elements in an array.
- Write a program to rotate an array left by one position.
- Write a program to rotate an array right by one position.
- Write a program to rotate an array left by k positions.
- Write a program to rotate an array right by k positions.
- Write a program to swap the first and last element of an array.
- Write a program to insert an element at a specific position in an array.
- Write a program to delete an element from a specific position in an array.
- Write a program to find the index of an element in an array.
- Write a program to print the first repeating element in an array.
- Write a program to print the first non-repeating element in an array.
- Write a program to count occurrences of a given element in an array.
- Write a program to print all pairs of elements in an array.
B. Medium Array Programs (41–75)
- Write a program to reverse each half of an array separately.
- Write a program to find the missing number in a sequence array.
- Write a program to find the duplicate number in an array of n+1 integers.
- Write a program to segregate even and odd numbers in an array.
- Write a program to segregate 0s and 1s in an array.
- Write a program to segregate 0s, 1s, and 2s in an array (Dutch national flag).
- Write a program to move all zeros to the end of an array.
- Write a program to move all negative numbers to one side of an array.
- Write a program to find the intersection of two arrays.
- Write a program to find the union of two arrays.
- Write a program to find common elements between two arrays.
- Write a program to find the difference between two arrays.
- Write a program to check if two arrays are equal.
- Write a program to check if two arrays are disjoint.
- Write a program to check if an array is a subset of another array.
- Write a program to find the maximum product of two elements in an array.
- Write a program to find the maximum sum subarray (Kadane’s algorithm).
- Write a program to find the minimum sum subarray.
- Write a program to find the longest increasing subsequence in an array.
- Write a program to find the longest decreasing subsequence in an array.
- Write a program to find the longest consecutive sequence in an array.
- Write a program to check if an array contains duplicate elements within k distance.
- Write a program to print leaders in an array (element greater than all elements to its right).
- Write a program to find equilibrium index (where left sum = right sum).
- Write a program to find peak elements in an array.
- Write a program to find the maximum difference between two elements in an array.
- Write a program to find the minimum difference between two elements in an array.
- Write a program to calculate the prefix sum of an array.
- Write a program to calculate the suffix sum of an array.
- Write a program to find a pair of elements whose sum is equal to a given number.
- Write a program to find all triplets whose sum is equal to a given number.
- Write a program to find all quadruplets whose sum is equal to a given number.
- Write a program to find the majority element in an array.
- Write a program to rearrange an array so that positive and negative numbers alternate.
- Write a program to rearrange an array such that arr[i] = i (if possible).
C. Difficult Array Programs (76–100)
- Write a program to find the maximum product subarray.
- Write a program to find the subarray with given sum (sliding window).
- Write a program to find the smallest subarray with sum greater than a given value.
- Write a program to find the largest subarray with equal number of 0s and 1s.
- Write a program to find the maximum circular subarray sum.
- Write a program to find the maximum sum of non-adjacent elements.
- Write a program to find the median of two sorted arrays.
- Write a program to find the kth smallest element in an array.
- Write a program to find the kth largest element in an array.
- Write a program to find the kth missing number in a sorted array.
- Write a program to merge overlapping intervals in an array.
- Write a program to find the minimum number of jumps to reach the end of an array.
- Write a program to find the minimum number of platforms required (train problem with arrays).
- Write a program to maximize stock profit from given price array (buy/sell once).
- Write a program to maximize stock profit (buy/sell multiple times).
- Write a program to maximize stock profit (at most two transactions).
- Write a program to check if an array can be divided into two parts with equal sum.
- Write a program to check if an array can be partitioned into k subsets with equal sum.
- Write a program to find the maximum length subarray with a given XOR.
- Write a program to find the maximum XOR of two elements in an array.
- Write a program to count inversions in an array (using merge sort).
- Write a program to find the minimum swaps required to sort an array.
- Write a program to find the next lexicographic permutation of an array.
- Write a program to solve the trapping rainwater problem.
- Write a program to solve the maximum histogram area problem using arrays.
Comments
Post a Comment