Tap here to switch tabs
Problem
Submissions

Problem: Beautiful Towers I

Try to solve the Beautiful Towers I problem.

Statement

You are given an integer array heights of length n.

A configuration of towers is defined as beautiful if it can be represented by an array result of length n that satisfies the following conditions:

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

  • result forms a mountain shape, meaning there exists a peak index pp where 0≤p<n0 \leq p < n such that:

    • result[i] ≤\leq result[i + 1] for all 0≤i<p0 \leq i < p

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

Return the maximum possible sum of heights among all beautiful tower configurations.

Constraints:

  • 1≤1 \leq n ==== heights.length ≤103\leq 10^3

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Beautiful Towers I

Try to solve the Beautiful Towers I problem.

Statement

You are given an integer array heights of length n.

A configuration of towers is defined as beautiful if it can be represented by an array result of length n that satisfies the following conditions:

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

  • result forms a mountain shape, meaning there exists a peak index pp where 0≤p<n0 \leq p < n such that:

    • result[i] ≤\leq result[i + 1] for all 0≤i<p0 \leq i < p

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

Return the maximum possible sum of heights among all beautiful tower configurations.

Constraints:

  • 1≤1 \leq n ==== heights.length ≤103\leq 10^3

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