
Sort a in place with selection sort and return the exact number of comparisons between array elements that the sort performed.
sort_cost(a, 5) with a = {3, -1, 7, 0, -4}Expected result
cost=10 [-4, -1, 0, 3, 7]For your own tracking. Tests grade your code.
sort_cost(a, 8) with a = {8, 7, 6, 5, 4, 3, 2, 1}Expected result
cost=28 [1, 2, 3, 4, 5, 6, 7, 8]sort_cost(a, 0) with a = {5, 3}Expected result
cost=0 [5, 3]sort_cost(a, 100) with a filled by the harnessExpected result
cost=4950 first=679 last=63337 sum=3246985 sorted=yessort_cost at n = 10, 100, 1000, 10000Expected result
n=10 cost=45
n=100 cost=4950
n=1000 cost=499500
n=10000 cost=49995000Expected files
sort_cost.cAllowed functions
None. Write every helper yourself.
Allowed headers

v0.40: Create exercises. Challenge the community.
Meet Studio →Sort a in place with selection sort and return the exact number of comparisons between array elements that the sort performed.
sort_cost(a, 5) with a = {3, -1, 7, 0, -4}Expected result
cost=10 [-4, -1, 0, 3, 7]For your own tracking. Tests grade your code.
sort_cost(a, 8) with a = {8, 7, 6, 5, 4, 3, 2, 1}Expected result
cost=28 [1, 2, 3, 4, 5, 6, 7, 8]sort_cost(a, 0) with a = {5, 3}Expected result
cost=0 [5, 3]sort_cost(a, 100) with a filled by the harnessExpected result
cost=4950 first=679 last=63337 sum=3246985 sorted=yessort_cost at n = 10, 100, 1000, 10000Expected result
n=10 cost=45
n=100 cost=4950
n=1000 cost=499500
n=10000 cost=49995000Expected files
sort_cost.cAllowed functions
None. Write every helper yourself.
Allowed headers

Run the tests to grade your code
Build your code, then check each test here. Open a result to inspect its output.