We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
What's wrong here, which corner case may I be missing? (suceeds with some of them)
deffreqQuery(queries):'''FunctiontoconducttheoperationasdefinedinthequerylistuponanarrayInputs:queries-[List(tuples)]Listcontainingtupleswith(actionType,value)Returns:None'''myArray=[]outputArray=[]forqueryinqueries:queryValue=query[1]# debugprint(f"myArray: {myArray}")print(f"query type: {query[0]}, query value: {queryValue}")# Check type of query and perform mentioned actionmatchquery[0]:case1:# Append to listmyArray.append(queryValue)case2:# Convert to set and check if the element existsmySet=set(myArray)ifmySet.intersection([queryValue]):myArray.remove(queryValue)case3:# Create a dictinoary of frequenciesmyDict=dict(())forelementinmyArray:count=0ifmyDict.get(element)==None:myDict.update({element:count+1})else:myDict.update({element:myDict.get(element)+1})# Convert the dict to list for easy iterationfrequencies=list(myDict.items())# Check for matching or NO frequenciesifnotfrequencies:outputArray.append(0)else:forindex,frequencyinenumerate(frequencies):iffrequency[1]==queryValue:outputArray.append(1)breakelse:outputArray.append(0)breakreturnoutputArray
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Frequency Queries
You are viewing a single comment's thread. Return to all comments →
What's wrong here, which corner case may I be missing? (suceeds with some of them)