Statistics

Problem Statement for "Popcorn"

Problem Statement

"Place popcorn bag into microwave and start at full power. After at least 3 kernels have popped, listen until more than T seconds have passed without popping. Remove bag from microwave oven."

We plan to put these instructions on our popcorn bag, with the T replaced by a number. We want to choose T so that at least 75% of the kernels will have popped if the user follows the instructions. A popcorn sample has been tested and we have recorded the time that it took for each kernel to pop. Create a class Popcorn that contains the method quietTime that takes the popTimes of the kernels in the sample as input and returns the smallest T that will yield at least 75%.

Definition

Class:
Popcorn
Method:
quietTime
Parameters:
int[]
Returns:
int
Method signature:
int quietTime(int[] popTimes)
(be sure your method is public)

Notes

  • popTimes are already sorted into non-descending order.
  • If exactly T seconds pass between pops, the user will continue popping.

Constraints

  • popTimes contains between 3 and 50 elements, inclusive.
  • Each element in popTimes is between 1 and 10,000, inclusive.
  • popTimes is in non-descending order.

Examples

  1. {3,4,9,12,13,14,14,18,19,25,27}

    Returns: 4

    The intervals after the 3rd kernel has popped are 3,1,1,0,4,1,6,2. If T were 3, the user would stop at time 17, popping 7 of the 11 kernels which is less than 75%. So make T be 4. The user will stop at time 23, popping 9 of the 11 kernels.

  2. {2,5,19}

    Returns: 0

    The user will stop at time 19, yielding 3 of 3.

  3. {2,5,19,29,30}

    Returns: 10

  4. {2,5,19,29,30,42}

    Returns: 10

  5. {1000,5000,5000,5001}

    Returns: 0

  6. {1000,5000,5000,5001,5002}

    Returns: 1

  7. {1000,5000,5000,5001,5003}

    Returns: 1

  8. {5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5}

    Returns: 0

  9. {1,1,10000,10000,10000}

    Returns: 0

  10. {3,5,12,12,15}

    Returns: 0

  11. {1,1,10000,10000,10000,10000}

    Returns: 0

  12. {1,1,1,10000,10000}

    Returns: 9999

  13. {1,2,100,130,132,135,300,301}

    Returns: 30

  14. {1,2,100,130,132,135,300,301,302}

    Returns: 165

  15. {100,120,130,138,138,142,152,153}

    Returns: 8

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

    Returns: 1

  17. { 3, 4, 5, 15 }

    Returns: 0

  18. { 1, 5, 6, 8, 9 }

    Returns: 2

  19. { 1, 2, 3, 7, 15 }

    Returns: 4

  20. { 1, 2, 3, 30, 31, 32, 33, 34, 35 }

    Returns: 27

  21. { 1, 2, 3, 4, 19, 20, 21, 22, 23, 24, 25 }

    Returns: 15

  22. { 1, 1, 1, 5, 5 }

    Returns: 4

  23. { 1, 2, 3, 4, 5, 10, 18 }

    Returns: 5

  24. { 3, 5, 9 }

    Returns: 0

  25. { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 18 }

    Returns: 1

  26. { 1, 1, 1, 1, 1, 1, 5, 5, 5 }

    Returns: 4

  27. { 1, 1, 1, 2 }

    Returns: 0

  28. { 100, 120, 130, 138, 138, 142, 152, 153 }

    Returns: 8

  29. { 1, 2, 3, 7, 8, 9, 10, 11, 12 }

    Returns: 4

  30. { 3, 5, 8, 9 }

    Returns: 0

  31. { 1, 2, 3, 15 }

    Returns: 0

  32. { 12, 15, 15, 9394 }

    Returns: 0

  33. { 2, 5, 19, 29, 30 }

    Returns: 10

  34. { 1, 1, 1 }

    Returns: 0

  35. { 2, 3, 4, 5 }

    Returns: 0


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: