Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A number of cities are arranged on a graph that has been divided up like an ordinary Cartesian plane. Each city is located at
A number of cities are arranged on a graph that has been divided up like an ordinary Cartesian plane. Each city is located at an integral (x, y) coordinate intersection. City names and locations are given in the form of three arrays: c, x, and y, which are aligned by the index to provide the city name (c[i]), and its coordinates, (x[i], y[i]). Determine the name of the nearest city that shares either an x or a y coordinate with the queried city. If no other cities share an x or y coordinate, return 'NONE'. If two cities have the same distance to the queried city, q[i], consider the one with an alphabetically shorter name (i.e. 'ab' < 'aba' if __name__ == '__main__' Activate Windows Go to Settings to activate Windows. Function Description Complete the function closestStraightCity in the editor below. closestStraightCity has the following parameter(s): string c[n]: an array of strings that represent the names of each city[i] int x[n]: the x coordinates of each city[i] int y[n]: the y coordinates of each city[i] string q[m]: the names of each city to query Returns: string[m]: an array of m strings where the index of i element denotes the return value of the index of i query Constraints 1 n, m 105 1 x[i].y[i] 10 1 length of q[i] and c[i] 10 Each character of all c[i] and q[i] is in the range ascii[a-z, 0-9, -] All city name values, c[i], are unique All cities have unique coordinates Sample Case 0 Sample Input STDIN 3 c[] size n = 3 fastcity c[] = ['fastcity', 'bigbanana', 'xyz'] bigbanana xyz 3 ~ ~ ~ 23 23 23 3 1 10 20 3 Function xyz x[] size n = 3 x[] = [23, 23, 23]. y[] size n = 3 y[] = [1, 10, 201 q[] size m = 3 fastcity q[] = ['fastcity', 'bigbanana', 'xyz'] bigbanana Sample Output bigbanana fastcity bigbanana
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres the code for the closestStraightCity function def closestStraightCityc x y q Create dictionari...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started