You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// https://www.hackerrank.com/challenges/missing-numbers/problemfunc missingNumbers(arr:[Int], brr:[Int])->[Int]{
guard !arr.isEmpty else{returnArray(Set(brr)).sorted()}varresult:[Int]=[Int]()varbrrDictionary=[Int: Int]()vararrDictionary=[Int: Int]()
for num in brr {
if let count =brrDictionary[num]{brrDictionary[num]= count +1}else{brrDictionary[num]=1}}
for num in arr {
if let count =arrDictionary[num]{arrDictionary[num]= count +1}else{arrDictionary[num]=1}}
for (key,value) in brrDictionary {
if arrDictionary[key]==nil{
result.append(key)}else{
if arrDictionary[key]!= value{
result.append(key)}}}return result.sorted()}
JavaScript Solution
functionmissingNumbers(arr,brr){constbrrFreq={}for(letnumofbrr){if(!brrFreq.hasOwnProperty(num)){brrFreq[num]=1}else{brrFreq[num]++}}// substract the elements that are present in arr from brrFreqfor(letnumofarr){brrFreq[num]--}constmissing=[]for(letnumKeyinbrrFreq){if(brrFreq[numKey]!==0){// if there's any number whose count is not 0 then its missingmissing.push(numKey)}}returnmissing.sort((a,b)=>a-b)}
// https://www.hackerrank.com/challenges/icecream-parlor/problemfunc icecreamParlor(m:Int, arr:[Int])->[Int]{vardict=[Int: Int]()
for i in 0..<arr.count {letcurrentValue=arr[i]
if let index =dict[m - currentValue]{return[index +1, i +1]}else{dict[currentValue]= i
}}return[]}
thanks!