Комментарии:
bro atleast explain me the code
Ответить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)
Why did you use set ?
ОтветитьSir, why do we have to remove 0s?
Ответить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?
ОтветитьIt's an amazing solution, thanks🤣🤣
ОтветитьBhayya
Can you please give your number