A layout tool applies a list of nudges to an element, in order. Each nudge has a size in nudges, and for each one you choose its direction: + moves the element right by that size and - moves it left. The element starts at position 0.
Write countSignedNudges(nudges, target) that returns how many different choices of signs leave the element exactly at target. A nudge of size 0 still has two signs, and both count.
Input: nudges = [1,1,1,1], target = 2 Output: 4
Exactly one of the four nudges must be negative, and there are 4 ways to pick it.
Input: nudges = [2,3], target = 1 Output: 1
Only -2 + 3 gives 1.
1 <= nudges.length <= 400 <= nudges[i] <= 1000-1000 <= target <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #488 Signed Nudges to a Target. 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.