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.
// Complete the freqQuery function below.funfreqQuery(queries:Array<Array<Int>>):Array<Int>{valvalueCount=mutableMapOf<Int,Int>()valresult=mutableListOf<Int>()queries.forEach{items->valoperation=items[0]valvalue=items[1]if(operation==1){valcurrentCount=valueCount.getOrDefault(value,0)valnewCount=currentCount+1valueCount.put(value,newCount)}elseif(operation==2){if(valueCount.contains(value)){valcurrentCount=valueCount.get(value)!!if(currentCount<=1){valueCount.remove(value)}else{valueCount.put(value,currentCount-1)}}}else{if(valueCount.containsValue(value)){result.add(1)}else{result.add(0)}}}returnresult.toTypedArray()}
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 →
Kotlin Solution