99 - Sherlock and the Valid String | Strings | Hackerrank Solution | Python

99 - Sherlock and the Valid String | Strings | Hackerrank Solution | Python

Hackers Realm

3 года назад

7,000 Просмотров

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


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

@debojitmandal8670
@debojitmandal8670 - 22.05.2023 21:04

bro atleast explain me the code

Ответить
@udaykiranramaraju4985
@udaykiranramaraju4985 - 01.02.2022 21:02

I think in interviews it's better not to use any built in functions like counter etc..

s='abc'
d={}
for i in s:
if i in d:
d[i]+=1
else:
d[i]=1
min_count=d[i]
max_count=d[i]
z={}
for i,value in d.items():
if value in z:
z[value]+=1
else:
z[value]=1
if value<min_count:
min_count=value
if value>max_count:
max_count=value
if len(z)==1:
print("YES")
elif len(z)==2:
if z[max_count] == 1 and max_count - min_count == 1:
print("YES")
elif z[min_count] == 1 and min_count == 1:
print("YES")
print("NO") (in platfom use return instead of print)




here's my soilution t.c:O(n) and s.c: O(1)

Ответить
@tanyagupta0201
@tanyagupta0201 - 28.01.2022 13:57

Why did you use set ?

Ответить
@NirmalaDevi-qu7nj
@NirmalaDevi-qu7nj - 18.05.2021 08:53

Sir, why do we have to remove 0s?

Ответить
@mrlai999
@mrlai999 - 26.04.2021 06:05

Thank you for the video. May I know why is there a need to remove 0 on line 29? Does 0 represent empty character in this case?

Ответить
@tony851029976201
@tony851029976201 - 08.01.2021 11:18

It's an amazing solution, thanks🤣🤣

Ответить
@kuruvajanardhan2093
@kuruvajanardhan2093 - 08.08.2020 17:33

Bhayya
Can you please give your number

Ответить