FY-PSAP LAB EXAM AY:2024-25 SEM-I
A01
Problem: Given an array of integers, find the maximum element.
Input Format:
First line: Integer n (size of the array).
Second line: n space-separated integers
(elements of the array).
Output Format:
Single integer representing the maximum
element.
Test Case:
Input:
5
13705
Output:
7
A03
Problem: Count how many even and odd numbers are present in an array.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
Two integers: count of even numbers and count of odd numbers.
Test Case:
Input:
6
123456
Output:
33
A04
Problem: Find the second largest element in an array.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
Single integer representing the second largest element.
Test Case:
Input:
5
10 20 20 30 40
Output:30
, FY-PSAP LAB EXAM AY:2024-25 SEM-I
A05
Problem: Reverse the elements of an array.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
A single line with n space-separated integers in reversed order
Test Case:
Input:
5
12345
Output:
54321
A06
Problem: Rotate the elements of an array to the left by k positions.
Input Format:
First line: Integers n (size of the array) and k
(number of positions to rotate).
Second line: n space-separated integers.
Output Format:
A single line with n space-separated integers after
rotation.
Test Case:
Input:
62
123456
Output:
345612
A07
Problem: Find all unique elements in an array.
A08
, FY-PSAP LAB EXAM AY:2024-25 SEM-I
Given an array of size n-1 containing integers from 1 to n with one number missing, find the
missing number.
Input Format:
First line: Integer n.
Second line: n-1 space-separated integers.
Output Format:
Single integer representing the missing number.
Test Case:
Input:
5
1245
Output:
3
A09
Problem: Find the element that appears more than n/2 times in an array. If no such element
exists, output -1.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
Single integer representing the majority element
or -1 if no majority element exists.
Test Case:
Input:
6
334233
Output:
3
A10
Problem: Given an array of integers, find the minimum element.
A11
Problem: Find the index of a given target element in an array. If the element is not found, output -1.
, FY-PSAP LAB EXAM AY:2024-25 SEM-I
A12
Problem: Find all elements common in two arrays.
A15
Problem: A peak element is an element that is greater than its neighbors. Find any one peak
element in the array.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
Single integer representing the peak element.
Test Case:
Input:
5
1 3 20 4 1
Output:
20
A16
Problem: Write a program to find the transpose of a given matrix.
A17
Problem: Write a program to calculate the sum of each row and each column of a given matrix.
Input Format:
First line: Two integers n and m (dimensions of the matrix).
Next n lines: m space-separated integers (matrix elements).
Output Format:
First line: Row sums as space-separated integers.
Second line: Column sums as space-separated
integers.
Test Case:
Input:
23
123
456
Output:
6 15
579
A01
Problem: Given an array of integers, find the maximum element.
Input Format:
First line: Integer n (size of the array).
Second line: n space-separated integers
(elements of the array).
Output Format:
Single integer representing the maximum
element.
Test Case:
Input:
5
13705
Output:
7
A03
Problem: Count how many even and odd numbers are present in an array.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
Two integers: count of even numbers and count of odd numbers.
Test Case:
Input:
6
123456
Output:
33
A04
Problem: Find the second largest element in an array.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
Single integer representing the second largest element.
Test Case:
Input:
5
10 20 20 30 40
Output:30
, FY-PSAP LAB EXAM AY:2024-25 SEM-I
A05
Problem: Reverse the elements of an array.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
A single line with n space-separated integers in reversed order
Test Case:
Input:
5
12345
Output:
54321
A06
Problem: Rotate the elements of an array to the left by k positions.
Input Format:
First line: Integers n (size of the array) and k
(number of positions to rotate).
Second line: n space-separated integers.
Output Format:
A single line with n space-separated integers after
rotation.
Test Case:
Input:
62
123456
Output:
345612
A07
Problem: Find all unique elements in an array.
A08
, FY-PSAP LAB EXAM AY:2024-25 SEM-I
Given an array of size n-1 containing integers from 1 to n with one number missing, find the
missing number.
Input Format:
First line: Integer n.
Second line: n-1 space-separated integers.
Output Format:
Single integer representing the missing number.
Test Case:
Input:
5
1245
Output:
3
A09
Problem: Find the element that appears more than n/2 times in an array. If no such element
exists, output -1.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
Single integer representing the majority element
or -1 if no majority element exists.
Test Case:
Input:
6
334233
Output:
3
A10
Problem: Given an array of integers, find the minimum element.
A11
Problem: Find the index of a given target element in an array. If the element is not found, output -1.
, FY-PSAP LAB EXAM AY:2024-25 SEM-I
A12
Problem: Find all elements common in two arrays.
A15
Problem: A peak element is an element that is greater than its neighbors. Find any one peak
element in the array.
Input Format:
First line: Integer n.
Second line: n space-separated integers.
Output Format:
Single integer representing the peak element.
Test Case:
Input:
5
1 3 20 4 1
Output:
20
A16
Problem: Write a program to find the transpose of a given matrix.
A17
Problem: Write a program to calculate the sum of each row and each column of a given matrix.
Input Format:
First line: Two integers n and m (dimensions of the matrix).
Next n lines: m space-separated integers (matrix elements).
Output Format:
First line: Row sums as space-separated integers.
Second line: Column sums as space-separated
integers.
Test Case:
Input:
23
123
456
Output:
6 15
579