prabaprakash/Hackerrank-JavaScript-Solutions

Almost Sorted Algorithms

prabaprakash opened this issue · 0 comments

Algorithm Explained: https://medium.com/@leejh3224/hackerrank-solution-almost-sorted-4331bd58275

1_7WwKAq9CeuMTf8Rrc-Yu8g
Case 1: Valley === 1
No
Case 2: Valley === Peak === 1
swap, then the array is sorted
or
reverse, then the array is sorted
case 3: Valley > 1, Peak > 1
no
case 4: Valley === Peak === 0
reverse, then the array is sorted