I need your help guys! This code is working fine. But the execution time is more. So please help me to optimize this code. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I need your help guys! This code is working fine. But the execution time is more. So please help me to optimize this code.

https://code.sololearn.com/cWjJkip1Q2UU/?ref=app

1st Jun 2019, 6:36 AM
Geek
Geek - avatar
4 Answers
+ 1
remove the first for loop as string is an array of chars. you dont have to push chars into another array to get the last one. just reassign a pre defined variable. s=input() #taking input string n=int(input()) #taking frequency a='' for i in s: if(s.count(i)==n): a=i if(a): print(a) else: print(-1)
1st Jun 2019, 6:46 AM
Farry
Farry - avatar
+ 1
Geek it works perfectly fine on my side. try clearing the cache of your sololearn app
1st Jun 2019, 7:03 AM
Farry
Farry - avatar
0
Thanks farry. This code is way better than my code. But it is still showing time limit exceeded. I don't know what to do
1st Jun 2019, 7:02 AM
Geek
Geek - avatar
0
This problem is asked in a practice contest in skillrack. In that private test cases are not passing.
1st Jun 2019, 9:28 AM
Geek
Geek - avatar