This was very similar to binary search as it was mostly sorted. Just had to keep splitting until the mid word was lesser than starting word.
def rotation_point(words) starting_index = 0 ending_index = words.length - 1 while starting_index < ending_index puts "\n#{words[starting_index]}" puts "#{words[ending_index]}" mid = (starting_index + ending_index) /2 puts "#{mid}" puts "#{words[mid]}" if words[mid] < words[0] ending_index = mid else starting_index = mid end return ending_index if starting_index + 1 == ending_index end end
Binary search so its O[logn] time and space if O[1]
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This was very similar to binary search as it was mostly sorted. Just had to keep splitting until the mid word was lesser than starting word.
Binary search so its O[logn] time and space if O[1]