an HCL GUVI product

21. Trapping Rain Water

Required Input:

arr = [0,1,0,2,1,0,1,3,2,1,2,1]

Expected Output:

6

Code In Python

def trap_rain_water(arr): # Write your logic here pass # Prefilled input arr = [0,1,0,2,1,0,1,3,2,1,2,1] print(trap_rain_water(arr))

Run Code?

Click Run Button to view compiled output

22. Find the Shortest Unsorted Subarray

Required Input:

arr = [2, 6, 4, 8, 10, 9, 15]

Expected Output:

[6, 4, 8, 10, 9]

Code In Python

def shortest_unsorted_subarray(arr): # Write your logic here pass # Prefilled input arr = [2, 6, 4, 8, 10, 9, 15] print(shortest_unsorted_subarray(arr))

Run Code?

Click Run Button to view compiled output

23. Remove Duplicates from a Sorted Array

Required Input:

arr = [1, 1, 2, 2, 3]

Expected Output:

[1, 2, 3]

Code In Python

def remove_duplicates(arr): # Write your logic here pass # Prefilled input arr = [1, 1, 2, 2, 3] print(remove_duplicates(arr))

Run Code?

Click Run Button to view compiled output

24. Merge Two Sorted Arrays Without Extra Space

Required Input:

arr1 = [1, 3, 5], arr2 = [2, 4, 6]

Expected Output:

[1, 2, 3]
[4, 5, 6]

Code In Python

def merge_sorted_arrays(arr1, arr2): # Write your logic here pass # Prefilled input arr1 = [1, 3, 5] arr2 = [2, 4, 6] merge_sorted_arrays(arr1, arr2) print(arr1) print(arr2)

Run Code?

Click Run Button to view compiled output

25. Maximize Number of Pairs with Sum Less Than K

Required Input:

arr = [1, 2, 3, 4, 5], k = 8

Expected Output:

2

Code In Python

def max_pairs_less_than_k(arr, k): # Write your logic here pass # Prefilled input arr = [1, 2, 3, 4, 5] k = 8 print(max_pairs_less_than_k(arr, k))

Run Code?

Click Run Button to view compiled output

26. Find Longest Even-Length Subarray with Equal Sum Halves

Required Input:

arr = [2, 3, 5, 1, 2, 2]

Expected Output:

2

Code In Python

def longest_even_length_subarray(arr): # Write your logic here pass # Prefilled input arr = [2, 3, 5, 1, 2, 2] print(longest_even_length_subarray(arr))

Run Code?

Click Run Button to view compiled output

27. Minimum Absolute Difference in a Sorted Array

Required Input:

arr = [1, 3, 8, 15, 18]

Expected Output:

2

Code In Python

def min_absolute_difference(arr): # Write your logic here pass # Prefilled input arr = [1, 3, 8, 15, 18] print(min_absolute_difference(arr))

Run Code?

Click Run Button to view compiled output

28. Move Zeros to the End

Required Input:

arr = [0, 1, 0, 3, 12]

Expected Output:

[1, 3, 12, 0, 0]

Code In Python

def move_zeros(arr): # Write your logic here pass # Prefilled input arr = [0, 1, 0, 3, 12] print(move_zeros(arr))

Run Code?

Click Run Button to view compiled output

29. Count Occurrences of Target Sum Using Two Pointers

Required Input:

arr = [1, 2, 3, 4, 5, 6], target = 7

Expected Output:

3

Code In Python

def count_target_sum_pairs(arr, target): # Write your logic here pass # Prefilled input arr = [1, 2, 3, 4, 5, 6] target = 7 print(count_target_sum_pairs(arr, target))

Run Code?

Click Run Button to view compiled output

30. Shortest Subarray with Sum Greater Than Target

Required Input:

arr = [2, 3, 1, 2, 4, 3], target = 7

Expected Output:

2

Code In Python

def shortest_subarray_sum_greater_than_target(arr, target): # Write your logic here pass # Prefilled input arr = [2, 3, 1, 2, 4, 3] target = 7 print(shortest_subarray_sum_greater_than_target(arr, target))

Run Code?

Click Run Button to view compiled output

3 of 3