Tap here to switch tabs
Problem
Submissions

Problem: Incremental Memory Leak

med
30 min
Try to solve the Incremental Memory Leak problem.

Statement

You are given two integers memory1 and memory2 representing the initial available memory in two memory sticks.

Starting at second 11, memory is allocated every second as follows:

  • At second ii, ii bits of memory are allocated from the stick that currently has more available memory.

  • If both sticks have an equal amount of available memory, the memory is allocated from the first stick memory1.

If neither memory stick has at least ii bits of available memory at second ii, the program crashes immediately.

Return an array containing three integers: [crashTime, memory1Left, memory2Left], representing the exact second at which the program crashes, along with the remaining available memory in memory1 and memory2 respectively.

Constraints:

  • 0≤0 \le memory1, memory2 ≤231−1\le 2^{31} - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Incremental Memory Leak

med
30 min
Try to solve the Incremental Memory Leak problem.

Statement

You are given two integers memory1 and memory2 representing the initial available memory in two memory sticks.

Starting at second 11, memory is allocated every second as follows:

  • At second ii, ii bits of memory are allocated from the stick that currently has more available memory.

  • If both sticks have an equal amount of available memory, the memory is allocated from the first stick memory1.

If neither memory stick has at least ii bits of available memory at second ii, the program crashes immediately.

Return an array containing three integers: [crashTime, memory1Left, memory2Left], representing the exact second at which the program crashes, along with the remaining available memory in memory1 and memory2 respectively.

Constraints:

  • 0≤0 \le memory1, memory2 ≤231−1\le 2^{31} - 1