You're writing a log buffer for a browser extension. It starts with room for initial entries. When an entry is pushed and the buffer is full, it first grows: its capacity is multiplied by factor, and every entry already stored is copied to the new space, one copy per entry. Then the new entry is written.
Write copyCost(pushes, initial, factor) that returns [copies, capacity]: the total number of entry copies after pushes pushes into an empty buffer, and the capacity at the end.
Input: pushes = 9, initial = 1, factor = 2 Output: [15,16]
The buffer grows at sizes 1, 2, 4, and 8, copying 1 + 2 + 4 + 8 = 15 entries, and ends with room for 16.
Input: pushes = 10, initial = 4, factor = 3 Output: [4,12]
It grows once, from 4 to 12, when the fifth entry arrives, copying 4 entries.
0 <= pushes <= 10^61 <= initial <= 10002 <= factor <= 10Run 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 #8 Growing Buffer Copy Cost. 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.