title: Faster Algorithm to Tailor Given Mathematical Expression
body: <p>Is there a more optimized solution to solve the stated problem?</p>
  
  <p>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().</p>
  
  <p><a href="https://i.stack.imgur.com/bDdJJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bDdJJ.png" alt="enter image description here"></a></p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>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&gt;M):
              break
      if((i+1)==len(arr) and s&lt;=M):
          print(counts)
          ans=1
      counts+=1
  </code></pre>
  
  <p><strong>Explanation:</strong></p>
  
  <ol>
  <li><p>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.</p></li>
  <li><p>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.</p></li>
  </ol>
  
  <p><strong>Example:</strong></p>
  
  <p><strong>INPUT:</strong></p>
  
  <p>N=3 M=3</p>
  
  <p>arr=[1 2 3]</p>
  
  <p><strong>OUTPUT:</strong></p>
  
  <p>0</p>
  
  <p>This would give the answer 0 since the 0th index contains the first element to satisfy the given relation.</p>
  
  <p>Thanks in advance.</p>