In a design tool, nested groups each scale their contents by a whole-number factor, listed in order in factors. A run of neighboring groups multiplies its factors together, and the editor warns when that product reaches limit or more.
Write countSafeChains(factors, limit) that returns how many non-empty runs of neighboring groups have a product strictly less than limit.
Input: factors = [10,5,2,6], limit = 100 Output: 8
The runs [10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6] all stay under 100.
Input: factors = [1,2,3], limit = 0 Output: 0
No product is below 0.
0 <= factors.length <= 300001 <= factors[i] <= 10000 <= limit <= 10^6Run 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 #138 Scale Chains Below a Limit. 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.