title: How to add, multiply n numbers to a given range in array and also reverse the range in the array in O(n) time?
body: <p>Suppose we have an a array L[]={4,1,2,6}. What we need to do is to take a string S consisting of characters A,R,M as input and apply the following algorithm:</p>
  
  <pre><code>for i from 1 to N do 
  
      if ith letter of S is 'R'
          reverse L[i...N]
      else if ith letter of S is 'A'
          add A to all numbers of L[i..N].
      else if ith letter of S is 'M'
          multiply B to all numbers of L[i..N].
  
      for all number in L[i..N], module them by C.
  print L[i]
  
  end
  </code></pre>
  
  <p>How to optimize this algorithm so that it runs in O(n) time? Length of the array as well as the string is n.
  Anyway, any optimization (like removing the loop for add and multiply only ) in this algorithm will be welcomed.</p>