6 kyu

Circularly Sorted Array

1,117 of 2,330JTSHEP

Description:

An array is circularly sorted if the elements are sorted in ascending order, but displaced, or rotated, by any number of steps.

Complete the function/method that determines if the given array of integers is circularly sorted.

Examples

These arrays are circularly sorted (true):

[2, 3, 4, 5, 0, 1]       -->  [0, 1] + [2, 3, 4, 5]
[4, 5, 6, 9, 1]          -->  [1] + [4, 5, 6, 9]
[10, 11, 6, 7, 9]        -->  [6, 7, 9] + [10, 11]
[1, 2, 3, 4, 5]          -->  [1, 2, 3, 4, 5]
[5, 7, 43, 987, -9, 0]   -->  [-9, 0] + [5, 7, 43, 987]
[1, 2, 3, 4, 1]          -->  [1] + [1, 2, 3, 4]

While these are not (false):

[4, 1, 2, 5]
[8, 7, 6, 5, 4, 3]
[6, 7, 4, 8]
[7, 6, 5, 4, 3, 2, 1]
Algorithms
Sorting

Stats:

CreatedOct 23, 2014
PublishedOct 23, 2014
Warriors Trained4422
Total Skips665
Total Code Submissions13761
Total Times Completed2330
Java Completions1117
Ruby Completions170
JavaScript Completions520
PHP Completions60
Haskell Completions43
Go Completions73
Python Completions438
Total Stars88
% of votes with a positive feedback rating95% of 345
Total "Very Satisfied" Votes312
Total "Somewhat Satisfied" Votes30
Total "Not Satisfied" Votes3
Ad
Contributors
  • JTSHEP Avatar
  • jhoffner Avatar
  • ZozoFouchtra Avatar
  • ominiom Avatar
  • Unnamed Avatar
  • anter69 Avatar
  • candrabeqx Avatar
  • Chrono79 Avatar
  • docgunthrop Avatar
  • JohanWiltink Avatar
  • RobsonMoon Avatar
  • user8436785 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad