(coordinates, previous = 0, fleets = 0)
| 76 | ); /* Time O(N) | Space O(N) */ |
| 77 | |
| 78 | var searchDescending = (coordinates, previous = 0, fleets = 0) => { |
| 79 | for (const coordinate of coordinates) { |
| 80 | /* Time O(N) */ |
| 81 | const isPreviousLess = previous < coordinate; |
| 82 | if (!isPreviousLess) continue; |
| 83 | |
| 84 | previous = coordinate; |
| 85 | fleets++; |
| 86 | } |
| 87 | |
| 88 | return fleets; |
| 89 | }; |