Problem 121 - Insertion Sort

Back to General discussions forum

omsarmiento1953     2023-02-27 20:52:42

input data: 4 3 1 2 5

answer: 1 1 0

I have an idea how the algorithm works, but I don't know what the answers 1 1 0 mean.

gardengnome     2023-02-27 22:34:51
User avatar
3            (start)

_ 3          1 element shifted
1 3

1 _ 3        1 element shifted
1 2 3

1 2 3 _      0 element shifted
1 2 3 5
omsarmiento1953     2023-02-28 02:01:07

What happened to the 4?

zelevin     2023-02-28 02:05:51

Four is the number of the elements in the list. As the problem says:

Input data will contain N - the size of array - in the first line. Next line will contain the array itself (all elements will be different).
gardengnome     2023-02-28 04:56:40
User avatar

Formatting is important. Not

input data: 4 3 1 2 5

but:

input data:
4
3 1 2 5
Please login and solve 5 problems to be able to post at forum