Tap here to switch tabs
Problem
Submissions

Problem: Beautiful Towers II

Try to solve the Beautiful Towers II problem.

Statement

You are given a 00 indexed integer array maxHeights of length nn.

Your task is to construct an array heights of length nn such that:

  • 1≤1 \leq heights[i] ≤\leq maxHeights[i] for all 0≤i<n0 \leq i < n.

  • heights forms a mountain array, meaning there exists an index ii such that:

    • heights[j] ≤\leq heights[j + 1] for all 0≤j<i0 \leq j < i

    • heights[k] ≥\geq heights[k + 1] for all i≤k<n−1i \leq k < n - 1

Return the maximum possible sum of elements in heights for any valid configuration.

Constraints:

  • 1≤n==1 \leq n == maxHeights.length ≤105\leq 10^5

  • 1≤1 \leq maxHeights[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Beautiful Towers II

Try to solve the Beautiful Towers II problem.

Statement

You are given a 00 indexed integer array maxHeights of length nn.

Your task is to construct an array heights of length nn such that:

  • 1≤1 \leq heights[i] ≤\leq maxHeights[i] for all 0≤i<n0 \leq i < n.

  • heights forms a mountain array, meaning there exists an index ii such that:

    • heights[j] ≤\leq heights[j + 1] for all 0≤j<i0 \leq j < i

    • heights[k] ≥\geq heights[k + 1] for all i≤k<n−1i \leq k < n - 1

Return the maximum possible sum of elements in heights for any valid configuration.

Constraints:

  • 1≤n==1 \leq n == maxHeights.length ≤105\leq 10^5

  • 1≤1 \leq maxHeights[i] ≤109\leq 10^9