📘 100 Array Traversing Problems
Pattern-Based Practice for Beginners
📌 About This PDF
This PDF contains 100 array traversal problems, grouped by logic patterns.
All problems can be solved using simple loops such as for or while.
🎯 Focus on patterns, not memorization.
If you understand how to think, you can solve many problems on your own.
🔹 Pattern 1: Basic Traversal
(Goal: Learn how to visit every element in an array)
1. Print all elements of the array
→ Traverse the array from start to end and display each element one by one.
2. Print all elements in reverse order
→ Traverse the array from the last index to the first and print each value.
3. Print elements present at even indices
→ Print elements whose index position is even (0, 2, 4, …).
4. Print elements present at odd indices
→ Print elements whose index position is odd (1, 3, 5, …).
5. Print all positive elements
→ Traverse the array and print only values greater than zero.
6. Print all negative elements
→ Traverse the array and print only values less than zero.
7. Print all zero elements
→ Traverse the array and print elements that are exactly equal to zero.
8. Print elements divisible by 3
→ Print elements whose value can be divided by 3 without remainder.
9. Print elements greater than a given number X
→ Compare each element with X and print those greater than it.
10.Print elements less than or equal to X
→ Print elements whose value is less than or equal to X.
🔹 Pattern 2: Max / Min Comparison
(Goal: Learn comparison and updating values)
11.Find the maximum element in the array
→ Traverse the array and keep updating the largest value found.
12.Find the minimum element in the array
→ Traverse the array and keep updating the smallest value found.
13.Find the second maximum element
→ Find the largest and second largest values without sorting.
14.Find the second minimum element
→ Find the smallest and second smallest values using traversal.
15.Find the largest even number
→ Among all even numbers, find the maximum value.
16.Find the smallest odd number
→ Among all odd numbers, find the minimum value.
17.Find the index of the maximum element
→ Track the position (index) of the largest element.
18.Find the index of the minimum element
→ Track the position (index) of the smallest element.
19.Find the maximum element at even indices
→ Consider only elements at even indices and find the largest among them.
20.Find the minimum element at odd indices
→ Consider only elements at odd indices and find the smallest among them.
🔹 Pattern 3: Sum / Aggregation
(Goal: Learn accumulation logic)
21.Find the sum of all elements
→ Add all elements together using a loop.
22.Find the sum of even elements
→ Add only elements whose value is even.
23.Find the sum of odd elements
→ Add only elements whose value is odd.
24.Find the sum of elements at even indices
→ Add elements present at even positions.
25.Find the sum of negative elements
→ Add all elements that are less than zero.
26.Find the product of all elements
→ Multiply all elements together.
27.Find the average of all elements
→ Calculate sum first, then divide by total number of elements.
28.Find the sum of elements divisible by X
→ Add elements that are divisible by a given number X.
29.Find the difference between maximum and minimum
→ Find max and min values, then subtract min from max.
30.Find the sum of digits of all array elements
→ For each number, break it into digits and add them.
🔹 Pattern 4: Counting
(Goal: Learn how to count based on conditions)
31.Count the number of even elements
→ Count how many elements are divisible by 2.
32.Count the number of odd elements
→ Count how many elements are not divisible by 2.
33.Count the number of positive elements
→ Count elements greater than zero.
34.Count the number of negative elements
→ Count elements less than zero.
35.Count the number of zeros
→ Count how many elements are equal to zero.
36.Count elements greater than X
→ Count elements whose value is greater than X.
37.Count elements divisible by X
→ Count elements divisible by a given number.
38.Count prime numbers in the array
→ Check each element and count how many are prime.
39.Count numbers having more than one digit
→ Count numbers whose absolute value is ≥ 10.
40.Count perfect square numbers
→ Count numbers whose square root is an integer.
🔹 Pattern 5: Linear Search
(Goal: Learn searching using traversal)
41.Check whether a given element exists in the array
→ Traverse the array and check if the value appears at least once.
42.Find the frequency of a given element
→ Count how many times a value occurs.
43.Print all indices of a given element
→ Print every index where the element is found.
44.Find the first occurrence of an element
→ Stop traversal once the element is found for the first time.
45.Find the last occurrence of an element
→ Keep updating index whenever the element is found.
46.Check if the array contains only even numbers
→ Verify that no odd number exists in the array.
47.Check if the array contains at least one negative number
→ Stop traversal as soon as a negative value is found.
48.Check whether the array is sorted
→ Ensure every element is less than or equal to the next element.
49.Check if the array contains duplicate elements
→ Detect if any value appears more than once.
50.Find the element with the highest frequency
→ Find which element appears the most times.
🔹 Pattern 6: Index-Based Logic
(Goal: Learn index + value relationship)
51.Replace every element with its index
→ Change each value to its position in the array.
52.Multiply each element by its index
→ Replace each element with (value × index).
53.Find the sum of (index × value)
→ Multiply each element with its index and add the results.
54.Swap every pair of adjacent elements
→ Swap elements at index (0,1), (2,3), etc.
55.Print the middle element(s) of the array
→ Print the center element(s) based on array length.
56.Find elements whose value is equal to their index
→ Print elements where value equals index position.
57.Print elements present at prime indices
→ Print elements whose index is a prime number.
58.Find the maximum difference between index and value
→ Calculate and track the largest difference.
59.Reverse the array using traversal
→ Rearrange elements in reverse order.
60.Rotate the array left by one position
→ Shift elements left and move the first element to the end.
🔹 Pattern 7: Prefix / Running Computation
(Goal: Learn cumulative calculations)
61.Create a prefix sum array
→ Each element stores sum of all previous elements including itself.
62.Find the running sum of the array
→ Print sum after each step of traversal.
63.Find the maximum prefix sum
→ Track the largest prefix sum value.
64.Find the minimum prefix sum
→ Track the smallest prefix sum value.
65.Replace each element with the sum of elements before it
→ Each element becomes sum of previous elements only.
66.Find an equilibrium index
→ Find index where left sum equals right sum.
67.Check if any prefix sum equals suffix sum
→ Verify if array can be split into equal sum parts.
68.Find the longest prefix with positive sum
→ Find how long prefix remains positive.
69.Create a cumulative product array
→ Each element stores product till that position.
70.Replace each element with the maximum element seen so far
→ Keep updating max while traversing.
🔹 Pattern 8: Pair / Nested Traversal
(Goal: Learn nested loops)
71.Find all pairs with a given sum
→ Check every possible pair whose sum equals a target.
72.Count pairs with a given sum
→ Count how many such valid pairs exist.
73.Find all equal element pairs
→ Find pairs where both values are the same.
74.Count duplicate pairs
→ Count pairs that represent duplicates.
75.Find the maximum pair sum
→ Find the pair whose sum is maximum.
76.Find the minimum pair sum
→ Find the pair whose sum is minimum.
77.Find the pair with maximum difference
→ Find pair where difference is highest.
78.Find pairs where both elements are even
→ Check both values are even.
79.Find pairs where both elements are odd
→ Check both values are odd.
80.Find pairs whose product is positive
→ Product should be greater than zero.
🔹 Pattern 9: Frequency / Map Thinking
(Goal: Learn frequency counting)
81.Find the element with the highest frequency
82.Find the element with the lowest frequency
83.Print all unique elements
84.Print all duplicate elements
85.Count distinct elements
86.Find the first repeating element
87.Find the first non-repeating element
88.Remove duplicate elements from the array
89.Check if two arrays are equal
90.Find the intersection of two arrays
(Each problem involves counting how many times elements appear.)
🔹 Pattern 10: Validation / Flag Pattern
(Goal: Learn condition validation)
91.Check whether the array is a palindrome
92.Check if the array is sorted in ascending order
93.Check if the array is sorted in descending order
94.Check if elements alternate between even and odd
95.Check if all elements are unique
96.Check if the array contains consecutive numbers
97.Check whether the sum of elements is even
98.Check if the array contains only 0s and 1s
99.Check if the array contains a majority element
100. Check if the array can be split into two equal-sum parts
🔥 Final Line for the PDF
“Master the pattern, and the problems will solve themselves.”
👨💻 About Me
Hey, I’m Madhu 👋
I love sharing coding knowledge and helping beginners learn programming in a simple
way
🌐 Connect with Me
🔗 GitHub: [Link]/madhu-sudhan-rao
🔗 LinkedIn: [Link]/in/madhu-sudhana-rao
🔗 Instagram: [Link]/[Link]
🔗 YouTube: [Link]/@madhu-sudhan-39
🔗 1:1 Call: [Link]/madhu_sudhan_rao
💌 Email: madhusudhanrao391@[Link]