Sparse Arrays

  • + 0 comments

    Javascript solution

    function matchingStrings(strings, queries) {

    let freqObj = {}
    for(let i=0; i < strings.length; i++) {
        let str = strings[i];  
        freqObj[str] = (freqObj[str] || 0) + 1; 
        }
        return queries.map(querie => freqObj[querie]) 
    
    
    return queries.map(querie => freqObj[querie] || 0); 
    

    }