Given a sorted input list [1,2,4,5] and the element to be inserted, i.e. 6. The list has four elements, namely 1, 2, 4 and 5, all of which are smaller than input element 6. The position in the list where the input element 6 can be inserted to keep the resulting list sorted is at the end of the list. The output is position 4. Given a sorted input list [1,2,4,5] and the element to be inserted, i.e. 3. The list has four elements, namely 1, 2, 4 and 5. The first and the second elements are smaller than the input element 3. The third and fourth elements are greater than 3. The position in the list where the input element 3 can be inserted to keep the resulting list sorted is between the second and the third element. The output is position 2. Given a sorted input list [1,2,4,5] and the element to be inserted, i.e. 0. The list has four elements, namely 1, 2, 4 and 5, all of which are greater than input element 0. The position in the list where the input element 0 can be inserted to keep the resulting list sorted is at the beginning of the list. The output is position 0.
[[1,2,4,5], 6] [[1,2,4,5], 3] [[1,2,4,5],0]
4 2 0