Swift | One-Liner | Fastest & Simplest | FULLY EXPLAINED
One-Liner (accepted answer)\n\nclass Solution {\n    func fillCups(_ amount: [Int]) -> Int {\n        max(amount.max()!, amount.reduce(1,+)/2)\n    }\n}\n\n\nSO
**One-Liner (accepted answer)**\n```\nclass Solution {\n    func fillCups(_ amount: [Int]) -> Int {\n        max(amount.max()!, amount.reduce(1,+)/2)\n    }\n}\n```\n\n**SOLUTION EXPLANATION**\n\n**Approach**\n1) First, imagine the three element array is separated into three sorted values: Small, Medium and Large replace Cold, Warm, Hot.\n2) There are two cases to this problem:\n\t**Case 1: Largest element is at least the size of the two other elements combined.** (`Medium + Small <= Large`): \n\tSubtract the combined middle and smaller elements from the largest. These will pair up with the subtracted units, one per second. The remaining value of the largest will reduce by one unit every second. Since both slices of the largest element go away one unit per second, it doesn\'t matter what size or proportion of the slices are, the largest value is the number of seconds it will take for the cups to get filled up, so return that value.\n\t\n\t**Case 2: Largest element is smaller than the other two elements combined.** (`Medium + Small > Large`)\n\tThe difference between `(Medium - Small) < Large` (otherwise, Medium would become Large).  We\'ll remove one unit at a time from Large and remove a pairing unit from the largest of Medium and Small values. When Large is exhausted, the difference between Medium and Small will be zero or one. So, the total number of seconds is determined by paring up all units of the three values (plus the odd-case). We can calculate this total number by adding up the original three values, add one to expose the odd-case and divide the sum by 2 (pairs) to get the number of seconds required to fill the cups.  \n\n3) If we don\'t sort the array, we don\'t have access to Small, Medium or Large. This is OK, between the two cases, we calculate both of them and return the larger of the two values. When Case 1 is the case, the largest value in the array is at least the size of the calculation in Case 2, so return that. When Case 2 is the case, the largest value in the array doesn\'t contribute as much as half of all three values, so we can use the `max()` operator between the two cases to determine which case is active.
[]