Problem 1:: Trapping Rain Water Hard 33.14% 467K+ 8 20m Arr Examples: Input: Output: Explanation
Problem 1:: Trapping Rain Water Hard 33.14% 467K+ 8 20m Arr Examples: Input: Output: Explanation
Output:
Problem 2:
Maximum Sub Array
Difficulty: MediumAccuracy: 15.84%Submissions: 96K+Points: 4
Given an array of integers, find the contiguous subarray with the maximum sum that contains only non-
negative numbers. If multiple subarrays have the same sum, return the one with the smallest starting
index.
A subarray is a contiguous non-empty sequence of elements within an array.
Examples:
Input: arr[] = [1, 2, 3]
Output: [1, 2, 3]
Explanation: In the given array, every element is non-negative, so the entire array [1, 2, 3] is the valid
subarray with the maximum sum.
Input: arr[] = [-1, 2]
Output: 2
Explanation: The only valid non-negative subarray is [2], so the output is [2].
Program:
class Solution {
public ArrayList<Integer> findSubarray(int arr[]) {
ArrayList<Integer> maxSubarray = new ArrayList<>(), temp = new ArrayList<>();
long maxSum = -1, tempSum = 0;
Output: