Search for a command to run...
Binary search that returns index or insertion point
Try your own input
Change the array and replay the algorithm from step one.
Current step
Whether the target is present or not, the answer is the same thing: the first index holding a value ≥ 5. Scanning left to right finds it directly.
Brute Force
1function searchInsert(nums, target) {2 for (let i = 0; i < nums.length; i++) {//target: 5n: 4ans: —3 // First value at or above the target4 if (nums[i] >= target) {5 return i;6 }7 }8 // Target is larger than everything9 return nums.length;10}