
Implement partition, which rearranges the range a[lo..hi] around the pivot a[hi] following the Lomuto scheme and returns the index the pivot ends up on.
int a[] = {9, 4, 7, 1, 8, 5, 6}; partition(a, 0, 6);Expected result
p=3 a=[4, 1, 5, 6, 8, 7, 9]For your own tracking. Tests grade your code.
int a[] = {5, 2, 5, 9, 5}; partition(a, 0, 4);Expected result
p=3 a=[5, 2, 5, 5, 9]int a[] = {100, 5, 3, 9, 4, 200}; partition(a, 1, 4);Expected result
p=2 a=[100, 3, 4, 9, 5, 200]int a[] = {42}; partition(a, 0, 0);Expected result
p=0 a=[42]Expected files
partition.cAllowed functions
None. Write every helper yourself.
Allowed headers

Implement partition, which rearranges the range a[lo..hi] around the pivot a[hi] following the Lomuto scheme and returns the index the pivot ends up on.
int a[] = {9, 4, 7, 1, 8, 5, 6}; partition(a, 0, 6);Expected result
p=3 a=[4, 1, 5, 6, 8, 7, 9]For your own tracking. Tests grade your code.
int a[] = {5, 2, 5, 9, 5}; partition(a, 0, 4);Expected result
p=3 a=[5, 2, 5, 5, 9]int a[] = {100, 5, 3, 9, 4, 200}; partition(a, 1, 4);Expected result
p=2 a=[100, 3, 4, 9, 5, 200]int a[] = {42}; partition(a, 0, 0);Expected result
p=0 a=[42]Expected files
partition.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.
v0.40: Create exercises. Challenge the community.
Meet Studio →