Write a method, isCircleSorted(int[] A) (Java, JavaScript), or Array#circularly_sorted? (Ruby) that determines if A is circularly sorted. An Array is circularly sorted if the elements are sorted in ascending order, but displaced, or rotated, by any number of steps.
For Example:
// True:
isCircleSorted([2,3,4,5,0,1]);
isCircleSorted([4,5,6,9,1]);
isCircleSorted([10,11,6,7,9]);
isCircleSorted([1,2,3,4,5]);
isCircleSorted([5,7,43,987,-9,0]);
// False:
isCircleSorted([4,1,2,5]);
isCircleSorted([8,7,6,5,4,3]);
isCircleSorted([6,7,4,8]);
isCircleSorted([7,6,5,4,3,2,1]);
'매일매일개발 > Codewars' 카테고리의 다른 글
codewars #87 Extract the IDs from the data set (6kyu) (0) | 2018.07.27 |
---|---|
codewars #86 Remove Duplicates(7kyu) (0) | 2018.07.26 |
codewars #84Can you get the loop ? (5kyu) (0) | 2018.07.24 |
codewars #83 Stop gninnipS My sdroW! (6kyu) (0) | 2018.07.23 |
codewars #82Evil Autocorrect Prank (6kyu) (0) | 2018.07.19 |