Sock Merchant [HackerRank] | Interview | Python | Problem Solving

Sock Merchant [HackerRank] | Interview | Python | Problem Solving

Coding Cart

4 года назад

12,992 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@codingcart
@codingcart - 30.01.2020 19:25

Hey Programmer, if you have any alternative solution feel free to post in comment section.

Ответить
@gioadan4680
@gioadan4680 - 13.02.2023 21:20

My output keeps returning 2 instead of three and four for cases 1 and 2, what’s the reason for this?

Ответить
@infinitygaming7192
@infinitygaming7192 - 08.08.2021 20:12

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

Ответить
@aaditshah5825
@aaditshah5825 - 06.03.2021 22:22

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

Ответить
@RohanVemula
@RohanVemula - 25.01.2021 08:59

Can't we solve by solving with arrays
Like arr[i]=arr[i+1]

Ответить
@harshhwardhanrai3716
@harshhwardhanrai3716 - 26.12.2020 00:00

I don't how how this question can be warmup challenge, dimaag hila daala is problem be to

Ответить
@husainbaig9507
@husainbaig9507 - 03.12.2020 07:19

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

Ответить
@michealerick9428
@michealerick9428 - 29.09.2020 13:10

All thanks to hacker-erick9 for deactivating my girlfriend's insta account

Ответить
@prashnatdivase8523
@prashnatdivase8523 - 05.08.2020 13:40

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

Ответить
@rahulrc7905
@rahulrc7905 - 13.07.2020 18:16

very well explained!!

Ответить
@viacheslavgurov4371
@viacheslavgurov4371 - 29.04.2020 05:02

Namaste, Bhagawan))) Really helpful. Send me yours LinkedIn and GitHub.

Ответить
@abhisheksaha3953
@abhisheksaha3953 - 02.02.2020 22:56

really helpful. was not aware of counter feature. thank you for sharing.👍

Ответить
@sachinsingh-jg9lx
@sachinsingh-jg9lx - 30.01.2020 19:11

Wow nice solsn

Ответить