News for hackers. Stuff that matters.
Re:Array Iteration Interview Problem by robomartin on Wednesday August 01, 2012 @11:03PM (#4327004)
OK, here's a C version. Had to add a parameter, of course:

  void add1(int arr[], int length, int val, int n)
  {
    int direction  = n >= 0;
    int counter    = n == 0 ? length : abs(n);
    int index;
    
    for(int i = 0; (i < length) && (counter != 0) ; i++)
    {
      index = direction ? i : length - i;
      if(arr[index] == val)
      {
        arr[index]++;
        counter--;
      }
    }
  }
Verified with test vectors.

There are no comments on this comment yet.