Thu Mar 16 2023 15:00:37 GMT+0000 (Coordinated Universal Time)
Saved by @vishal
const arr=[1,4,3,2,6,7,8] function twoSum(arr, S) { const sum = []; for(let i = 0; i< arr.length; i++) { for(let j = i+1; j < arr.length; j++) { if( arr[i] + arr[j]==S) sum.push(arr[i],arr[j]) } } return sum } console.log(twoSum(arr,8))
Copy this HTML code:
Preview:
open_in_newInstructions on embedding in Medium
Comments