Statistics

Problem Statement for "OrderingTakeout"

Problem Statement

You want to order takeout from a nearby restaurant. The roads in your town do not align to a grid, however, they can be represented as a graph. You live at node 0. You want to order from a restaurant that is nearby, however you are willing to travel a little extra distance if it means getting a better meal. As such, you are willing to consider any restaurant that is no more than 10 minutes drive further than the closest restaurant. From those restaurants you consider, you select the one with the highest rating.

You are given the int[] rating with as many elements as there are nodes in the graph. If rating[i] is 0, it indicates that there is no restaurant at node i. If rating[i] is positive, there is a restaurant at node i and this is its rating.

You are also given the distance between nodes of your graph in the int[]s startNode, endNode, and dist. These arrays correspond to each other: for each i, there is a bidirectional road that connects nodes startNode[i] and endNode[i], with a travel time of dist[i] minutes in either direction.

Return the index of the highest-rated node meeting the distance requirement. If multiple restaurants are tied for the highest rating, return the smallest among their node numbers.

Definition

Class:
OrderingTakeout
Method:
bestSelection
Parameters:
int[], int[], int[], int[]
Returns:
int
Method signature:
int bestSelection(int[] rating, int[] startNode, int[] endNode, int[] dist)
(be sure your method is public)

Notes

  • You may assume that all roads are bi-directional, and have the same travel time in either direction.

Constraints

  • rating will contain between 2 and 50 elements, inclusive.
  • Each element of rating will be between 0 and 100, inclusive.
  • rating[0] will be 0.
  • startNode will contain between 1 and 100 elements.
  • startNode, endNode and dist will each contain the same number of elements.
  • Each element of startNode and endNode will be between 0 and Len(rating) - 1, inclusive.
  • At most only one road will be defined between any start and end node (and there will be no self-loops).
  • Each element of dist will be between 1 and 10, inclusive.
  • There will be at least one node with rating greater than 0 that can be reached from node 0.

Examples

  1. { 0, 1, 2, 3 }

    { 0, 0, 0 }

    { 1, 2, 3 }

    { 5, 6, 7 }

    Returns: 3

    We live at the center of town, and there's three roads leaving our house, each going to a different restaurant. They are a 5, 6, or 7 minute drive. The closest restaurant is 5 minutes, so they're all within 15 (5 + 10) minutes drive. Thus, we select the highest rated restaurant, #3.

  2. { 0, 1, 2, 3 }

    { 0, 0, 2}

    { 1, 2, 3 }

    { 5, 6, 7 }

    Returns: 3

    Notice here we no longer have a direct path to the restaurant at node 3. However, the total distance of 13 minutes is still acceptable.

  3. { 0, 1, 2, 3 }

    { 0, 0, 2 }

    { 1, 2, 3 }

    { 5, 8, 10 }

    Returns: 2

    It's 8 minutes to node 2... node 3 would take us 18 minutes, which is too far.

  4. { 0, 1, 0, 3 }

    { 0, 0, 2 }

    { 1, 2, 3 }

    { 5, 6, 10 }

    Returns: 1

    We can get to node 2 in 6 minutes, but there's no restaurant there. Node 3 is too far away. Our only choice is the restaurant at node 1.

  5. { 0, 1, 2, 3 }

    { 0, 2 }

    { 1, 3 }

    { 5, 5 }

    Returns: 1

    Nodes 2 and 3 are connected, but we can't actually get to either of them from node 0. The town road designers didn't do such a great job.

  6. {0,34,27,74,36,24,23,38,34,39,69,96}

    {1,2,0,4,0,0,0,9,1,3,1,1,7,8,1,3,2,2,2,2,8,2,4,3,3,3,3,4,7,4,9,6,7,5,9,6,9,8,9,9}

    {0,0,3,0,5,6,8,0,2,1,5,6,1,1,9,2,4,5,6,7,2,9,3,5,6,7,9,5,4,8,4,5,5,8,5,7,6,7,7,8}

    {3,7,8,2,5,1,8,6,9,7,3,1,1,3,8,4,9,5,1,3,3,6,7,1,10,10,7,9,10,6,10,1,3,2,9,6,9,8,4,3}

    Returns: 3

  7. {0,31,59,24,73,79,87,13,93,61,77,87,76,88,81,64,37,32,24,32,78,1,21,34,32,12,6,20,68,70,86,94,40,49,4,55,68,77,7,33,6,98}

    {0,0,27,0,16,21,35,4,3,34,39,11,15,5,13,5,5,6,7,33,25,8,8,9,9,9,9,36,10,10,28,10,33,36,10,17,18,11,29,11,35,12,12,16,12,29,33,14,16,30,15,34,16,36,16,18,17,17,23,25,18,18,19,26,32,19,26,20,38,25,26,39,22,23,23,34,25,26,26,30,27,27,30,27,29,29,30,33,30,34,38,32,39}

    {19,25,0,34,1,1,2,3,29,3,3,4,4,11,5,25,36,25,17,7,8,29,31,21,25,26,33,9,18,23,10,29,10,10,38,11,11,20,11,32,11,13,15,12,29,13,13,20,15,15,32,15,18,16,39,17,31,39,18,18,29,36,24,19,19,34,20,31,20,21,21,21,33,32,34,24,31,27,29,26,28,29,27,37,31,34,31,30,38,31,31,33,34}

    {7,5,10,6,8,8,6,1,1,6,10,2,9,9,10,10,3,2,1,6,1,9,10,2,2,2,7,7,9,9,3,10,4,3,7,7,10,2,6,10,8,6,5,6,6,3,9,2,9,1,10,1,7,4,6,10,2,3,4,6,2,4,4,4,2,9,7,2,3,5,1,6,6,6,6,9,10,10,5,3,6,1,3,7,4,5,4,4,5,5,2,3,5}

    Returns: 31

  8. {0,37,44,37,49,30,22,5,80,17,57,76,92,17,10,40,54,67,23,68,56,12,93,23,81,98,36,51,22}

    {0,0,1,1,1,1,2,2,2,2,8,14,16,25,3,6,10,4,19,4,4,5,9,11,13,16,18,19,20,21,22,6,6,6,6,6,24,6,7,7,7,7,17,18,24,25,10,13,15,9,9,9,25,14,16,24,11,21,22,14,21,22,23,13,13,13,25,22,23,14,21,20,17,18,19,21,22,19,24,23,25,26,26}

    {3,11,4,13,14,15,3,7,10,24,3,3,3,3,26,4,4,18,4,21,22,7,5,5,5,5,5,5,5,5,5,10,14,17,18,20,6,25,9,10,12,15,7,7,7,7,8,8,8,15,20,23,9,10,10,10,12,11,11,12,12,12,12,14,17,21,13,14,14,24,16,17,22,24,20,19,19,24,20,21,22,22,24}

    {10,1,10,3,10,3,9,10,10,3,8,2,3,5,10,2,4,7,10,7,7,8,1,6,7,6,8,6,4,1,5,7,4,10,10,9,4,10,1,4,7,7,5,3,6,3,5,2,3,7,2,6,5,8,3,3,8,3,10,7,8,5,5,2,2,2,8,10,1,10,8,1,8,5,6,6,4,1,3,5,2,5,4}

    Returns: 25

  9. {0,99,12,3,93,84,72,12,90,98,90,25,55,51,28,30,6,90,17,31,76,21,30,86,54,11,43,94,39,94}

    {0,8,21,0,2,6,1,1,1,1,4,2,7,9,12,15,2,22,27,3,6,10,3,15,18,19,3,3,3,4,4,4,27,9,13,5,21,5,6,6,24,13,14,7,24,8,8,24,12,18,20,9,9,23,26,10,10,14,21,12,13,18,27,15,18,15,15,16,16,16,17,17,23,17,22,26,25,20,21,21,22,25,24}

    {1,0,0,27,1,1,10,13,19,25,2,5,2,2,2,2,19,2,2,5,3,3,11,3,3,3,20,24,27,11,17,26,4,5,5,16,5,25,17,22,6,7,7,20,7,19,21,8,9,9,9,21,22,9,9,13,14,11,11,26,17,13,14,16,15,26,27,19,20,27,18,22,17,26,18,18,19,23,23,27,26,23,26}

    {2,1,3,1,1,6,7,3,3,8,2,8,4,9,10,1,3,2,3,4,1,1,8,5,7,8,6,10,4,4,4,9,1,4,6,8,6,1,5,7,9,9,8,9,4,8,7,10,5,7,7,7,1,9,3,1,3,5,8,8,2,6,7,10,5,2,8,4,5,6,2,10,9,5,5,10,6,8,4,6,10,1,3}

    Returns: 1

  10. {0,44,31,51,12,14,91,35,28,10,30,83,56,48,55,54,20,45,64,40,72,68,44,21,99,16,24,60,17}

    {0,0,0,0,3,1,10,1,18,21,1,12,14,2,2,2,2,3,3,12,3,3,4,10,4,15,4,24,5,11,5,5,17,5,7,6,6,6,24,10,11,8,8,9,9,10,13,17,18,10,20,11,24,18,12,19,22,13,17,14,24,15,22,16,25,17,17,17,17,17,18,25,26,19,19,25,20,20,26,24,25}

    {2,5,16,24,1,9,1,15,1,1,24,2,2,16,18,23,26,9,11,3,14,19,5,4,13,4,21,4,6,5,13,16,5,20,6,13,16,19,7,8,8,20,26,14,18,11,10,10,10,20,11,21,11,12,26,13,13,23,14,23,14,23,16,24,16,20,21,23,24,25,20,18,18,22,23,19,22,25,22,26,26}

    {9,2,6,9,8,3,7,10,9,7,1,9,1,3,2,9,6,7,4,1,1,8,8,10,6,2,8,3,1,6,9,5,9,2,5,5,1,3,6,9,7,5,5,10,1,5,8,9,7,2,4,4,2,7,9,4,6,6,6,2,7,1,8,1,7,5,5,5,7,3,4,3,4,8,5,1,5,2,10,4,4}

    Returns: 24

  11. {0,100,44,100,10,3,13,27,9,25,1,31,30}

    {1,2,3,0,5,0,0,0,2,3,4,1,1,1,8,3,2,5,6,7,2,2,10,5,7,3,9,4,6,4,4,9,4,5,5,9,5,7,6,10,9,7,8,8,10}

    {0,0,0,4,0,8,9,10,1,1,1,5,6,7,1,2,4,2,2,2,8,9,2,3,3,8,3,5,4,7,8,4,10,6,7,5,10,6,9,6,7,10,9,10,9}

    {6,5,3,3,8,2,3,9,10,3,10,10,7,1,2,7,1,4,2,2,9,9,5,2,8,5,9,3,2,1,2,9,8,6,4,8,8,4,7,2,8,9,6,1,8}

    Returns: 1

  12. {0,44,48,86,33,88,90,72,41,69,84,76,7,27,67,94,60,34,87}

    {3,5,0,0,0,0,1,1,1,11,12,2,4,7,8,9,2,14,15,3,6,10,13,3,16,4,4,4,4,14,16,5,13,14,15,16,8,6,10,6,15,8,7,10,16,8,8,8,15,9,15,11,12,13,14,10,11,11,11,11,12,15,16,13,15}

    {0,0,8,12,13,15,2,9,10,1,1,3,2,2,2,2,10,2,2,5,3,3,3,15,3,5,7,10,12,4,4,8,5,5,5,5,6,9,6,12,6,7,9,7,7,9,11,13,8,11,9,10,10,10,10,15,12,13,15,16,14,12,12,16,14}

    {8,10,8,1,10,4,10,9,10,8,10,4,10,3,9,9,4,1,9,7,2,7,1,10,5,9,5,5,2,6,1,9,4,1,10,4,2,10,4,8,9,10,5,10,4,5,10,5,3,2,9,2,7,10,7,4,7,8,7,3,8,7,3,4,4}

    Returns: 15

  13. {0,18,8,84,15,78,20,87,77,4,99,83,63,64,89,89,3,36,88,51,34,56,85,10,93,82,75}

    {1,0,0,0,0,9,10,11,0,13,16,17,0,4,1,9,1,16,3,2,2,2,2,24,14,19,10,4,15,16,4,4,4,23,5,16,5,7,8,9,6,6,17,6,6,7,7,7,14,18,7,7,8,18,20,8,9,10,18,10,11,11,21,11,20,12,13,17,13,22,15,15,15,15,16,18,19,20,17,20,21,23,22,23,22}

    {0,3,4,5,6,0,0,0,12,0,0,0,18,1,8,1,12,1,2,7,10,18,22,2,3,3,4,12,4,4,18,19,22,4,6,5,19,6,6,6,13,14,6,18,23,8,10,13,7,7,22,24,14,8,8,21,17,16,10,20,12,18,11,23,12,21,14,13,18,13,14,16,17,18,18,17,17,17,22,18,18,20,21,22,24}

    {9,10,3,7,6,5,1,6,1,6,6,2,10,4,9,8,3,1,1,3,7,7,1,7,8,1,8,3,10,9,8,10,2,5,8,1,5,8,4,8,9,10,1,2,9,5,8,8,2,8,5,9,6,7,2,7,9,2,4,5,7,5,7,1,1,2,2,4,8,3,7,3,8,10,10,1,9,5,7,1,10,10,8,4,4}

    Returns: 10

  14. {0,63,6,73,76,53,59,84,78,29,60,1,35,42,48,48,8,59,12,80,99,2,89}

    {0,4,12,14,1,1,1,6,8,10,16,9,10,2,15,2,3,8,16,3,8,4,4,4,4,5,9,5,5,5,5,20,6,17,18,7,11,13,20,9,10,8,8,8,10,14,9,18,19,20,11,12,13,19,11,14,20,12,12,16,17,20,18,13,14,14,20,15,15,17,16,18,18,18}

    {3,0,0,0,2,3,5,1,1,1,1,2,2,11,2,20,4,3,3,20,4,10,17,19,20,7,5,11,12,16,17,5,7,6,6,9,7,7,7,8,8,12,14,16,9,9,16,9,9,9,10,10,10,10,12,11,11,14,15,12,12,12,13,20,15,18,14,17,18,16,19,17,19,20}

    {8,4,3,5,10,3,9,9,8,7,5,4,1,9,10,8,7,6,3,10,1,6,1,5,4,8,2,1,2,9,8,5,4,10,4,3,9,5,9,5,8,9,3,4,3,8,10,8,6,6,1,6,1,5,6,5,9,9,2,9,5,3,5,9,1,6,2,4,3,8,8,7,1,9}

    Returns: 20

  15. {0,50,8,59,73,85,25,63,39,58,10,16,100,33,47,32,37,71,17,93,11,74,5,97,76,53,9,67,60,12,49,88,43,42,56,70,100,95,13,57,60,51,67,2}

    {11,0,28,0,0,1,1,22,23,1,34,40,4,2,19,2,2,20,3,30,31,34,3,4,9,15,4,4,4,4,8,5,6,7,29,7,16,8,8,31,37,8,13,9,21,30,32,9,18,31,41,11,21,11,13,12,12,32,12,13,13,33,41,14,35,15,17,19,17,22,24,18,31,24,25,20,23,22,22,22,25,25,28,24,33,33,35,34,28,41,36,37}

    {0,26,0,32,37,17,20,1,1,24,1,1,2,14,2,24,29,3,28,3,3,3,39,8,4,4,17,18,28,38,5,34,21,24,7,38,8,20,26,8,8,41,9,20,9,9,9,39,10,10,10,18,11,41,12,18,25,12,41,25,32,13,13,32,14,16,18,17,21,17,17,23,18,20,20,33,21,31,32,41,23,24,24,29,24,25,26,27,30,32,33,38}

    {1,10,7,8,3,2,4,6,1,6,7,7,6,4,10,1,5,10,5,7,7,10,10,5,10,4,5,9,4,9,6,5,9,1,2,9,4,7,3,6,3,6,3,6,10,6,3,8,9,10,4,1,1,2,3,7,6,2,8,1,7,6,6,6,10,9,8,6,8,10,6,8,7,10,10,3,2,4,7,5,5,3,5,7,3,3,3,2,7,6,3,5}

    Returns: 12

  16. {0,22,58,98,18,83,24,12,12,64,59,54,87}

    {0,0,3,0,5,0,9,2,1,1,1,1,1,1,1,2,4,2,7,8,2,2,4,3,6,7,8,3,3,5,4,7,8,4,10,6,7,8,5,10,7,6,9,10,7,7,7,10}

    {1,2,0,4,0,8,0,1,4,5,6,7,8,9,10,3,2,6,2,2,9,10,3,5,3,3,3,9,10,4,6,4,4,9,4,5,5,5,9,5,6,8,6,6,8,9,10,9}

    {2,10,2,2,1,9,3,10,2,4,2,1,7,4,4,8,8,8,8,8,3,1,5,1,5,8,3,9,2,9,4,1,6,5,1,5,5,7,1,8,6,9,3,6,4,8,2,6}

    Returns: 3

  17. {0,71,50,21,39,38,39,61,9}

    {0,2,3,0,5,6,1,3,4,5,6,2,2,2,2,3,3,3,5,4,5}

    {1,0,0,4,0,0,2,1,1,1,1,3,4,5,6,4,5,6,4,6,6}

    {5,6,2,9,9,3,2,2,3,3,9,2,8,3,2,7,2,3,1,2,2}

    Returns: 1

  18. {0,1,53,71,47,30,94,15,2,19}

    {0,0,0,4,0,0,7,2,1,1,6,7,2,4,2,2,2,4,5,3,3,5,4,7,5,5,7}

    {1,2,3,0,5,6,0,1,3,5,1,1,3,2,5,6,7,3,3,6,7,4,6,4,6,7,6}

    {8,1,9,9,10,7,9,10,8,3,10,3,6,7,1,10,1,9,4,2,10,3,7,7,8,5,2}

    Returns: 6

  19. {0,57,64,65,37,93,53,87,34,17,34,26,64,7,74,43,93,14,67,29,85,29,66,1,53,92,68,72,11,26,91,25,45,80,21,63,12,72,98}

    {8,0,21,29,35,0,1,7,1,1,1,9,2,4,3,3,13,3,3,3,3,13,4,4,4,4,11,18,5,13,31,36,7,12,7,24,7,13,8,8,8,9,9,22,9,9,22,11,18,11,11,12,12,19,26,30,14,20,14,16,16,36,17,17,26,30,17,17,35,19,18,18,19,19,19,19,36,20,31,26,21,23,32,22,23,23,23,32,25,27,30,36,32,35,35}

    {0,17,0,0,0,36,5,1,21,26,36,2,34,3,9,11,3,14,15,28,36,4,14,18,23,32,5,5,20,6,6,6,8,7,13,7,35,8,21,27,31,15,20,9,27,29,10,12,11,19,20,34,35,13,13,13,15,14,27,21,29,16,20,25,17,17,32,33,17,18,23,35,21,29,31,32,19,29,20,21,29,22,22,33,33,35,36,24,31,29,31,30,33,32,34}

    {7,3,1,10,9,4,5,1,4,7,6,1,8,4,1,3,1,9,6,10,8,9,4,5,5,3,9,3,2,1,9,6,8,4,9,5,2,1,8,7,1,10,8,10,7,8,4,2,6,5,1,6,4,8,7,2,4,7,1,10,2,9,10,6,6,4,2,9,1,5,1,2,2,7,4,2,5,9,4,1,3,8,5,9,5,4,3,6,7,9,9,5,1,4,4}

    Returns: 5

  20. {0,4,89,84,22,90,46,23,53,87,30,82,66,58,16,19,63,25,76,17,84,83,30,56,19,91,50,86,90,93,50,84}

    {0,0,0,20,25,0,9,16,23,26,1,1,9,10,13,2,22,3,5,6,18,28,19,11,5,25,14,25,7,10,13,7,7,25,7,8,14,19,8,8,8,9,9,9,14,17,9,12,10,10,17,10,25,29,18,11,11,19,12,12,16,13,13,14,14,14,14,29,15,19,16,16,16,23,17,29,18,20,19,28,20,20,20,21,29,23,24,23,24,28}

    {2,6,15,0,0,27,1,1,1,1,28,29,2,2,2,14,2,4,3,3,3,3,4,5,13,5,6,6,8,7,7,14,18,7,28,10,8,8,20,23,28,10,11,12,9,9,22,10,15,16,10,18,10,10,11,19,29,12,20,23,13,20,22,16,18,23,25,14,18,15,18,19,21,16,27,17,23,19,26,19,22,23,27,24,21,22,22,26,27,26}

    {3,4,8,8,6,6,9,9,4,5,4,4,5,1,3,6,3,6,10,5,7,6,3,2,7,7,6,4,8,3,7,5,4,4,10,9,3,10,9,4,5,6,3,2,3,4,7,2,1,5,10,1,3,5,8,2,2,8,4,4,9,4,5,3,10,3,6,1,5,9,2,2,10,1,5,3,2,2,10,1,8,5,6,4,2,10,3,1,1,5}

    Returns: 29

  21. {0,64,63,49,58,37,99,14,41,22,2,83,81,75,40,59,83,16,10,16,38,13,42,76,49,82,22,87,22,81,70,82,42,75,4,90,24,90,81,61,56,91,50}

    {13,21,27,0,0,10,1,1,8,16,20,28,2,2,37,5,3,3,3,3,11,14,35,37,40,18,6,6,6,7,21,20,24,25,8,32,33,20,28,11,17,11,11,39,13,13,13,35,13,14,38,34,36,15,15,16,17,17,30,24,19,26,19,35,39,20,27,30,20,38,39,20,40,22,23,32,40,26,24,25,26,26,27,27,28,30,32,38,33,37,40}

    {0,0,0,29,31,1,12,36,2,2,2,2,31,36,2,3,6,12,27,33,4,4,4,4,4,6,38,39,40,9,7,8,8,8,31,8,8,9,9,10,11,26,29,11,18,19,33,13,37,16,14,15,15,39,40,21,18,27,17,19,25,19,27,19,19,26,20,20,31,20,20,40,21,23,24,23,23,24,32,27,35,36,29,40,36,38,33,33,40,35,36}

    {6,1,3,3,2,5,2,7,8,8,4,5,1,3,4,9,6,1,5,10,4,5,1,9,2,5,8,7,7,6,5,1,9,6,6,4,2,8,9,8,6,6,6,7,3,6,5,7,8,1,6,9,7,3,4,10,10,2,8,5,5,4,4,2,7,9,1,2,9,4,3,1,7,10,3,2,10,4,1,2,1,3,6,10,8,1,5,9,1,2,5}

    Returns: 35

  22. {0,22,15,55,53,40,49,24,51,16,47,98,21,86,3,89,50,39,27,41,33,75,6,100,17,60,73,50,69,84,3,83,3,91,18,59,46,86,99,72,26,46,96,23,84}

    {26,0,40,2,1,2,29,39,3,3,30,3,4,30,41,5,28,5,14,6,6,38,7,21,18,28,30,8,8,9,9,9,37,41,10,10,30,34,12,12,29,12,40,13,39,42,14,14,20,25,15,40,16,16,28,40,42,23,17,17,17,19,28,18,22,19,25,20,21,40,22,39,24,34,36,39,28,28,29,41,42,37,36,31,32,37,40,35,36,36,41,39,42}

    {0,31,0,1,25,19,2,2,21,27,3,38,12,4,4,19,5,34,6,16,34,6,14,7,8,8,8,37,41,17,20,34,9,9,18,24,10,11,24,28,12,38,12,18,13,13,15,29,15,15,39,15,19,21,16,16,16,17,29,35,41,18,18,29,19,27,20,38,27,21,36,23,32,24,24,24,38,39,32,29,29,30,31,38,41,33,33,41,40,41,38,40,39}

    {3,5,1,3,10,6,10,10,1,8,6,7,4,4,1,7,7,2,5,10,7,5,6,6,7,4,1,6,10,2,2,6,8,1,1,6,7,7,9,4,2,1,8,5,7,6,7,10,10,4,8,9,1,7,6,4,3,2,6,8,1,7,10,8,3,4,9,6,10,9,2,2,9,9,1,4,10,7,2,1,6,1,10,9,4,9,4,10,6,4,5,2,10}

    Returns: 23

  23. {0,1,45,98,83,76,98,6,88,20,37,56,37,75,94,65,30,10,28,34,39,51,59,75,36,56,91,10,81,45,28,54,90,99,16,26}

    {6,0,21,6,1,32,2,12,16,2,2,9,3,3,16,17,22,3,4,4,4,20,22,23,4,4,8,5,32,8,17,6,6,12,19,28,30,8,8,23,32,9,9,10,21,24,26,11,11,12,22,13,24,13,27,17,21,31,15,31,16,26,16,20,26,27,31,18,18,33,19,19,20,20,21,21,31,32,22,28,22,23,23,23,29,23,25,24,31,33,26,29,29}

    {0,13,0,1,23,1,7,2,2,17,28,3,11,12,3,3,3,29,11,14,18,4,4,4,25,33,5,27,5,6,6,21,26,7,7,7,7,13,19,8,8,13,32,11,10,10,11,28,31,14,12,23,13,26,13,14,14,14,24,15,25,16,32,17,17,17,17,20,25,18,21,22,28,30,23,24,21,21,23,22,30,24,26,28,23,33,24,33,25,25,33,28,30}

    {10,1,7,3,3,10,6,1,9,3,6,1,6,5,6,4,8,2,3,4,8,5,1,10,3,10,9,9,5,5,5,4,4,8,2,8,10,3,1,1,7,10,6,10,3,3,7,6,6,6,6,10,5,7,5,9,10,9,4,9,8,4,7,9,9,9,7,2,2,3,9,4,6,5,3,10,4,5,1,1,5,9,5,10,1,4,2,6,2,5,6,3,7}

    Returns: 33

  24. {0,62,67,47,90,36,78,15,1,95,85,15,13,27,25}

    {1,3,0,5,0,7,8,0,0,0,0,1,3,1,5,6,7,1,1,10,1,12,3,2,2,2,10,4,5,3,3,9,10,3,4,4,4,6,8,9,10,6,7,7,7,11,12,8,8,10,11,9,10,10,12}

    {0,0,4,0,6,0,0,9,10,11,12,2,1,4,1,1,1,8,9,1,11,1,2,5,7,8,2,3,3,7,8,3,3,12,5,7,11,7,6,6,6,11,8,9,10,7,7,11,12,9,9,12,11,12,11}

    {6,2,4,6,1,8,6,1,4,5,9,6,3,5,4,10,5,8,7,3,9,3,3,7,1,3,2,1,6,7,9,8,8,3,6,10,10,9,6,6,1,3,10,7,7,3,8,2,8,1,5,5,9,3,3}

    Returns: 9

  25. {0,32,43,11,48,52,74,73,44,59,4,49,14,86,27,7,63,56,95,77,31,3,30,36,60,88,80,79,90,87,54,96,7,50,13,92,30,60,30,16,67,8,88,80,55}

    {0,20,0,42,5,7,8,11,24,1,2,2,2,20,2,27,37,42,17,26,3,4,4,5,25,5,27,5,5,6,6,7,8,8,35,9,11,13,21,24,27,10,10,14,11,25,11,12,22,12,13,42,32,14,40,18,15,24,16,16,16,40,16,17,17,18,26,19,20,30,36,40,20,33,23,40,24,33,25,39,42,31,39,30,30,32,32,42,33,33,35,37,41,39}

    {1,0,26,0,1,1,1,1,1,26,11,16,19,2,21,2,2,2,3,3,29,19,30,10,5,26,5,34,42,9,22,16,16,22,8,38,10,10,10,10,10,30,33,11,22,11,36,17,12,32,18,13,14,39,14,15,32,16,26,31,39,16,42,20,36,27,19,30,22,20,20,20,41,21,34,23,30,24,29,26,26,29,29,36,40,34,36,32,35,40,37,38,37,41}

    {7,6,3,2,9,3,4,10,1,4,4,2,8,8,7,8,1,8,10,10,4,5,3,6,7,4,6,5,1,6,6,2,6,6,9,1,8,8,7,10,7,8,1,8,9,9,2,1,8,7,6,9,1,2,8,4,1,10,2,7,1,4,9,8,2,8,2,8,9,7,1,7,3,1,6,4,9,2,2,5,10,7,1,7,9,7,10,5,9,9,6,1,9,3}

    Returns: 31

  26. {0,69,46,32,100,70,4,71,2,20,79,22,22,30,90,49,76,31,28,16,80,47,3,86,77,50,28,26}

    {0,6,8,0,0,0,3,9,1,15,1,1,19,22,2,8,2,2,21,3,6,3,11,16,4,4,4,24,14,5,6,6,6,6,24,7,7,7,17,20,7,8,10,20,8,22,8,25,11,9,9,17,9,9,22,9,9,14,10,16,14,24,11,12,15,16,25,13,24,16,15,25,19,16,17,18,18,19,23,22}

    {2,0,0,17,18,20,1,1,14,1,16,17,1,1,4,2,9,16,2,5,3,10,3,3,8,16,23,4,5,18,8,10,12,14,6,9,11,12,7,7,25,9,8,8,21,8,23,8,9,13,16,9,18,19,9,23,24,10,15,10,11,11,25,14,12,12,12,19,13,14,17,15,16,21,23,20,24,20,20,24}

    {5,9,6,7,9,7,3,4,5,2,9,8,7,6,5,4,10,5,10,5,3,3,10,7,8,9,3,3,10,5,1,9,8,9,1,2,9,5,9,7,5,7,10,3,1,1,2,7,9,8,9,3,5,8,1,8,9,3,4,5,9,1,3,5,9,8,2,2,2,3,7,8,10,1,3,10,6,5,1,10}

    Returns: 4

  27. {0,94,89,87,15,75,22,91,64,86,5,78,91,8,2,26,96,76,34,7,87,91,1,51,62,84}

    {3,0,0,0,10,23,2,4,1,10,16,1,1,23,5,2,2,18,19,22,3,7,11,3,3,23,4,4,16,17,19,20,5,5,12,5,19,5,7,6,6,16,6,6,8,7,7,7,19,10,12,13,17,19,20,23,11,12,9,15,10,18,13,11,16,18,20,11,12,19,13,13,13,17,14,19,22,16,17,22,23,19,23}

    {0,5,6,9,0,0,1,1,6,1,1,21,22,1,2,10,15,2,2,2,6,3,3,12,22,3,6,13,4,4,4,4,7,9,5,15,5,21,6,8,9,6,18,20,7,10,11,18,7,8,8,8,8,8,8,8,9,9,22,10,17,10,11,14,11,11,11,23,14,12,19,20,22,14,21,15,15,18,18,17,18,20,22}

    {8,9,4,10,5,1,2,2,3,9,1,8,8,1,3,5,4,4,7,8,8,7,1,5,8,4,3,9,2,6,10,1,1,2,10,4,2,8,9,4,10,6,3,10,10,10,3,10,5,5,2,3,2,1,3,8,2,2,3,9,1,4,3,2,10,1,2,3,10,10,3,3,8,6,3,7,10,5,7,3,3,2,5}

    Returns: 16

  28. {0,18,6,83,56,86,11,10,31,58,43,28,8,32,83,80,54,83,19,72,55,47,50,3,45,8,64,99,51,46,23,55,97,76,52}

    {20,28,7,12,16,18,1,4,5,8,23,4,9,3,4,4,4,5,5,5,14,19,5,5,5,6,13,6,6,7,13,15,20,7,26,8,8,8,9,24,9,32,11,10,10,29,19,27,11,13,20,21,12,23,26,15,13,26,14,27,14,32,15,15,21,16,16,17,17,19,26,18,32,21,19,25,19,19,20,28,20,32,31,26,24,31,27,25,25,32,27,29}

    {0,0,1,1,1,1,22,2,2,2,2,3,3,28,5,14,25,7,12,13,5,5,24,25,28,12,6,19,27,12,7,7,7,25,7,23,30,32,13,9,29,9,10,18,25,10,11,11,28,12,12,12,22,12,12,13,25,13,17,14,30,14,17,18,15,20,25,24,31,18,18,29,18,19,24,19,28,30,23,20,29,21,22,24,30,24,25,29,32,26,32,28}

    {9,3,10,8,1,6,4,8,3,9,10,6,5,8,5,10,5,4,7,6,4,9,2,8,6,2,10,6,2,3,9,2,1,9,7,5,3,7,8,2,2,4,9,9,10,4,1,1,7,9,5,10,7,8,9,2,10,10,9,3,7,5,7,7,2,5,7,2,8,7,7,1,7,4,10,10,4,8,5,3,2,2,2,6,10,9,9,9,5,4,4,4}

    Returns: 27

  29. {0,61,48,83,72,48,99,23,39,7,82,34,68,44,61,59,86,47,44,12,46,88,70,78,27}

    {0,9,14,15,17,0,10,1,19,22,3,5,2,2,17,22,3,3,8,3,12,16,20,3,22,7,4,4,4,4,4,8,9,5,5,5,21,6,6,7,7,18,10,8,13,8,8,11,9,9,9,18,10,10,11,17,11,12,19,20,14,13,13,20,13,22,14,18,21,16,15,17,19,16,17,17,19,21}

    {4,0,0,0,0,21,1,12,1,1,2,2,8,15,2,2,4,7,3,11,3,3,3,21,3,4,14,15,16,17,22,5,5,14,17,19,5,9,21,9,15,7,8,12,8,17,22,9,12,13,14,9,12,20,13,11,22,16,12,12,13,17,18,13,21,13,15,14,14,15,22,16,16,22,19,20,22,22}

    {1,9,9,5,8,7,1,3,9,6,3,5,2,8,1,5,3,6,2,1,10,5,4,2,7,9,4,4,4,9,1,3,3,2,1,2,6,8,5,3,9,2,5,8,9,2,4,7,7,5,9,10,1,2,8,9,8,3,1,2,3,1,5,2,2,6,2,5,10,10,5,8,6,4,8,4,9,3}

    Returns: 6

  30. {0, 0, 0, 1, 2 }

    {0, 1, 2, 2 }

    {1, 2, 3, 4 }

    {1, 1, 9, 10 }

    Returns: 4

  31. {0, 2, 1 }

    {0, 2 }

    {1, 1 }

    {5, 10 }

    Returns: 1

  32. {0, 1, 2, 3 }

    {0, 0, 0 }

    {1, 2, 3 }

    {5, 6, 7 }

    Returns: 3

  33. {0, 0, 1, 2 }

    {0, 0, 2 }

    {1, 2, 3 }

    {5, 10, 10 }

    Returns: 3

  34. {0, 0, 0, 10, 1 }

    {0, 1, 2, 0 }

    {1, 2, 3, 4 }

    {3, 1, 10, 5 }

    Returns: 3

  35. {0, 5 }

    {0 }

    {1 }

    {5 }

    Returns: 1

  36. {0, 10, 20, 30 }

    {0, 0, 2 }

    {1, 2, 3 }

    {5, 8, 10 }

    Returns: 2

  37. {0, 100, 100, 100 }

    {0, 1, 1 }

    {1, 2, 3 }

    {1, 2, 2 }

    Returns: 1

  38. {0, 0, 0, 0, 20, 0, 0, 0 }

    {0, 1, 2, 3, 4, 5 }

    {1, 2, 3, 4, 5, 6 }

    {10, 10, 10, 10, 10, 10 }

    Returns: 4

  39. {0, 0, 0, 10, 1 }

    {0, 1, 2, 0 }

    {1, 2, 3, 4 }

    {3, 1, 10, 4 }

    Returns: 3

  40. {0, 1, 2, 3 }

    {1, 2, 3 }

    {0, 1, 2 }

    {10, 10, 10 }

    Returns: 2

  41. {0, 1, 0, 2 }

    {0, 0, 2 }

    {1, 2, 3 }

    {1, 2, 9 }

    Returns: 3

  42. {0, 1 }

    {1 }

    {0 }

    {1 }

    Returns: 1

  43. {0, 10, 20, 30 }

    {0, 0, 0 }

    {1, 2, 3 }

    {5, 6, 7 }

    Returns: 3

  44. {0, 10, 20, 30 }

    {1, 2, 3 }

    {0, 1, 2 }

    {10, 10, 10 }

    Returns: 2

  45. {0, 1, 2, 1 }

    {0, 1 }

    {1, 2 }

    {5, 5 }

    Returns: 2

  46. {0, 0, 6, 5 }

    {0, 1, 2 }

    {1, 2, 3 }

    {10, 5, 5 }

    Returns: 2

  47. {0, 10, 0, 30 }

    {0, 0, 2 }

    {1, 2, 3 }

    {5, 6, 10 }

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: