A shop's product grid shows items in a fixed order. stock[i] is how many units of the item in slot i are left. The grid should show a "Sold out" banner above the first empty slot.
Write findFirstEmpty(stock) that returns the index of the first slot whose count is 0, or -1 if nothing is sold out.
The counts are in no particular order.
Input: stock = [5,2,0,7,0] Output: 2
Slots 2 and 4 are empty. Slot 2 comes first.
Input: stock = [3,1,4] Output: -1
Every product still has stock.
0 <= stock.length <= 100000 <= stock[i] <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #152 First Sold-Out Product. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.