2020年12月19日星期六

Length of Longest Subarray with all same elements

Given an array that contain n integers.You have to choose any subarray and perform following operation

Reduce an element A[i] by 1 that will cost 1 unit

Your task is determine the longest subarray that contain all equal elements and ensure cost to make subarray is less than or equal to K

Test Cases:

N,K=6,6

A=[1,7,3,4,6,5]

Output :4

My apporach:Using Brute Force Anyone suggest how to do optimal solution



from Recent Questions - Stack Overflow https://stackoverflow.com/questions/65368796/length-of-longest-subarray-with-all-same-elements go_k

没有评论:

发表评论