News for hackers. Stuff that matters.
Re:Array Iteration Interview Problem by jkbr on Wednesday August 01, 2012 @09:58PM (#4326816)
My Python version (in-place, no reverse):

    def add1(arr, val, n):
        todo = abs(n) or len(arr)
        seq = xrange(0, len(arr), 1) if n >= 0 else xrange(len(arr) - 1, 0, -1)
        for i in seq:
            if arr[i] == val:
                arr[i] += 1
                todo -= 1
                if not todo:
                    break
        return arr

There are no comments on this comment yet.