A server can run three background jobs at once only if their combined memory use is strictly below cap. The memory use of each job is in loads.
Write countTriples(loads, cap) that returns how many groups of three different jobs (three different indexes i < j < k) have loads[i] + loads[j] + loads[k] < cap.
Input: loads = [-2,0,1,3], cap = 2 Output: 2
-2 + 0 + 1 = -1 and -2 + 0 + 3 = 1 are below 2. The other two triples total 2 and 4.
Input: loads = [5,5,5], cap = 15 Output: 0
The only triple totals exactly 15, which is not strictly below.
0 <= loads.length <= 2000-100 <= loads[i] <= 100-300 <= cap <= 300Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #118 Count Triples Under a Cap. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.