Tap here to switch tabs
Problem
Submissions

Problem: Maximize the Beauty of the Garden

Try to solve the Maximize the Beauty of the Garden problem.

Statement

You are given an integer array flowers of size nn, where flowers[i] represents the beauty of the ii-th flower.

A garden is considered valid if:

  • It contains at least 22 flowers.

  • The first flower and the last flower in the garden have the same beauty value.

You want to produce a valid garden by removing zero or more flowers from the original array flowers while maintaining the relative order of the remaining flowers.

The beauty of a garden is the sum of the beauty values of all its flowers.

Return the maximum possible beauty of a valid garden.

Constraints:

  • 2≤2 \leq flowers.length ≤105\leq 10^5

  • −104≤-10^4 \leq flowers[i] ≤104\leq 10^4

  • It is possible to create a valid garden by removing some (possibly none) flowers.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize the Beauty of the Garden

Try to solve the Maximize the Beauty of the Garden problem.

Statement

You are given an integer array flowers of size nn, where flowers[i] represents the beauty of the ii-th flower.

A garden is considered valid if:

  • It contains at least 22 flowers.

  • The first flower and the last flower in the garden have the same beauty value.

You want to produce a valid garden by removing zero or more flowers from the original array flowers while maintaining the relative order of the remaining flowers.

The beauty of a garden is the sum of the beauty values of all its flowers.

Return the maximum possible beauty of a valid garden.

Constraints:

  • 2≤2 \leq flowers.length ≤105\leq 10^5

  • −104≤-10^4 \leq flowers[i] ≤104\leq 10^4

  • It is possible to create a valid garden by removing some (possibly none) flowers.