Комментарии:
Hey Programmer, if you have any alternative solution feel free to post in comment section.
ОтветитьMy output keeps returning 2 instead of three and four for cases 1 and 2, what’s the reason for this?
Ответитьmy solution
def sockMerchant(n, ar):
cat = Counter(ar)
c = list(cat.values())
d = 0
for i in range(0,len(c)):
if c[i] > 1:
d += int(c[i]/2)
return(d)
i am working very hard i wish i become programmer like you
Nice video bro keep it up :D!
An alternate solution:
def sockMerchant(n, array):
pairs = 0
set_of_array = set(array)
for i in set_of_array:
count = array.count(i)
total_pair = count//2
pairs += total_pair
return pairs
Can't we solve by solving with arrays
Like arr[i]=arr[i+1]
I don't how how this question can be warmup challenge, dimaag hila daala is problem be to
Ответитьdef pairlist(list):
data = []
sum = 0
r = set(list)
for i in r:
res = list.count(i)
data.append({i:res})
for j in data:
for key, val in j.items():
result = val//2
sum = sum+result
return sum
All thanks to hacker-erick9 for deactivating my girlfriend's insta account
ОтветитьAlternate solution
blank_list=[]
count_of_pair=0
for i in ar:
if i not in blank_list:
cnt= ar.count(i)
count_of_pair+= cnt//2
blank_list.append(i)
return count_of_pair
very well explained!!
ОтветитьNamaste, Bhagawan))) Really helpful. Send me yours LinkedIn and GitHub.
Ответитьreally helpful. was not aware of counter feature. thank you for sharing.👍
ОтветитьWow nice solsn
Ответить