prabaprakash / Hackerrank-JavaScript-Solutions

Solved entire Easy, few Medium Problems. A total of 171/563 challenges solved by JavaScript
https://www.hackerrank.com/prabaprakash
123 stars 64 forks source link

Almost Sorted Algorithms #3

Closed prabaprakash closed 4 years ago

prabaprakash commented 4 years ago

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