Find is validsequence and target
// When you know what language you would like to use for your interview,
// simply choose it from the dropdown in the left bar.
// Enjoy your interview!
// Given a sequence of non-negative integers and an integer total target, return whether a continuous sequence of integers sums up to target.
//
// => [1,2,3,4, 5 ,6 ] target 7, true/false
left = 0
right = 0
currentSum = 1
right = 1, 3 < 7, …right
6 < 7 , keep incrementing
function isValidSequence(input, target , currentSum, start, end){
if(!input) return false
if currentSum == target { return true}
// if currentsum > target then ignroe this element and start
if(currentSum > target){
let firstElement = input[start]
start++
if(start > end){ end = start}
// Remove first element and call the valid sequence
return isValidSequence(input, target, currentSum-firstElement, start, end )
}
else if(currentSum < target){
end+=1
let nextElement = input[end]
// Adding a new element at the end
return isValidSequence(input, target, currentSum+nextElement, start ,end )
}
// if current sum < target then add a new element and check validity , or remove current element and add new element
}