#K78822. Wave Pattern Detection

    ID: 35172 Type: Default 1000ms 256MiB

Wave Pattern Detection

Wave Pattern Detection

You are given a sequence of integers. Your task is to determine whether the sequence forms a wave pattern. A wave pattern is defined as a sequence that strictly increases until it reaches a single peak and then strictly decreases thereafter. Note that the sequence must have at least one increasing transition before the peak and at least one decreasing transition after the peak. Sequences with less than two integers or without a proper peak are not considered wave patterns.

Definition:

  • The sequence must start with a strictly increasing segment.
  • The transition from increasing to decreasing must happen exactly once; once the sequence starts decreasing, it must continue to do so.
  • If there is no valid peak or if adjacent elements are equal, the sequence is not considered a valid wave pattern.

For example:

  • [1, 3, 5, 4, 2] is a valid wave pattern.
  • [3, 2, 1] is not a valid wave pattern because it never increases.
  • [1, 2, 3, 4, 5, 4, 3, 2, 1] is a valid wave pattern.
  • [1, 1, 2, 3, 2, 1, 1] is not a valid wave pattern because of repeated adjacent values.

inputFormat

The input is provided via standard input (stdin). The first line contains an integer n, representing the number of elements in the sequence. The second line contains n space-separated integers representing the sequence.

outputFormat

The output should be printed to standard output (stdout) as either 'True' if the sequence forms a wave pattern, or 'False' otherwise.## sample

5
1 3 5 4 2
True