A fitness app stores daily calorie balance changes in nums, which can be negative. The coach wants the longest stretch of back-to-back days whose changes add up to exactly k.
Write longestTargetStreak(nums, k) that returns the length of that stretch, or 0 if no stretch adds up to k.
Input: nums = [2,-1,3,-2,4,1], k = 4 Output: 4
Days 1 to 4, [-1, 3, -2, 4], add up to 4. No longer stretch does.
Input: nums = [1,2,3], k = 7 Output: 0
No stretch adds up to 7.
0 <= nums.length <= 10^5-10^4 <= nums[i] <= 10^4-10^9 <= k <= 10^9Run 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 #48 Longest Streak Hitting 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.