Leetcode Problem 1646. Get Maximum in Generated Array

1646. Get Maximum in Generated Array

Leetcode Solutions

Approach: Using Division

  1. Initialize an array nums of size n+1 with nums[0] = 0 and nums[1] = 1 if n is at least 1.
  2. Initialize a variable maximumValue to keep track of the maximum value found so far. If n is 0, return 0.
  3. Iterate from index 2 to n. a. If i is even, set nums[i] to nums[i/2]. b. If i is odd, set nums[i] to nums[i/2] + nums[i/2 + 1]. c. Update maximumValue if nums[i] is greater than the current maximumValue.
  4. Return maximumValue.
UML Thumbnail

Approach: Naive Solution

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...