Google Q

Run Settings
LanguageJavaScript
Language Version
Run Command
const arr1 = [1,2,4,7]; const arr2 = [4,5,6,7]; const sum = 13; // function answer(a1,sum){ // for(let i=0;i<a1.length;i++){ // for(let j=0;j<a1.length;j++){ // if(a1[i]+a1[j]==sum){ // console.log(a1[i],' ',a1[j]); // return true; // } // } // } // return false; // } function answer2(a2,sum){ const lp = new Set(); for(let i=0;i<a2.length;i++){ if(lp.has(a2[i])) return true; lp.add(sum-a2[i]); console.log(lp); } return false; } let bool = answer2(arr2,sum); console.log(bool);
Editor Settings
Theme
Key bindings
Full width
Lines