Is there a more optimized solution to solve the stated problem?
Given an array 'arr' of 'N' elements and a number 'M', find the least index 'z' at which the equation gets satisfied. [ ] is considered as floor().
counts=0 ans=0 while(ans==0): s=0 for i in range(counts,len(arr)): s+=int(arr[i]/(i+1-counts)) if(s>M): break if((i+1)==len(arr) and s<=M): print(counts) ans=1 counts+=1
Check array from left to right. The first index that satisfies the condition is the answer. This is more optimized than considering from right to left.
If at any time during the calculation, 's' is deemed more than M, break the loop and consider the next. This is more optimized than calculating 's' completely.
arr=[1 2 3]
This would give the answer 0 since the 0th index contains the first element to satisfy the given relation.
Thanks in advance.