Cody

# Problem 43072. Check if a rotated array was originally sorted

Solution 1929671

Submitted on 10 Sep 2019 by Nikolaos Nikolaou
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = [4 5 6 7 0 1 2]; y_correct = true; assert(isequal(isRotaSorTED(x),y_correct))

k = 0 x = 2 4 5 6 7 0 1 x = 1 2 4 5 6 7 0 x = 0 1 2 4 5 6 7 k = 1 x = 7 0 1 2 4 5 6 x = 6 7 0 1 2 4 5 x = 5 6 7 0 1 2 4 x = 4 5 6 7 0 1 2 y = 1

2   Pass
x = [2 5 6 8 0 1 3]; y_correct = false; assert(isequal(isRotaSorTED(x),y_correct))

k = 0 x = 3 2 5 6 8 0 1 x = 1 3 2 5 6 8 0 x = 0 1 3 2 5 6 8 x = 8 0 1 3 2 5 6 x = 6 8 0 1 3 2 5 x = 5 6 8 0 1 3 2 x = 2 5 6 8 0 1 3 y = 0

3   Pass
x = [101, 103, 106, 109, 158, 164, 182, 187, 202, 205, 2, 3, 32, 57, 69, 74, 81, 99, 100]; y_correct = true; assert(isequal(isRotaSorTED(x),y_correct))

k = 0 x = 100 101 103 106 109 158 164 182 187 202 205 2 3 32 57 69 74 81 99 x = 99 100 101 103 106 109 158 164 182 187 202 205 2 3 32 57 69 74 81 x = 81 99 100 101 103 106 109 158 164 182 187 202 205 2 3 32 57 69 74 x = 74 81 99 100 101 103 106 109 158 164 182 187 202 205 2 3 32 57 69 x = 69 74 81 99 100 101 103 106 109 158 164 182 187 202 205 2 3 32 57 x = 57 69 74 81 99 100 101 103 106 109 158 164 182 187 202 205 2 3 32 x = 32 57 69 74 81 99 100 101 103 106 109 158 164 182 187 202 205 2 3 x = 3 32 57 69 74 81 99 100 101 103 106 109 158 164 182 187 202 205 2 x = 2 3 32 57 69 74 81 99 100 101 103 106 109 158 164 182 187 202 205 k = 1 x = 205 2 3 32 57 69 74 81 99 100 101 103 106 109 158 164 182 187 202 x = 202 205 2 3 32 57 69 74 81 99 100 101 103 106 109 158 164 182 187 x = 187 202 205 2 3 32 57 69 74 81 99 100 101 103 106 109 158 164 182 x = 182 187 202 205 2 3 32 57 69 74 81 99 100 101 103 106 109 158 164 x = 164 182 187 202 205 2 3 32 57 69 74 81 99 100 101 103 106 109 158 x = 158 164 182 187 202 205 2 3 32 57 69 74 81 99 100 101 103 106 109 x = 109 158 164 182 187 202 205 2 3 32 57 69 74 81 99 100 101 103 106 x = 106 109 158 164 182 187 202 205 2 3 32 57 69 74 81 99 100 101 103 x = 103 106 109 158 164 182 187 202 205 2 3 32 57 69 74 81 99 100 101 x = 101 103 106 109 158 164 182 187 202 205 2 3 32 57 69 74 81 99 100 y = 1

4   Pass
x = [42 1:10]; y_correct = true; assert(isequal(isRotaSorTED(x),y_correct))

k = 0 x = 10 42 1 2 3 4 5 6 7 8 9 x = 9 10 42 1 2 3 4 5 6 7 8 x = 8 9 10 42 1 2 3 4 5 6 7 x = 7 8 9 10 42 1 2 3 4 5 6 x = 6 7 8 9 10 42 1 2 3 4 5 x = 5 6 7 8 9 10 42 1 2 3 4 x = 4 5 6 7 8 9 10 42 1 2 3 x = 3 4 5 6 7 8 9 10 42 1 2 x = 2 3 4 5 6 7 8 9 10 42 1 x = 1 2 3 4 5 6 7 8 9 10 42 k = 1 x = 42 1 2 3 4 5 6 7 8 9 10 y = 1

5   Pass
x = 1:10; x(1) = 100; x(4) = 1; y_correct = false; assert(isequal(isRotaSorTED(x),y_correct))

k = 0 x = 10 100 2 3 1 5 6 7 8 9 x = 9 10 100 2 3 1 5 6 7 8 x = 8 9 10 100 2 3 1 5 6 7 x = 7 8 9 10 100 2 3 1 5 6 x = 6 7 8 9 10 100 2 3 1 5 x = 5 6 7 8 9 10 100 2 3 1 x = 1 5 6 7 8 9 10 100 2 3 x = 3 1 5 6 7 8 9 10 100 2 x = 2 3 1 5 6 7 8 9 10 100 x = 100 2 3 1 5 6 7 8 9 10 y = 0

6   Pass
x = 10:-1:1; y_correct = false; assert(isequal(isRotaSorTED(x),y_correct))

k = 0 x = 1 10 9 8 7 6 5 4 3 2 x = 2 1 10 9 8 7 6 5 4 3 x = 3 2 1 10 9 8 7 6 5 4 x = 4 3 2 1 10 9 8 7 6 5 x = 5 4 3 2 1 10 9 8 7 6 x = 6 5 4 3 2 1 10 9 8 7 x = 7 6 5 4 3 2 1 10 9 8 x = 8 7 6 5 4 3 2 1 10 9 x = 9 8 7 6 5 4 3 2 1 10 x = 10 9 8 7 6 5 4 3 2 1 y = 0