0% found this document useful (0 votes)
13 views5 pages

Essential Array Operations and Challenges

The document lists various programming challenges categorized by difficulty levels: Easy, Medium, and Hard. Each challenge includes a description, input example, expected output, and a test case. The challenges cover a range of topics including array manipulation, searching, and mathematical computations.

Uploaded by

pandeyarpit1707
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)
13 views5 pages

Essential Array Operations and Challenges

The document lists various programming challenges categorized by difficulty levels: Easy, Medium, and Hard. Each challenge includes a description, input example, expected output, and a test case. The challenges cover a range of topics including array manipulation, searching, and mathematical computations.

Uploaded by

pandeyarpit1707
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

Easy Level

1. Find the Largest Element in an Array


• Description: Given an array, find the largest element.
• Input: [1, 3, 7, 0, 5]
• Output: 7
• Test Case:
• Input: [10, 15, 2, 3], Output: 15
2. Find the Smallest Element in an Array
• Description: Given an array, find the smallest element.
• Input: [4, 6, 1, 9, 2]
• Output: 1
• Test Case:
• Input: [7, 5, 8, 6], Output: 5
3. Sum of All Elements
• Description: Find the sum of all elements in an array.
• Input: [1, 2, 3, 4]
• Output: 10
• Test Case:
• Input: [10, 20, 30], Output: 60
4. Find the Second Largest Element
• Description: Given an array, find the second largest element.
• Input: [5, 2, 9, 3, 6]
• Output: 6
• Test Case:
• Input: [7, 7, 7, 5], Output: 5
5. Reverse an Array
• Description: Reverse the given array.
• Input: [1, 2, 3, 4]
• Output: [4, 3, 2, 1]
• Test Case:
• Input: [9, 7, 5], Output: [5, 7, 9]
6. Count Occurrences of an Element
• Description: Count how many times an element occurs in the array.
• Input: [2, 3, 2, 3, 2], target = 2
• Output: 3
• Test Case:
• Input: [1, 2, 3, 4, 4], target = 4, Output: 2
7. Check if Array is Sorted
• Description: Determine if the array is sorted in ascending order.
• Input: [1, 2, 3, 4]
• Output: True
• Test Case:
• Input: [3, 2, 1], Output: False
8. Remove Duplicates from Array
• Description: Remove all duplicate elements from the array.
• Input: [1, 1, 2, 3, 3]
• Output: [1, 2, 3]
• Test Case:
• Input: [4, 5, 4, 6, 5], Output: [4, 5, 6]
9. Find the Maximum and Minimum in an Array
•Description: Return the maximum and minimum element from an array.
•Input: [3, 5, 7, 2, 8]
•Output: Max: 8, Min: 2
•Test Case:
• Input: [10, 100, 20], Output: Max: 100, Min: 10
[Link] Two Sorted Arrays
• Description: Merge two sorted arrays into one sorted array.
• Input: [1, 3, 5], [2, 4, 6]
• Output: [1, 2, 3, 4, 5, 6]
• Test Case:
• Input: [0, 2, 4], [1, 3, 5], Output: [0, 1, 2, 3, 4, 5]

Medium Level
[Link] All Zeros to End
• Description: Move all zeroes in the array to the end.
• Input: [0, 1, 0, 3, 12]
• Output: [1, 3, 12, 0, 0]
• Test Case:
• Input: [0, 0, 1, 2, 0], Output: [1, 2, 0, 0, 0]
[Link] an Array by K Positions
• Description: Rotate an array to the right by k steps.
• Input: [1, 2, 3, 4, 5, 6, 7], k = 3
• Output: [5, 6, 7, 1, 2, 3, 4]
• Test Case:
• Input: [1, 2, 3], k = 2, Output: [2, 3, 1]
[Link] Missing Number in an Array
• Description: Find the missing number in an array of size n with elements from 1 to
n.
• Input: [1, 2, 4, 5]
• Output: 3
• Test Case:
• Input: [1, 3, 4], Output: 2
[Link] the Intersection of Two Arrays
• Description: Find the intersection of two arrays.
• Input: [1, 2, 2, 1], [2, 2]
• Output: [2, 2]
• Test Case:
• Input: [4, 9, 5], [9, 4, 9, 8, 4], Output: [4, 9]
[Link] the Subarray with Maximum Sum (Kadane's Algorithm)
• Description: Find the contiguous subarray with the maximum sum.
• Input: [-2, 1, -3, 4, -1, 2, 1, -5, 4]
• Output: 6 (subarray [4, -1, 2, 1])
• Test Case:
• Input: [1, 2, 3, 4, -10], Output: 10
[Link] All Pairs with a Given Sum
• Description: Find all pairs in an array that add up to a target sum.
• Input: [1, 2, 3, 4, 5], target = 5
• Output: [(1, 4), (2, 3)]
• Test Case:
• Input: [2, 4, 3, 5, 7], target = 9, Output: [(2, 7), (4, 5)]
[Link] the Longest Increasing Subsequence
• Description: Find the length of the longest increasing subsequence.
• Input: [10, 9, 2, 5, 3, 7, 101, 18]
• Output: 4 (subsequence [2, 3, 7, 101])
• Test Case:
• Input: [0, 1, 0, 3, 2, 3], Output: 4
[Link] Duplicates in an Array
• Description: Find all duplicates in an array where elements are between 1 and n.
• Input: [4, 3, 2, 7, 8, 2, 3, 1]
• Output: [2, 3]
• Test Case:
• Input: [1, 1, 2], Output: [1]
[Link] Majority Element
• Description: Find the element that appears more than n/2 times.
• Input: [3, 2, 3]
• Output: 3
• Test Case:
• Input: [2, 2, 1, 1, 1, 2, 2], Output: 2
[Link] the Union of Two Arrays
• Description: Return the union of two arrays.
• Input: [1, 2, 2, 3], [2, 3, 4]
• Output: [1, 2, 3, 4]
• Test Case:
• Input: [7, 8, 9], [9, 10], Output: [7, 8, 9, 10]
Hard Level
[Link] Product Subarray
• Description: Find the subarray with the maximum product.
• Input: [2, 3, -2, 4]
• Output: 6
• Test Case:
• Input: [-2, 0, -1], Output: 0
[Link] Rain Water
• Description: Given n non-negative integers representing the height of bars, find how
much water it can trap.
• Input: [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
• Output: 6
• Test Case:
• Input: [4, 2, 0, 3, 2, 5], Output: 9
[Link] the Minimum in a Rotated Sorted Array
• Description: Find the minimum element in a rotated sorted array.
• Input: [3, 4, 5, 1, 2]
• Output: 1
• Test Case:
• Input: [4, 5, 6, 7, 0, 1, 2], Output: 0
[Link] the Longest Consecutive Sequence
• Description: Find the length of the longest consecutive elements sequence.
• Input: [100, 4, 200, 1, 3, 2]
• Output: 4 (sequence [1, 2, 3, 4])
• Test Case:
• Input: [0, 3, 7, 2, 5, 8, 4, 6, 0, 1], Output: 9
[Link] Sum Equals K
• Description: Find the number of continuous subarrays that sum to k.
• Input: [1, 1, 1], k = 2
• Output: 2
• Test Case:
• Input: [1, 2, 3], k = 3, Output: 2
[Link] Subarray with Sum Divisible by K
• Description: Find the length of the longest subarray with sum divisible by k.
• Input: [2, 7, 6, 1, 4, 5], k = 3
• Output: 4
• Test Case:
• Input: [4, 5, 0, -2, -3, 1], k = 5, Output: 5
[Link] Inversions in an Array
• Description: Find how many inversions are needed to sort the array.
• Input: [8, 4, 2, 1]
• Output: 6
• Test Case:
• Input: [3, 1, 2], Output: 2
[Link] Minimum Jumps to Reach End of Array
• Description: Given an array where each element represents the max jump length,
find the minimum number of jumps to reach the end.
• Input: [2, 3, 1, 1, 4]
• Output: 2
• Test Case:
• Input: [1, 1, 1, 1], Output: 3
[Link] Largest Element in an Array
•Description: Find the kth largest element in an unsorted array.
•Input: [3, 2, 1, 5, 6, 4], k = 2
•Output: 5
•Test Case:
• Input: [7, 10, 4, 3, 20, 15], k = 4, Output: 7
[Link] of Two Sorted Arrays
• Description: Given two sorted arrays, find the median.
• Input: [1, 3], [2]
• Output: 2.0
• Test Case:
• Input: [1, 2], [3, 4], Output: 2.5
[Link] Subarrays with Equal 0s and 1s
• Description: Find the number of subarrays with an equal number of 0s and 1s.
• Input: [0, 0, 1, 0, 1, 1]
• Output: 4
• Test Case:
• Input: [0, 1, 0], Output: 2

You might also like