Answers for "sparse arrays hackerrank in python"

1

sparse arrays hackerrank solution in python

store = dict()
    ans = []
    
    for w in strings:
        if w in store:
            store[w] +=1    #adding value to the key word(current word in string)
        else:
            store[w]=1      #assigning 1 to the new word in store
            
    for q in queries:
        if q in store:
            ans.append(store[q])
        else:
            ans.append(0)
    return ans
Posted by: Guest on July-18-2021

Code answers related to "sparse arrays hackerrank in python"

Python Answers by Framework

Browse Popular Code Answers by Language