KEMBAR78
Array Problem Bank | PDF | Algorithms And Data Structures | Applied Mathematics
0% found this document useful (0 votes)
4 views8 pages

Array Problem Bank

Uploaded by

munitarak6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Array Problem Bank

Uploaded by

munitarak6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Array Problems Practice Bank

Problem: Print Elements


Description: Given an array, print all its elements.
Input Format:
First line: n (number of elements)
Second line: n space-separated integers
Output Format:
All elements separated by space
Example Input:
5
12345
Example Output:
12345

Problem: Find Max and Min


Description: Find the maximum and minimum element in an array.
Input Format:
n
n space-separated integers
Output Format:
Two integers: max min
Example Input:
5
10 4 7 2 9
Example Output:
10 2

Problem: Sum of Elements


Description: Calculate the sum of all elements in an array.
Input Format:
n
n space-separated integers
Output Format:
Sum of elements
Example Input:
4
1234
Example Output:
10

Problem: Reverse Array


Description: Reverse the given array in-place.
Input Format:
n
n space-separated integers
Output Format:
Reversed array
Example Input:
5
12345
Example Output:
54321

Problem: Rotate Array Right


Description: Rotate the array k times to the right.
Input Format:
nk
n space-separated integers
Output Format:
Rotated array
Example Input:
52
12345
Example Output:
45123

Problem: Linear Search


Description: Find the index of a target element (or -1 if not found).
Input Format:
n target
n space-separated integers
Output Format:
Index or -1
Example Input:
57
13795
Example Output:
2

Problem: Binary Search


Description: Find the index of a target in sorted array.
Input Format:
n target
n space-separated sorted integers
Output Format:
Index or -1
Example Input:
54
12469
Example Output:
2

Problem: Two Sum


Description: Find indices of two numbers that sum to target.
Input Format:
n target
n space-separated sorted integers
Output Format:
Two indices (0-based)
Example Input:
59
2 3 4 7 11
Example Output:
13
Problem: Move Zeros
Description: Move all zeros to the end while maintaining order.
Input Format:
n
n space-separated integers
Output Format:
Modified array
Example Input:
5
0 1 0 3 12
Example Output:
1 3 12 0 0

Problem: Max Sum Subarray (Fixed)


Description: Find max sum of any subarray of size k.
Input Format:
nk
n space-separated integers
Output Format:
Max sum
Example Input:
53
12345
Example Output:
12

Problem: Longest Subarray Sum <= K


Description: Find length of longest subarray with sum <= k.
Input Format:
nk
n space-separated integers
Output Format:
Length
Example Input:
58
12111
Example Output:
5

Problem: Range Sum Query


Description: Find sum of elements from l to r using prefix sum.
Input Format:
nq
n space-separated integers
q lines: l r
Output Format:
Sum for each query
Example Input:
52
12345
02
13
Example Output:
6
9

Problem: Max Subarray Sum


Description: Find maximum sum of contiguous subarray.
Input Format:
n
n space-separated integers
Output Format:
Max sum
Example Input:
9
-2 1 -3 4 -1 2 1 -5 4
Example Output:
6

Problem: Transpose Matrix


Description: Given matrix m x n, print its transpose.
Input Format:
mn
matrix elements
Output Format:
Transposed matrix
Example Input:
23
123
456
Example Output:
14
25
36

Problem: Rotate Matrix 90 Degrees


Description: Rotate a square matrix by 90 degrees clockwise.
Input Format:
n
matrix elements
Output Format:
Rotated matrix
Example Input:
3
123
456
789
Example Output:
741
852
963

Problem: Next Greater Element


Description: For each element, find the next greater to the right.
Input Format:
n
n space-separated integers
Output Format:
Array of next greater elements (-1 if none)
Example Input:
5
21243
Example Output:
4 2 4 -1 -1

Problem: Largest Rectangle in Histogram


Description: Find area of largest rectangle in histogram.
Input Format:
n
n space-separated heights
Output Format:
Max area
Example Input:
6
215623
Example Output:
10

Problem: Majority Element


Description: Find element appearing more than n/2 times.
Input Format:
n
n space-separated integers
Output Format:
Majority element
Example Input:
5
33423
Example Output:
3
Problem: Missing Number
Description: Find the missing number from 0..n.
Input Format:
n
n distinct numbers from 0..n
Output Format:
Missing number
Example Input:
4
0134
Example Output:
2

You might also like