0% found this document useful (0 votes)
39 views2 pages

Array Problems Practice

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)
39 views2 pages

Array Problems Practice

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/ 2

Array Problems - From Basic to Advanced

1. Reverse an Array
Description: Given an array, reverse it without using extra space.
Input: arr = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]

2. Find Maximum and Minimum in Array


Description: Find the largest and smallest elements in the array.
Input: arr = [10, 4, 7, 2, 9]
Output: Max = 10, Min = 2

3. Two Sum Problem (Two Pointer)


Description: Find indices of two numbers in a sorted array such that they add up to a target.
Input: arr = [2, 3, 4, 7, 11], target = 9
Output: [1, 3] (2 + 7 = 9)

4. Move Zeroes to End


Description: Move all zeroes in the array to the end while maintaining the order of other elements.
Input: arr = [0, 1, 0, 3, 12]
Output: [1, 3, 12, 0, 0]

5. Merge Two Sorted Arrays


Description: Merge two sorted arrays into one sorted array without using extra space.
Input: arr1 = [1, 3, 5], arr2 = [2, 4, 6]
Output: [1, 2, 3, 4, 5, 6]

6. Find Missing Number


Description: Find the missing number in an array containing numbers from 1 to n.
Input: arr = [1, 2, 4, 5], n = 5
Output: 3

7. Subarray with Given Sum


Description: Find a continuous subarray that adds to a given sum.
Input: arr = [1, 4, 20, 3, 10, 5], sum = 33
Output: Subarray [20, 3, 10]

8. Trapping Rain Water (Two Pointer)


Description: Given elevation heights, compute how much water can be trapped after raining.
Input: arr = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
Output: 6

9. Kadane's Algorithm
Description: Find the maximum sum subarray in the given array.
Input: arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6 (Subarray: [4, -1, 2, 1])

10. Longest Consecutive Sequence


Description: Find the length of the longest consecutive elements sequence.
Input: arr = [100, 4, 200, 1, 3, 2]
Output: 4 (Sequence: 1, 2, 3, 4)

11. 3Sum Problem


Description: Find all unique triplets in the array which gives the sum of zero.
Input: arr = [-1, 0, 1, 2, -1, -4]
Output: [[-1, -1, 2], [-1, 0, 1]]

12. Maximum Product Subarray


Description: Find the contiguous subarray within an array which has the largest product.
Input: arr = [2, 3, -2, 4]
Output: 6 (Subarray: [2, 3])

13. Rotate Array


Description: Rotate the array to the right by k steps.
Input: arr = [1, 2, 3, 4, 5, 6, 7], k = 3
Output: [5, 6, 7, 1, 2, 3, 4]

14. Find Duplicate Number


Description: Find the duplicate number in an array of n+1 integers where each integer is between 1
and n.
Input: arr = [3, 1, 3, 4, 2]
Output: 3

15. Sliding Window Maximum


Description: Given an array and window size k, find the maximum in each sliding window.
Input: arr = [1,3,-1,-3,5,3,6,7], k = 3
Output: [3, 3, 5, 5, 6, 7]

You might also like