Question: One more problem Given an array A of N elements. Find the smallest length of a subarray starting from index / such that the sum

One more problem
Given an array A of N elements. Find the smallest length of a subarray
starting from index/such that the sum of that subarray is positive for
each index /from 1 to N. If there is no such subarray, then the length is
considered to be 0.
Function description
Complete the solve function. This function takes the following 2
parameters:
N : Represents the number of elements
A: Represents the elements of the array
Input format for custom testing
Note: Use this input format if you are testing against custom input or
writing code in a language where we don't provide boilerplate code.
The first line of the indut contains one interiar Nl clanntine the
Output format
Print N space-separated integers, thi integer denoting the smallest lengths
of subarray starting from / with positive sum.
Constraints
1N105
-109Ai109AAiin[1,N]
Sample input
Sample output
3
-592
2+1
Explanation
Given:
N=3
A=[-5,9,2]
Approach:
For index t, the subarray is -5,9 with length 2.
For index 2, the subarray is 9 with length 1.
For index 3, the subarray is 2 with length 1.
So, answer =[2,1,1].
Note:
Your code must be able to print the sample output from the provided samplesinput.
However, your code is run against multiple hidden test cases. Therefore, your code
must pass these hidden test cases to solve the problem statement.
Limits
Time Limit: 1.0sec(s) for each input file
Memory Limit: 256 MB
Source Limit: 1024 KB
Scoring
One more problem Given an array A of N elements.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!