1860. Incremental Memory Leak Medium
1/**
2 * [1860] Incremental Memory Leak
3 *
4 * You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.
5 * At the i^th second (starting from 1), i bits of memory are allocated to the stick with more available memory (or from the first memory stick if both have the same available memory). If neither stick has at least i bits of available memory, the program crashes.
6 * Return an array containing [crashTime, memory1crash, memory2crash], where crashTime is the time (in seconds) when the program crashed and memory1crash and memory2crash are the available bits of memory in the first and second sticks respectively.
7 *
8 * Example 1:
9 *
10 * Input: memory1 = 2, memory2 = 2
11 * Output: [3,1,0]
12 * Explanation: The memory is allocated as follows:
13 * - At the 1^st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.
14 * - At the 2^nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.
15 * - At the 3^rd second, the program crashes. The sticks have 1 and 0 bits available respectively.
16 *
17 * Example 2:
18 *
19 * Input: memory1 = 8, memory2 = 11
20 * Output: [6,0,4]
21 * Explanation: The memory is allocated as follows:
22 * - At the 1^st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.
23 * - At the 2^nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.
24 * - At the 3^rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.
25 * - At the 4^th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.
26 * - At the 5^th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.
27 * - At the 6^th second, the program crashes. The sticks have 0 and 4 bits available respectively.
28 *
29 *
30 * Constraints:
31 *
32 * 0 <= memory1, memory2 <= 2^31 - 1
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/incremental-memory-leak/
38// discuss: https://leetcode.com/problems/incremental-memory-leak/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn mem_leak(memory1: i32, memory2: i32) -> Vec<i32> {
44 vec![]
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_1860() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.