Please find the attachment.
Question 2: Maximum Common Candies There are friends_nodes friends, numbered from 1 to friends_nodes, who like to eat different candies. There are friends_edges pairs of friends where each pair of friends is connected by the common candy that they both like. Candies are numbered from 1 to 100. Note that if x[i] and y[i] are connected by a candy c[i] and y[i] and z[i] are also connected by the candy c[i], then x[i] and z[i] are also said to be connected by c[i]. Find the maximal product of x[i] and y[i] so that x[i] and y[i] share the largest group of friends which is connected by some common candy. As an example, assume the following 6 inputs: From To Candy 1 2 51 7 3 51 5 6 51 10 8 51 6 9 51 2 3 51 Everyone likes the same candy, but not everyone is connected. A graphical representation is: The largest group is [1, 2, 3, 7] and its largest elements are 3 and 7. Their product is 21. Function Description Complete the function countCandies in the editor below. The function must return an integer that represents the product of the maximum two friend numbers in the largest group. countCandies has the following parameter(s): friends_nodes: an integer, the number of friends friends_from[friends_from[0],...friends_from[n-1]]: an integer array where each element denotes the first friend in the pair friends_to[friends_to[0],...friends_to[n-1]]: an integer array where each element denotes the second friend in the pair friends_weight[friends_weight[0],...friends_weight[n-1]]: an integer array where each element denotes a candy liked by both friends Constraints · 2 ≤ friends_nodes ≤ 100 · 1 ≤ friends_edges ≤ min(200, (friends_nodes × (friends_nodes - 1)) / 2) · 1 ≤ friends_weight[i] ≤ 100 · 1 ≤ friends_from[i], friends_to[i] ≤ friends_nodes · 1≤ friends_weight[i] ≤ friends_edges · friends_from[i] ≠ friends_to[i] · Each pair of friends can be connected by more than one type of candy Question 3: Nearest Neighbor A number of cities arranged on a plane that has been divided up like an ordinary Cartesian plane. Each city is located at an integral (x, y) intersection. City names and locations are given in the form of three arrays: c, x, and y, aligned by index to provide the city name (c[i]), and its coordinates, (x[i], y[i]). For each city queried, determine the name of the nearest other 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 alphabetically smaller name (i.e. 'ab' < 'aba'="">< 'abb') as the closer one. the distance here denotes the euclidean distance on the plane: difference in x plus difference in y. for example, there are n = 3 cities, c = [c1, c2, c3] at locations x = [ 3, 2, 1] and y = [3, 2, 3], so points (3,3), (2,2) and (1,3). our queries are q = [c1, c2, c3]. the nearest city to c1 is c3 which shares a y value (distance = (3-1) + (3-3) = 2). city c2 does not have a nearest city as none shares an x or y with c2, so this query would return none. a query of c3 would return c1 based on the first calculation. the return array after all queries is [c3, none, c1]. function description complete the function closeststraightcity in the editor below. the function must return an array of m strings, where the ith element of this array denotes the answer to the i th query. closeststraightcity has the following parameter(s): c[c[0],...c[n-1]]: an array of strings x[x[0],...x[n-1]]: an array of integers y[y[0],...y[n-1]]: an array of integers q[q[0],...q[m-1]]: an array of strings constraints · 1 ≤ n, m ≤ 105 · 1 ≤ x[i], y[i] ≤ 109 · 1 ≤ | q[i] |, | c[i] | ≤ 10 · each character of all c[i] and q[i] ∈ ascii[a-z] · all city name values, c[i], are unique · all cities have unique coordinates question 5: dangerous script if you've ever looked at an assembly language dump of an executable file, you know that commands come in the form of hexadecimal digits that are grouped by the processor into instructions. it is important that the parsing be done correctly or code will not be executed as expected. wrong parsing is the basis for return oriented programming, a method of causing mahem. you have developed a program in a new scripting language. of course, it requires accurate parsing in order to perform as expeced, and it is very cryptic. you want to determine how many valid commands can be made out of your lines of script. to do this, you count all of the substrings that make up a valid command. each of the valid commands will be in the following format: · the first letter is a lowercase english letter. · next, it contains a sequence of zero or more of the following characters: lowercase english letters, digits, and colons. · next, it contains a forward slash '/'. · next, it contains a sequence of one or more of the following characters: lowercase english letters and digits. · next, it contains a backward slash '\'. · next, it contains a sequence of one or more lowercase english letters. given some string, s, we define the following: · s[i..j] is a substring consisting of all the characters in the inclusive range between index i and index j. · two substrings, s[i[1]..j[1]] and s[i[2]..j[2]], are said to be distinct if either i[1] ≠ i[2] or j[1] ≠ j[2]. for example, your command line is abc:/b1c\xy. valid command substrings are: abc:/b1c\xy bc:/b1c\xy c:/b1c\xy abc:/b1c\x bc:/b1c\x c:/b1c\x there are six valid commands that may be parsed from that one command string. function description complete the function commandcount in the editor below. the function must return an array of integers, each representing the number of valid command strings in commands[i]. commandcount has the following parameter(s): commands[commands[0],...commands[n-1]]: an array of strings constraints · 1 ≤ n ≤ 50 · each character of commands[i] ∈ [a-z,0-9,/,\,:] · each |commands[i]| ≤ 5 × 105. 'abb')="" as="" the="" closer="" one.="" the="" distance="" here="" denotes="" the="" euclidean="" distance="" on="" the="" plane:="" difference="" in="" x plus="" difference="" in="" y.="" ="" for="" example,="" there="" are="" n="3 cities," c="[c1," c2,="" c3] at="" locations="" x="[" 3,="" 2,="" 1] and="" y="[3," 2,="" 3],="" so="" points="" (3,3),="" (2,2)="" and="" (1,3). ="" our="" queries="" are="" q="[c1," c2,="" c3].="" the="" nearest="" city="" to="" c1="" is="" c3="" which="" shares="" a="" y value="" (distance="(3-1)" +="" (3-3)="2)." city="" c2="" does="" not="" have="" a="" nearest="" city="" as="" none="" shares="" an="" x or="" y with="" c2,="" so="" this="" query="" would="" return="" none.="" a="" query="" of="" c3="" would="" return="" c1="" based="" on="" the="" first="" calculation.="" the="" return="" array="" after="" all="" queries="" is="" [c3,="" none,="" c1].="" ="" function="" description="" complete="" the="" function="" closeststraightcity="" in="" the="" editor="" below.="" the="" function="" must="" return="" an="" array="" of="" m="" strings,="" where="" the="" ith="" element="" of="" this="" array="" denotes="" the="" answer="" to="" the="" i="" th="" query.="" ="" closeststraightcity="" has="" the="" following="" parameter(s):="" c[c[0],...c[n-1]]: ="" an="" array="" of="" strings="" x[x[0],...x[n-1]]: ="" an="" array="" of="" integers="" y[y[0],...y[n-1]]: ="" an="" array="" of="" integers="" q[q[0],...q[m-1]]: ="" an="" array="" of="" strings="" ="" constraints="" ·="" 1="" ≤="" n,="" m="" ≤="" 105="" ·="" 1="" ≤="" x[i],="" y[i]="" ≤="" 109="" ·="" 1="" ≤="" |="" q[i]="" |,="" |="" c[i]="" |="" ≤="" 10="" ·="" each="" character="" of="" all c[i] and q[i] ∈="" ascii[a-z]="" ·="" all="" city="" name="" values, c[i], are="" unique="" ·="" all="" cities="" have="" unique="" coordinates="" question="" 5:="" dangerous="" script="" if="" you've="" ever="" looked="" at="" an="" assembly="" language="" dump="" of="" an="" executable="" file,="" you="" know="" that="" commands="" come="" in="" the="" form="" of="" hexadecimal="" digits="" that="" are="" grouped="" by="" the="" processor="" into="" instructions.="" it="" is="" important="" that="" the="" parsing="" be="" done="" correctly="" or="" code="" will="" not="" be="" executed="" as="" expected.="" wrong="" parsing="" is="" the="" basis="" for="" return="" oriented="" programming,="" a="" method="" of="" causing="" mahem.="" ="" you="" have="" developed="" a="" program="" in="" a="" new="" scripting="" language.="" of="" course,="" it="" requires="" accurate="" parsing="" in="" order="" to="" perform="" as="" expeced,="" and="" it="" is="" very="" cryptic.="" you="" want="" to="" determine="" how="" many="" valid="" commands="" can="" be="" made="" out="" of="" your="" lines="" of="" script.="" to="" do="" this,="" you="" count="" all="" of="" the="" substrings="" that="" make="" up="" a="" valid="" command.="" each="" of="" the="" valid="" commands="" will="" be="" in="" the="" following="" format:="" ·="" the="" first="" letter="" is="" a="" lowercase="" english="" letter.="" ·="" next,="" it="" contains="" a="" sequence="" of zero="" or="" more of="" the="" following="" characters:="" lowercase="" english="" letters,="" digits,="" and="" colons.="" ·="" next,="" it="" contains="" a="" forward="" slash="" '/'.="" ·="" next,="" it="" contains="" a="" sequence="" of one="" or="" more of="" the="" following="" characters:="" lowercase="" english="" letters="" and="" digits.="" ·="" next,="" it="" contains="" a="" backward="" slash="" '\'.="" ·="" next,="" it="" contains="" a="" sequence="" of one="" or="" more lowercase="" english="" letters.="" ="" given="" some="" string,="" s,="" we="" define="" the="" following:="" ·="" s[i..j] is="" a="" substring="" consisting="" of="" all="" the="" characters="" in="" the="" inclusive="" range="" between="" index i and="" index j.="" ·="" two="" substrings, s[i[1]..j[1]] and s[i[2]..j[2]],="" are="" said="" to="" be distinct if="" either i[1]="" ≠="" i[2] or j[1]="" ≠="" j[2].="" ="" for="" example,="" your="" command="" line="" is="" abc:/b1c\xy.="" valid="" command="" substrings="" are:="" abc:/b1c\xy="" bc:/b1c\xy="" c:/b1c\xy="" abc:/b1c\x="" bc:/b1c\x="" c:/b1c\x="" ="" there="" are="" six="" valid="" commands="" that="" may="" be="" parsed="" from="" that="" one="" command="" string.="" ="" function="" description="" complete="" the="" function="" commandcount="" in="" the="" editor="" below.="" the="" function="" must="" return="" an="" array="" of="" integers,="" each="" representing="" the="" number="" of="" valid="" command="" strings="" in="" commands[i].="" ="" commandcount="" has="" the="" following="" parameter(s):="" commands[commands[0],...commands[n-1]]: ="" an="" array="" of="" strings="" ="" constraints="" ·="" 1="" ≤="" n="" ≤="" 50="" ·="" each="" character="" of commands[i]="" ∈="" [a-z,0-9,/,\,:]="" ·="" each |commands[i]|="" ≤="" 5="" ×=""> 'abb') as the closer one. the distance here denotes the euclidean distance on the plane: difference in x plus difference in y. for example, there are n = 3 cities, c = [c1, c2, c3] at locations x = [ 3, 2, 1] and y = [3, 2, 3], so points (3,3), (2,2) and (1,3). our queries are q = [c1, c2, c3]. the nearest city to c1 is c3 which shares a y value (distance = (3-1) + (3-3) = 2). city c2 does not have a nearest city as none shares an x or y with c2, so this query would return none. a query of c3 would return c1 based on the first calculation. the return array after all queries is [c3, none, c1]. function description complete the function closeststraightcity in the editor below. the function must return an array of m strings, where the ith element of this array denotes the answer to the i th query. closeststraightcity has the following parameter(s): c[c[0],...c[n-1]]: an array of strings x[x[0],...x[n-1]]: an array of integers y[y[0],...y[n-1]]: an array of integers q[q[0],...q[m-1]]: an array of strings constraints · 1 ≤ n, m ≤ 105 · 1 ≤ x[i], y[i] ≤ 109 · 1 ≤ | q[i] |, | c[i] | ≤ 10 · each character of all c[i] and q[i] ∈ ascii[a-z] · all city name values, c[i], are unique · all cities have unique coordinates question 5: dangerous script if you've ever looked at an assembly language dump of an executable file, you know that commands come in the form of hexadecimal digits that are grouped by the processor into instructions. it is important that the parsing be done correctly or code will not be executed as expected. wrong parsing is the basis for return oriented programming, a method of causing mahem. you have developed a program in a new scripting language. of course, it requires accurate parsing in order to perform as expeced, and it is very cryptic. you want to determine how many valid commands can be made out of your lines of script. to do this, you count all of the substrings that make up a valid command. each of the valid commands will be in the following format: · the first letter is a lowercase english letter. · next, it contains a sequence of zero or more of the following characters: lowercase english letters, digits, and colons. · next, it contains a forward slash '/'. · next, it contains a sequence of one or more of the following characters: lowercase english letters and digits. · next, it contains a backward slash '\'. · next, it contains a sequence of one or more lowercase english letters. given some string, s, we define the following: · s[i..j] is a substring consisting of all the characters in the inclusive range between index i and index j. · two substrings, s[i[1]..j[1]] and s[i[2]..j[2]], are said to be distinct if either i[1] ≠ i[2] or j[1] ≠ j[2]. for example, your command line is abc:/b1c\xy. valid command substrings are: abc:/b1c\xy bc:/b1c\xy c:/b1c\xy abc:/b1c\x bc:/b1c\x c:/b1c\x there are six valid commands that may be parsed from that one command string. function description complete the function commandcount in the editor below. the function must return an array of integers, each representing the number of valid command strings in commands[i]. commandcount has the following parameter(s): commands[commands[0],...commands[n-1]]: an array of strings constraints · 1 ≤ n ≤ 50 · each character of commands[i] ∈ [a-z,0-9,/,\,:] · each |commands[i]| ≤ 5 × 105.>