DSA ARRAY PRACTICE SET:-
Basic Array Operations (Questions 1-3)
Question 1: Find Maximum Element
Problem: Write a C program to find the maximum element in an array.
Expected Input:
Array size: 5
Elements: 12 45 23 67 34
Expected Output:
Maximum element: 67
Question 2: Find Minimum Element
Problem: Write a C program to find the minimum element in an array.
Expected Input:
Array size: 5
Elements: 12 45 23 67 34
Expected Output:
DSA ARRAY PRACTICE SET:- 1
Minimum element: 12
Question 3: Find Both Maximum and Minimum
Problem: Write a C program to find both maximum and minimum elements in an
array in a single traversal.
Expected Input:
Array size: 6
Elements: 8 15 3 9 22 1
Expected Output:
Maximum element: 22
Minimum element: 1
Array Searching (Questions 4-6)
Question 4: Linear Search
Problem: Write a C program to search for an element in an array using linear
search.
Expected Input:
Array size: 6
Elements: 10 20 30 40 50 60
Search element: 30
DSA ARRAY PRACTICE SET:- 2
Expected Output:
Element 30 found at index 2
Question 5: Search Element with Count
Problem: Write a C program to search for an element and count how many times it
appears in the array.
Expected Input:
Array size: 8
Elements: 5 10 5 20 5 30 15 5
Search element: 5
Expected Output:
Element 5 found 4 times
Question 6: Find All Positions of Element
Problem: Write a C program to find and display all positions where a given
element occurs in the array.
Expected Input:
Array size: 7
DSA ARRAY PRACTICE SET:- 3
Elements: 12 34 12 56 12 78 90
Search element: 12
Expected Output:
Element 12 found at positions: 0 2 4
Array Sum Operations (Questions 7-9)
Question 7: Sum of All Elements
Problem: Write a C program to calculate the sum of all elements in an array.
Expected Input:
Array size: 5
Elements: 10 20 30 40 50
Expected Output:
Sum of all elements: 150
Question 8: Sum of Even and Odd Elements
Problem: Write a C program to calculate separate sums of even and odd elements
in an array.
Expected Input:
DSA ARRAY PRACTICE SET:- 4
Array size: 6
Elements: 12 15 24 31 46 53
Expected Output:
Sum of even elements: 82
Sum of odd elements: 99
Question 9: Sum of Elements at Even and Odd Positions
Problem: Write a C program to calculate sum of elements at even positions and
odd positions separately.
Expected Input:
Array size: 6
Elements: 10 15 20 25 30 35
Expected Output:
Sum at even positions (0,2,4): 60
Sum at odd positions (1,3,5): 75
Array Reversal (Questions 10-12)
Question 10: Reverse Array Elements
DSA ARRAY PRACTICE SET:- 5
Problem: Write a C program to reverse the elements of an array.
Expected Input:
Array size: 5
Elements: 1 2 3 4 5
Expected Output:
Original array: 1 2 3 4 5
Reversed array: 5 4 3 2 1
Question 11: Check if Array is Palindrome
Problem: Write a C program to check if an array is a palindrome (reads same
forwards and backwards).
Expected Input:
Array size: 5
Elements: 1 2 3 2 1
Expected Output:
Array is a palindrome
Question 12: Reverse Only Even Elements
DSA ARRAY PRACTICE SET:- 6
Problem: Write a C program to reverse only the even elements in an array while
keeping odd elements in their original positions.
Expected Input:
Array size: 6
Elements: 12 15 24 31 46 53
Expected Output:
Original array: 12 15 24 31 46 53
Modified array: 46 15 24 31 12 53
Array Duplication & Uniqueness (Questions 13-15)
Question 13: Find Duplicate Elements
Problem: Write a C program to find and display all duplicate elements in an array.
Expected Input:
Array size: 8
Elements: 12 45 12 67 45 89 12 23
Expected Output:
Duplicate elements: 12 45
DSA ARRAY PRACTICE SET:- 7
Question 14: Remove Duplicates
Problem: Write a C program to remove duplicate elements from an array and
display the unique array.
Expected Input:
Array size: 7
Elements: 10 20 10 30 20 40 30
Expected Output:
Original array: 10 20 10 30 20 40 30
Array after removing duplicates: 10 20 30 40
New size: 4
Question 15: Count Unique Elements
Problem: Write a C program to count the number of unique elements in an array
and display them.
Expected Input:
Array size: 9
Elements: 5 10 5 15 10 20 15 25 30
Expected Output:
DSA ARRAY PRACTICE SET:- 8
Unique elements: 5 10 15 20 25 30
Total unique elements: 6
Logic Progression Notes:
Questions 1-3: Basic min/max finding logic
Questions 4-6: Element searching with increasing complexity
Questions 7-9: Sum calculations with different conditions
Questions 10-12: Array reversal concepts with variations
Questions 13-15: Duplicate handling and uniqueness concepts
Each group builds upon similar logical foundations, making it easier to understand
and practice related concepts together.
DSA Medium Level Questions Bank
Two Pointers Technique (Questions 1-3)
Question 1: Two Sum Problem
Problem: Given an array of integers and a target sum, find two numbers that add
up to the target.
Expected Input:
Array: [2, 7, 11, 15]
Target: 9
Expected Output:
DSA ARRAY PRACTICE SET:- 9
Indices: [0, 1]
Values: [2, 7]
Time Complexity: O(n)
Space Complexity: O(1) with sorted array
Question 2: Three Sum Problem
Problem: Given an array, find all unique triplets that sum to zero.
Expected Input:
Array: [-1, 0, 1, 2, -1, -4]
Expected Output:
Triplets: [[-1, -1, 2], [-1, 0, 1]]
Time Complexity: O(n²)
Space Complexity: O(1)
Question 3: Four Sum Problem
Problem: Given an array and a target, find all unique quadruplets that sum to the
target.
Expected Input:
DSA ARRAY PRACTICE SET:- 10
Array: [1, 0, -1, 0, -2, 2]
Target: 0
Expected Output:
Quadruplets: [[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]]
Time Complexity: O(n³)
Space Complexity: O(1)
Sliding Window Technique (Questions 4-6)
Question 4: Maximum Sum Subarray of Size K
Problem: Find the maximum sum of a subarray of size k.
Expected Input:
Array: [2, 1, 5, 1, 3, 2]
K: 3
Expected Output:
Maximum sum: 9
Subarray: [5, 1, 3]
Time Complexity: O(n)
Space Complexity: O(1)
Question 5: Longest Substring Without Repeating Characters
DSA ARRAY PRACTICE SET:- 11
Problem: Find the length of the longest substring without repeating characters.
Expected Input:
String: "abcabcbb"
Expected Output:
Length: 3
Substring: "abc"
Time Complexity: O(n)
Space Complexity: O(min(m,n))
Question 6: Minimum Window Substring
Problem: Find the minimum window substring that contains all characters of
pattern string.
Expected Input:
String: "ADOBECODEBANC"
Pattern: "ABC"
Expected Output:
Minimum window: "BANC"
Length: 4
DSA ARRAY PRACTICE SET:- 12
Time Complexity: O(n)
Space Complexity: O(k)
Binary Search Variations (Questions 7-9)
Question 7: Search in Rotated Sorted Array
Problem: Search for a target in a rotated sorted array.
Expected Input:
Array: [4, 5, 6, 7, 0, 1, 2]
Target: 0
Expected Output:
Index: 4
Found: true
Time Complexity: O(log n)
Space Complexity: O(1)
Question 8: Find Peak Element
Problem: Find a peak element in the array (element greater than its neighbors).
Expected Input:
Array: [1, 2, 3, 1]
Expected Output:
DSA ARRAY PRACTICE SET:- 13
Peak index: 2
Peak value: 3
Time Complexity: O(log n)
Space Complexity: O(1)
Question 9: Search in 2D Matrix
Problem: Search for a target in a 2D matrix where each row is sorted and first
element of each row is greater than last element of previous row.
Expected Input:
Matrix: [[1,3,5,7],[10,11,16,20],[23,30,34,60]]
Target: 3
Expected Output:
Found: true
Position: [0, 1]
Time Complexity: O(log(m*n))
Space Complexity: O(1)
Tree Traversal & Properties (Questions 10-12)
Question 10: Binary Tree Level Order Traversal
Problem: Return the level order traversal of a binary tree.
DSA ARRAY PRACTICE SET:- 14
Expected Input:
Tree: 3
/\
9 20
/ \
15 7
Expected Output:
Level order: [[3], [9, 20], [15, 7]]
Time Complexity: O(n)
Space Complexity: O(w) where w is maximum width
Question 11: Binary Tree Zigzag Level Order Traversal
Problem: Return zigzag level order traversal (alternate left-to-right and right-to-
left).
Expected Input:
Tree: 3
/\
9 20
/ \
15 7
Expected Output:
DSA ARRAY PRACTICE SET:- 15
Zigzag order: [[3], [20, 9], [15, 7]]
Time Complexity: O(n)
Space Complexity: O(w)
Question 12: Binary Tree Right Side View
Problem: Return the values of nodes you can see from the right side of a binary
tree.
Expected Input:
Tree: 1
/\
2 3
\ \
5 4
Expected Output:
Right side view: [1, 3, 4]
Time Complexity: O(n)
Space Complexity: O(h) where h is height
Dynamic Programming Patterns (Questions 13-15)
Question 13: Longest Increasing Subsequence
Problem: Find the length of the longest increasing subsequence.
DSA ARRAY PRACTICE SET:- 16
Expected Input:
Array: [10, 9, 2, 5, 3, 7, 101, 18]
Expected Output:
Length: 4
LIS: [2, 3, 7, 18] (one possible)
Time Complexity: O(n log n)
Space Complexity: O(n)
Question 14: Longest Common Subsequence
Problem: Find the length of longest common subsequence between two strings.
Expected Input:
String1: "abcde"
String2: "ace"
Expected Output:
Length: 3
LCS: "ace"
Time Complexity: O(mn)Space Complexity: O(mn)
DSA ARRAY PRACTICE SET:- 17
Question 15: Maximum Sum Increasing Subsequence
Problem: Find the maximum sum of an increasing subsequence.
Expected Input:
Array: [1, 101, 2, 3, 100, 4, 5]
Expected Output:
Maximum sum: 106
Subsequence: [1, 2, 3, 100] (one possible)
Time Complexity: O(n²)
Space Complexity: O(n)
Logic Progression Notes:
Questions 1-3: Two pointers technique with increasing complexity (2-sum →
3-sum → 4-sum)
Questions 4-6: Sliding window approach from fixed size to variable size
problems
Questions 7-9: Binary search variations in different scenarios
Questions 10-12: Tree traversal techniques with level-order variations
Questions 13-15: DP patterns focusing on subsequence problems
Each group follows the same algorithmic approach but with increasing difficulty
and slight variations in implementation.
DSA ARRAY PRACTICE SET:- 18