462. Count Cycling Workout Plans
Count Cycling Workout Plans

A fitness app stores the resistance levels of a cycling session in resistanceLevels, in stage order. Create workout plans by keeping some stages without changing their order or resistance levels.

A valid plan contains at least three stages. Its resistance levels strictly increase to one peak, then strictly decrease. Both an increase and a decrease are required.

Count all valid plans. Different selections of stage positions count separately, even when their resistance levels are identical.

Method Signature

int countWorkoutPlans(List<Integer> resistanceLevels)
  • resistanceLevels: The resistance level of each stage in the original session.
  • Return the number of valid plans modulo 1,000,000,007, or 0 if none exist.

Constraints

  • The list must be non-null and contain only non-null integers.
  • Resistance levels may repeat, but adjacent levels in a selected plan cannot be equal.
  • If resistanceLevels.size() < 3, return 0.
  • The result satisfies 0 ≤ result < 1,000,000,007.

Examples

Example 1

Method call: countWorkoutPlans(resistanceLevels = List.of(4, 7, 10, 6))

Output: 4

Explanation: The valid plans have levels [4, 7, 6], [4, 10, 6], [7, 10, 6], and [4, 7, 10, 6].

Example 2

Method call: countWorkoutPlans(resistanceLevels = List.of(4, 4, 9, 6, 6))

Output: 4

Explanation: Every valid plan has levels [4, 9, 6]. There are two choices for the stage with level 4 and two choices for the stage with level 6, giving four different selections.

Example 3

Method call: countWorkoutPlans(resistanceLevels = List.of(15, 11, 7, 3))

Output: 0

Explanation: The resistance levels only decrease, so no selected plan can include an increase before its peak.



Please use Laptop/Desktop or any other large screen to add/edit code.