Quick actions

cmd+k|ctrl+k

Navigation

Languages

allTwoSum

Snippet info

Language

JavaScript

Visibility

public

Author

soham57

Created

2022-09-01T12:30:36.767636Z

Updated

2022-09-01T12:30:36.767636Z

function allTwoSum(arr,target){
    
    let mySet=new Set();
    let pairs=[];
    for(let x of arr){
        if(mySet.has(x)){
            
            pairs.push([target-x,x]);
            mySet.delete(target-x)
        }
        
        else{
            mySet.add(target-x)
        }
    }
    
    return pairs
    
}


console.log(allTwoSum([5,3,4,6,2],8))
console.log(allTwoSum([5,3,4,6,2,4,4],8))
INFO