0
Can someone help me with this code?
It's a coding challenge present in sololearn. New drivers license. name = input() agents = int(input()) list = input().split(" ") list.append(name) list.sort() minutes = 20 d = minutes/agents for i in range(len(list)): if i > 0 and list[i] == name: minutes = (i+1)*d break; print(int(minutes))
7 Respuestas
+ 4
You should check the logic of your algorithmus: what happen with the time when number of agents is even and what when is odd.
+ 3
shahul hameed
When I input the following:
rik
3
bob ann zac jon
I get 26 as an output
Expected output is 40
Think in blocks of time
20 mins for each block.
You are close, just need to think a bit deeper.
Good luck!
+ 2
shahul hameed , if you think about your way of solving it for long enough you will realize your way is quite logically wrong. (try going through your algorithm if number of agents is 3 and the required name is first in the list)
But here is the correct way to solve this:
import math
name = input()
agents = int(input())
list = input().split(" ")
list.append(name)
list.sort()
minutes = 20
for i in range(len(list)):
if list[i] == name:
minutes = (math.floor(i/agents)+1)*minutes
break;
print(int(minutes))
So you should divide i rather than minutes by number of agents...
+ 2
Thank you guys. This is what I came up with and it worked.
name = input()
agents = int(input())
list = input().split(" ")
list.append(name)
list.sort()
flag=0
i=0
j=0
count = 0
for a in range(len(list)//agents):
count+=1
j+=agents
if name in list[i:j]:
print(20*count)
flag=1
break;
i=j
if (len(list)%agents) != 0 and flag!=1:
print(20*(len(list)//agents+1))
+ 2
shahul hameed
Congrats!
Well done
+ 1
I don’t see anything particularly wrong with the code itself, is the output not what it’s supposed to be? Could I know what this programme is supposed to be doing (perhaps with an example, as presented as a challenge in Sololearn)