Last active
March 9, 2021 15:12
-
-
Save Kawaritapas/facb564c2b69b2cd025f6958924dbeca to your computer and use it in GitHub Desktop.
Coding challenge submission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1st challenge solution:-- | |
function target(nums, target) { | |
let result = []; | |
for(let i=0;i<nums.length;i++){ | |
for(let j=i+1;j<nums.length;j++){ | |
if(nums[i]+nums[j]==target){ | |
result.push(i,j) | |
} | |
} | |
} | |
return result; | |
}; | |
target([2, 5, 9, 11],11); | |
------------------------------------------------------------------------------------------------------------------------------ | |
2nd challenge soulution:-- | |
const max_sum = function(k, arr) { | |
let newArr = []; | |
for(let i=0;i<arr.length;i++){ | |
newArr.push(arr.slice(i,k+i)) | |
} | |
let temp=[] | |
for(let j=0;j<newArr.length;j++){ | |
if(newArr[j].length==k){ | |
temp.push(newArr[j].reduce((a,b)=>{ | |
return a+b; | |
})) | |
} | |
} | |
return Math.max(...temp) | |
}; | |
max_sum(3,[2, 1, 5, 1, 3, 2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment