APT: Alcohol

Class

public class Alcohol { public String punish(String[] schedule) { // fill in body of this function } }

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 parties in a given year.

Given a String[] schedule, which represents which group throws a party on each day, return a string of the first group that becomes legally eligible for alcohol probation. Each element of schedule will represent one day. If the same group throws 3 or more parties, it becomes legally eligible for alcohol probation.

If no group becomes legally eligible for alcohol probation, return "".

Notes and Constraints

Examples

  1. 
    {"LSJUMB","SAE","AEP","SAE","LSJUMB","LSJUMB","AEP","LSJUMB"}
    
    Returns: "LSJUMB"
    
    
    LSJUMB throws 4 parties, while SAE and AEP throw only 2. Therefore LSJUMB is the only group that is legally eligible for alcohol probation.

  2. 
    {"LSJUMB","SAE","SAE","LSJUMB","LSJUMB","SAE","AEP","AEP","AEP"}
    
    Returns: "LSJUMB"
    
    All 3 groups throw 3 parties, so they are all eligible for alcohol probation. The order in which they become eligible is "LSJUMB", "SAE", "AEP".

  3. 
    {"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"
    
    
  4. 
    {"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: "A"
    

  5. 
    {"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"
    

  6. 
    {"B","S","W","J","Y","B","H","E","A","V","U","H"}
    
    Returns: ""