Opening your workspace…
Workspace/Coding room
Opening your workspace…
You’re running the Krusty Krab register, and Mr. Krabs says the drawer is a penny short. The register tallied every order at today’s prices, but for one unbroken stretch of orders you charged customers from an old menu. Find the shortest stretch that could explain the missing penny. Return its first and last order numbers, counting from 1. If several stretches tie, return the earliest. If none works, return [].
[[203,200],[198,200],[304,300]]Output[1,2]The register tallied 401 cents for the first two orders. You collected 400 cents at the old prices. No single order accounts for one cent.
[[202,200],[199,200],[302,300]]Output[1,2]Orders 1 and 3 each put the drawer two cents short at the old price. Order 2 puts it one cent over. Either adjacent pair leaves it one cent short, so the earlier pair wins.
Look up the latest earlier prefix that is exactly one cent below the current total.
function solve(orders) { // 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.