60 mins 3 questions
Q1
Each day, to enter their building, employees of an e-commerce company have to type a string of numbers into a console using a 3 × 3 numeric keypad. Every day, the numbers on the keypad are mixed up.
Use the following rules to calculate the total amount of time it takes to type a string:
• It takes 0 seconds to move their finger to the first key, and it takes 0 seconds to press the key where their finger is located any number of times.
They can move their finger from one location to any adjacent key in one second. Adjacent keys include those on a diagonal.
• Moving to a non-adiacent key is done as a series of moves to adjacent keys.
Function Description
Complete the function entryTime in the editor below.
entryTime has the following parameter(s):
string s: the string to type
string keypad: a string of 9 digits where each group of 3 digits represents a row on the keypad of the day, in order
Returns:
Int: integer denot smaller-numbered city first (city 3) and continuing in ascending order (city 4).
Therefore, the order is [2, 3, 4], which is the answer you would return.
Function Description
Complete the function order in the editor below.
order has the following parameters:
int cityNodes: the number of cities
int cityFrom[n]: the first city node where there is a bidirectional edge
int cityTo[n]: the second city node where there is a bidirectional edge int company: the node where the route starts
Returns:
intl: the cities where the goods will be delivered in the order visited |