// Write a function that takes an array of integers and an integer k, and returns the maximum sum of any contiguous subarray of length k.
/* Test cases
arr: [1, 4, 2, 10, 23, 3, 1, 0, 20], k: 4, expected: 39 }, Subarray [10, 23, 3, 1]
arr: [2, 1, 5, 1, 3, 2], k: 3, expected: 9 }, // Subarray [5, 1, 3]
arr: [2, 3, 4, 1, 5], k: 2, expected: 7 }, // Subarray [3, 4]
arr: [1, -1, 5, -2, 3, 6, -1], k: 3, expected: 10 }, // Subarray
[3, 6, -1]
arr: [1, 2, 3, 4, 5], k: 5, expected: 15 }, // Subarray [1, 2, 3, 4, 5]
arr: [5, -10, 6, 90, 3], k: 2, expected: 96 }, // Subarray [6, 90]
arr: [100, 200, 300, 400], k: 2, expected: 700 }, // Subarray [300, 400]
arr: [1, 2], k: 2, expected: 3 }, // Subarray [1, 2]
arr: [1], k: 1, expected: 1 }, // Subarray [1]
arr: [-1, -2, -3, -4], k: 2, expected: -3 } // Subarray [-1, -2]
*/
const findContiguosSum = (arr, k) => {
let sum = 0
let tempSum = 0
let results = []
let tempResults = []
for(let i = 0 ; i < arr.length - k ; i++){
for(let n = i; n < i+k ; n++){
tempSum = tempSum + arr[n]
tempResults.push(arr[n])
}
if(tempSum > sum){
sum = tempSum
results = tempResults
}
tempSum = 0
tempResults = []
}
return results
}
console.log( findContiguosSum([1, 4, 2, 10, 23, 3, 1, 0, 20], 4 ))
function sum(...a){
}
// const App = () => {
// const [formSteps, setFormSteps] = useState([{isActive:true, id:1},{isActive:false,id:2},{isActive:false, id:3}])
// const [activeIndex, seAtiveIndex] = useState(0)
// const handleNavigate = (type) => {
// if(type=="back"){
// setActiveIndex(activeIndex - 1)
// }else{
// setActiveIndex(activeIndex + 1)
// }
// }
// <
// }
// yup.arrayOf({
// value1:isRequired().min(2, "cannot have less 2 char").max(8).,
// })
// const anything = async() => {
// const result1 = axios.get("ur")
// const result2 = axios.get("url")
// const apiData1 = await result1
// const apiData2 = await result2
// }
To embed this project on your website, copy the following code and paste it into your website's HTML: