title: Hackerrank The subarray sums question - time out test cases
body: <p>Here is one question from hackerrank, I have a solution but there is some testcase failed because time limit exceeded. I don't know the better solution for it.</p>
  <p>Find Sum of elements in a subarray (if in subarray has 0, sum = sum + number x)</p>
  <p>input:
  numbers: main array(1-indexed)</p>
  <p>queries:</p>
  <pre><code>   array of query: left index, right index, number x(0-indexed)
  </code></pre>
  <p>output:</p>
  <p>array of sum corresponding with queries.</p>
  <p>my solution on C++ code:</p>
  <pre><code>vector&lt;long&gt; findSum(vector&lt;int&gt;numbers, vector&lt;vector&lt;int&gt;&gt; queries)
  {
     vector&lt;long&gt;result;
     long sum = 0;
     int count = 0;
     for(auto i : queries)
     {
        sum = 0;
        count = 0;
        int l = i[0] - 1;
        int r = i[1]-1;
        int x = i[2];
        for(int j =l; j&lt;r;j++)
        {
           sum+=numbers[j]==0?x:numbers[j]; 
        }
        result.push_back(sum);
     }
     return result;
  }
  </code></pre>