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.
# O(n^2)defsockMerchant(n,ar):cnt=0seen=set()fornuminar:ifnumnotinseen:seen.add(num)cnt+=ar.count(num)// 2returncnt# O(n)defsockMerchant(n,ar):ar.sort()idx=0cnt=0whileidx<len(ar)-1:ifar[idx]==ar[idx+1]:cnt+=1idx+=2else:idx+=1returncnt# O(n)defsockMerchant(n,ar):cnt=[0]*(max(ar)+1)fornuminar:cnt[num]+=1returnsum([num// 2 for num in cnt])
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sales by Match
You are viewing a single comment's thread. Return to all comments →
My 3 Python solutions - two O(n) and one O(n^2)