Statistics

Problem Statement for "Probation"

Problem Statement

The Stanford Office of Student Affairs has been placing student groups (including the one, the only, the truly incomparable, Leland Stanford Junior University Marching Band) on alcohol probation. However, due to some legal nitpicking, they are only allowed to place a group on alcohol probation if it throws 3 or more parties within 5 days of each other.

Given a String[], schedule, which represents which group throws a party on each day, return a String[] of which groups will be placed on alcohol probation (in the order that they become legally eligible for alcohol probation). Each element of schedule will represent one day. If the same group throws 3 parties within 5 days of each other (that is, day 0, day 2, and day 4 are within 5 days of each other, but day 0, day 2, and day 5 are not) it becomes legally eligible for alcohol probation.

Definition

Class:
Probation
Method:
punish
Parameters:
String[]
Returns:
String[]
Method signature:
String[] punish(String[] schedule)
(be sure your method is public)

Notes

  • Element 0 of schedule represents day 0, element 1 represents day 1, and so on. Thus, each day, there is exactly one group that throws a party.

Constraints

  • schedule will contain between 0 and 50 elements, inclusive.
  • each element of schedule will contain 1 to 10 characters, inclusive.
  • each element of schedule will only contain capital letters [A-Z].

Examples

  1. {"LSJUMB","SAE","AEP","SAE","LSJUMB", "SAE","LSJUMB","AEP","AEP","LSJUMB"}

    Returns: { "SAE" }

    LSJUMB throws parties on days 0, 4, 6, and 9. Since no 3 of these days are within 5 days of each other, they are not eligible for alcohol probation. SAE throws parties on days 1, 3, and 5, which are within 5 days of each other, so they become eligible for alcohol probation. AEP throws parties on days 2, 7, and 8, so they are also not eligible for alcohol probation.

  2. {"LSJUMB","SAE","SAE","LSJUMB", "LSJUMB","SAE","AEP","AEP","AEP"}

    Returns: { "LSJUMB", "SAE", "AEP" }

    All 3 groups throw 3 parties within 5 days of their other parties, so they are all eligible for alcohol probation. The order in which they become eligible is "LSJUMB", "SAE", "AEP".

  3. {"A","B","C","B","A","B", "C","B","A","B","D","D","D"}

    Returns: { "B", "D" }

  4. {"KA","SX","TAXI","TAXI","SX","SX","KA","TAXI", "KA","KA","TAXI","KA","TAXI","ST","KA","KA", "KA","KA","KA","SX","SX","SX","SX","SX"}

    Returns: { "SX", "KA" }

  5. {"A","B","C","C","A","B","C","A", "B","B","C","A","A","B","C","A"}

    Returns: { "C", "B", "A" }

  6. {"D","A","E","C","E","A","B","J","C","A","G", "J","J","I","D","J","B","J","F","E","C","D", "C","C","J","D","H","E","D","I","F","F","C","D"}

    Returns: { "J", "C" }

  7. {"I","F","H","F","A","H","E","H","J","G","C"}

    Returns: { }

  8. {"H","H","I","A","I","A","J","G","C","E", "J","G","H","H","E","H","I","I","D","G", "H","B","D","F","J","I","H","D","H","C", "D","J","C","F","G","D","D","B","F"}

    Returns: { "H" }

  9. {"C","G","F","B","H","D","C","F","J", "B","H","A","I","B","I","I","I","I", "J","J","B","I","D","C","J","C","G", "G","B","B","B","C","J","J","H","F","H"}

    Returns: { "I", "B" }

  10. {"D","H","G","H","J","J","G","F", "B","I","G","I","C","I","F","G", "B","A","I","B","C","A","D","B", "H","J","A","D","A","H","B","F", "B","D","G","D","C","D","C"}

    Returns: { "I", "D" }

  11. {"I","I","A","I","D","H","A","E", "C","C","C","G","A","A","I","G", "A","G","H","B","F","I","F","E", "B","I","D","B","C","B","H","A", "D","A","E","D","J","E","D","A", "C","A","C","A","C","J","B","F","F"}

    Returns: { "I", "C", "A" }

  12. {"H","D","H","J","D","C","C","B", "H","C","A","H","E","E","H","J", "H","E","I","H","H","J","J","E","J"}

    Returns: { "C", "H", "J" }

  13. {"J","I","D","J","E","A","C","E","G", "E","A","J","A","J","C","E","B","F", "B","B","D","G","D","E","G","I","A", "A","I","A","E","C","H","C","C","F","G"}

    Returns: { "B", "A", "C" }

  14. {"A","D","E","I","A","E","F","D", "D","H","D","H","E","H","I","C", "D","C","A","B","B","G","B","A", "E","D","B","E","E","H","F","J", "G","I","F","J","E","F","I","G","J","C"}

    Returns: { "D", "H", "B", "E" }

  15. {"D","B","I","I","I","F","A","E","G","A", "A","D","E","D","D","J","G","H","H","J", "B","J","J","B","C","H","H","F","B","J", "B","C","B","D","F","F","A","F","E","F", "H","H","D","D","I","H","B"}

    Returns: { "I", "A", "D", "J", "B", "F" }

  16. {"B","C","B","B","H","H","J","H","C", "G","D","C","H","F","A","E","J","E", "C","E","H","A","H","A","F","J","B", "J","E","I","A","B","C","J","C","C", "J","E","F","B","A","F","F","E","C"}

    Returns: { "B", "H", "E", "C", "F" }

  17. {}

    Returns: { }

  18. { "A", "A", "A" }

    Returns: { "A" }

  19. { "A", "B", "B", "C", "C", "D", "C", "D", "A", "A", "A" }

    Returns: { "C", "A" }

  20. { "B", "B", "B" }

    Returns: { "B" }

  21. { "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A" }

    Returns: { "A" }

  22. { "A", "A", "B", "B", "B", "A", "A", "A" }

    Returns: { "B", "A" }

  23. { "A", "B", "C", "B", "A", "B", "C", "B", "A", "B", "D", "D" }

    Returns: { "B" }

  24. { "A", "A", "A", "B" }

    Returns: { "A" }


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: