Question: Moderate - 9 8 0 8 0 . Average time to solve is 3 0 m ( c ) Contributed by Amit 3 8 6

Moderate -98080. Average time to solve is 30m
(c)
Contributed by Amit
386 upvates
Asked in companies
Problem statement
Send feedback
Ninja and his friend are playing a game of subarrays. They have an array 'NUMS' of length 'N': Ninja's friend gives him an arbitrary integer 'K' and asks him to find the length of the longest subarray in which the sum of elements is equal to K :
Ninjas asks for your help to win this game Find the length of the longest subarray in which the sum of elements is equal to K.
If there is no subarray whosesum is 'K : then you should return 0.
Example:
input: N'=5,*K'=4,NUMS=[1,2,1,0,1]
Output: 4
There are two subarrays with 5 um =4,[1,2,1] and 2,1,0,4 Hence the fength of the longest subarray with sum =4 is 4
 Moderate -98080. Average time to solve is 30m (c) Contributed by

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 Databases Questions!