1646. Get Maximum in Generated Array Easy
1/**
2 * [1646] Get Maximum in Generated Array
3 *
4 * You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way:
5 *
6 * nums[0] = 0
7 * nums[1] = 1
8 * nums[2 * i] = nums[i] when 2 <= 2 * i <= n
9 * nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n
10 *
11 * Return the maximum integer in the array nums.
12 *
13 * Example 1:
14 *
15 * Input: n = 7
16 * Output: 3
17 * Explanation: According to the given rules:
18 * nums[0] = 0
19 * nums[1] = 1
20 * nums[(1 * 2) = 2] = nums[1] = 1
21 * nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2
22 * nums[(2 * 2) = 4] = nums[2] = 1
23 * nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3
24 * nums[(3 * 2) = 6] = nums[3] = 2
25 * nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3
26 * Hence, nums = [0,1,1,2,1,3,2,3], and the maximum is max(0,1,1,2,1,3,2,3) = 3.
27 *
28 * Example 2:
29 *
30 * Input: n = 2
31 * Output: 1
32 * Explanation: According to the given rules, nums = [0,1,1]. The maximum is max(0,1,1) = 1.
33 *
34 * Example 3:
35 *
36 * Input: n = 3
37 * Output: 2
38 * Explanation: According to the given rules, nums = [0,1,1,2]. The maximum is max(0,1,1,2) = 2.
39 *
40 *
41 * Constraints:
42 *
43 * 0 <= n <= 100
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/get-maximum-in-generated-array/
49// discuss: https://leetcode.com/problems/get-maximum-in-generated-array/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn get_maximum_generated(n: i32) -> i32 {
55 0
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_1646() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.