+ 3

New Driver's License (How to do this)?

You have to get a new driver's license and you show up at the office at the same time as 4 other people. The office says that they will see everyone in alphabetical order and it takes 20 minutes for them to process each new license. All of the agents are available now, and they can each see one customer at a time. How long will it take for you to walk out of the office with your new license? Task Given everyone's name that showed up at the same time, determine how long it will take to get your new license. Input Format Your input will be a string of your name, then an integer of the number of available agents, and lastly a string of the other four names separated by spaces. Output Format You will output an integer of the number of minutes that it will take to get your license. Sample Input 'Eric' 2 'Adam Caroline Rebecca Frank' Sample Output 40

14th Oct 2021, 1:17 AM
Ctrl + Z
Ctrl + Z - avatar
6 Answers
+ 4
#this may help you and I have done in python, don't mind :) #to get myname my_name = input() #to get agent name agents = int(input()) #to get all the list names of people other_names = input() #converting all the string to lost to sort list_of_names = other_names.split() #appending myname to compare list_of_names.append(my_name) #sorting the list as question said, work is done only in alpha order. list_of_names.sort() #getting the index of our name in the list... index = list_of_names.index(my_name) + 1 #if the agents r more than index of our name, work will done soon. #because if 5 agents r thr and thr are only 4 peoples, then my task will get sooner if agents >= index: result = 20 #if that's not the case start decounting the value with index and agent and finallu print the value else: time = index - agents result = 20 + time * 20 #print the result finally... print(result)
14th Oct 2021, 1:19 AM
GURURAJ KL
GURURAJ KL - avatar
+ 2
Thank you â˜ș
14th Oct 2021, 1:20 AM
Ctrl + Z
Ctrl + Z - avatar
+ 1
Brian As in the question they r asking us to sort the list of names
14th Oct 2021, 8:12 AM
GURURAJ KL
GURURAJ KL - avatar
0
GURURAJ KL There is no requirement that says you must sort the names. The task is to determine how long it will take. You can efficiently determine the correct answer without sorting. A simple count of names less than or equal to your name gives the number to scale for the wait time.
14th Oct 2021, 8:42 AM
Brian
Brian - avatar
0
myname = input() num_agents = int(input()) other_names = list(input().split()) other_names.append(myname) other_names.sort() ind_myname = other_names.index(myname)+1 print('20' if ind_myname <=num_agents else (ind_myname-num_agents)*20+20)
25th Nov 2021, 10:31 PM
Mas'ud Saleh
Mas'ud Saleh - avatar
- 1
There is no need to sort. Just loop through the given names and count how many names are less than or equal to yours. GURURAJ KL's technique would give a wrong answer if there is already someone in line with the same name as you.
14th Oct 2021, 7:48 AM
Brian
Brian - avatar