Opening your workspace…
Workspace/Coding room
Opening your workspace…
Kageyama times his quick set to the first beat when Hinata reaches his takeoff mark. You get an integer mark and a list positions giving Hinata’s distance along his approach on beats numbered from 0. The positions are in nondecreasing order. Use binary search to return the smallest beat index i for which positions[i] ≥ mark. Landing exactly on the mark or passing it between beats both count. For positions [2, 5, 5, 9] and mark 5, return 1. If Hinata starts on or beyond the mark, return 0. If the list is empty or he never reaches the mark, return -1.
[2,5,5,9], 5Output1Beat 1 is the first time Hinata reaches 5.
[], 3Output-1There are no recorded beats.
Search for the first position greater than or equal to the takeoff mark.
function solve(positions, mark) { // Write your solution here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.