1129. Get Maximum in Generated Array

EasyDynamic Programming1D DP

An array nums of length n+1 is generated by: nums[0]=0, nums[1]=1, nums[2i]=nums[i], and nums[2i+1]=nums[i]+nums[i+1] for valid i. Given n, return the maximum value in nums. The input is JSON {n}.

Input: JSON {n}.

Output: Integer — the maximum generated value.

Examples

Example 1
Input: {"n":7}
Output: 3
Explanation: The generated array peaks at 3.
Example 2
Input: {"n":2}
Output: 1
Explanation: Maximum is 1.
Example 3
Input: {"n":0}
Output: 0
Explanation: Only zero.

Constraints

Asked by

AmazonGoogle
Solve this problem in the editor →