Question: Question 2 (25 points) Suppose a robot is trying to cross a river. The system provides two suggestion lists like the following: Given: list1 =

 Question 2 (25 points) Suppose a robot is trying to cross

Question 2 (25 points) Suppose a robot is trying to cross a river. The system provides two suggestion lists like the following: Given: list1 = ["swim", "boat", "via bridge A", "airplane"] list2 = ["via bridge B", "swim", "give up"] The robot will pick "swim" [Explain] The robot will pick the solution based on the common suggestion from the two lists. If there is not a common suggestion, it should return null. Additionally, if there are multiple common suggestions in the list, the robot will pick the solution that has the highest sum of the list index. For example, Given: list1 = ["swim", "boat", "via bridge A", "airplane"] list2 = ["via bridge B", "airplane", "swim", "give up"] The robot will pick "airplane" [Explain] both lists have "swim" and "airplane." The index for "swim" in list1 is 0 and in list2 is 2 , thus the sum of them is 2 . On the other hand, the index for "airplane" in list1 is 3 and in list2 is 1 , thus the sum of them is 4. Since the robot should pick the solution which has the highest sum of the list index, it will pick the airplane. If there is a choice tie, you can return any one of them. Finally, please check below for the method signature. public static String findRiverCrossingSolution(ArrayList list1, ArrayList list2)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!