Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

AP CSA Question of the Day Jan. 29, 2025

Reference
  1. Incorrect Correct No Answer was selected Invalid Answer

    An array of Integers is to be sorted biggest to smallest using the insertion sort method. If the array arr originally contains:
    [1 7 9 5 4 12]
    What will it look like after the third pass of the for loop?

    for (int i = 1; i < arr.length; i++)
    {
            int curNumber = arr[i];
            int curIndex = i-1;
    
            while (curIndex >= 0 && arr[curIndex] < curNumber)
            {
                arr[curIndex+1] = arr[curIndex];
                curIndex--;
            }
    
            arr[curIndex + 1] = curNumber;
    }
    Java