Array Programming Question Paper 100 Questions
Array Programming Question Paper 100 Questions
Instructions
• Solve the questions in order from easy to intermediate.
• Prefer loops and basic logic before using built-in array methods.
• For questions that prohibit sorting or built-in methods, follow the constraint.
• Write clean, readable code and test your solution with multiple inputs.
Beginner Level
1. Write a program to print all elements of an array.
7. Write a program to count the number of elements in an array without using length.
10. Write a program to search for a given element using linear search.
12. Write a program to copy all elements from one array into another.
15. Write a program to find the first element of an array without directly using index 0.
16. Write a program to find the last element of an array without directly using the last index.
18. Write a program to count how many elements are greater than a given number.
19. Write a program to count how many elements are smaller than a given number.
Page 1
22. Write a program to find the difference between the largest and smallest elements.
24. Write a program to replace every even number with its square.
25. Write a program to create a new array containing only positive numbers.
Easy Level
26. Write a program to reverse an array without using a built-in reverse function.
27. Write a program to find the second largest element without sorting.
28. Write a program to find the second smallest element without sorting.
34. Write a program to print only elements that occur exactly once.
37. Write a program to find the index of the first occurrence of a given value.
38. Write a program to find the index of the last occurrence of a given value.
39. Write a program to count how many times a given value occurs.
40. Write a program to merge two arrays without using a built-in concat function.
41. Write a program to compare two arrays and check whether they contain the same elements in the
same order.
47. Write a program to move all zeros to the end of the array.
49. Write a program to separate even and odd numbers into two arrays.
50. Write a program to find all pairs of elements whose sum equals a target value.
Intermediate Level
51. Write a program to find the missing number from an array containing numbers from 1 to N.
Page 2
52. Write a program to find all missing numbers from a range 1 to N.
53. Write a program to find common elements between two arrays without using built-in intersection
methods.
54. Write a program to find elements present in the first array but not the second.
55. Write a program to find the union of two arrays without duplicates.
61. Write a program to find the maximum difference arr[j] - arr[i] where j > i.
62. Write a program to find the minimum difference between any two elements.
63. Write a program to find the pair with the smallest absolute difference.
64. Write a program to find the pair with the largest sum.
65. Write a program to find all triplets whose sum equals a target value.
66. Write a program to find whether an array contains a subarray with sum equal to a target.
69. Write a program to find the length of the longest increasing contiguous subarray.
70. Write a program to find the length of the longest decreasing contiguous subarray.
71. Write a program to find the longest sequence of consecutive 1s in a binary array.
72. Write a program to find the maximum number of consecutive zeros in a binary array.
73. Write a program to find the majority element that occurs more than N/2 times.
74. Write a program to find all elements that occur more than N/3 times.
75. Write a program to find the equilibrium index where left sum equals right sum.
78. Write a program to answer multiple range-sum queries using prefix sums.
79. Write a program to find the product of all elements except the current element for every index.
82. Write a program to find the longest subarray with sum equal to zero.
83. Write a program to find the longest subarray with equal numbers of 0s and 1s.
Page 3
84. Write a program to find the smallest positive missing number.
85. Write a program to rearrange an array so positive and negative numbers alternate.
86. Write a program to sort an array containing only 0s, 1s, and 2s without using a built-in sort.
87. Write a program to merge two sorted arrays into one sorted array.
89. Write a program to find the kth largest element without fully sorting the array.
90. Write a program to find the kth smallest element without fully sorting the array.
95. Write a program to find the next greater element for every array element.
96. Write a program to find the previous greater element for every array element.
97. Write a program to find the next smaller element for every array element.
98. Write a program to find the previous smaller element for every array element.
99. Write a program to find the maximum value of arr[i] - arr[j] + arr[k] under valid index ordering.
100. Write a program to find the longest subarray containing at most K distinct elements.
101. Write a program to find the minimum length subarray whose sum is at least a target.
102. Write a program to find all leaders in an array; an element is a leader if it is greater than all elements
to its right.
103. Write a program to find the maximum profit from buying and selling a stock once using an array of
prices.
Page 4