Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms
      • 10
        Basic Dynamic Programming
      • 11
        Recursion
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
        Heap
      • 17
        Hashing
      • 18
        Graph Representation

  • Finding the peak

    You are given an array of n integers. You are asked to find the rightmost peak element in that array. We consider an element to be a peak if it’s greater or equal to two of its neighbors ().

    Input

    The first line of the input contains the number n (3 ≤ n ≤ ). The second line contains n integers representing the array a, where each element ().

    Output

    The program should print the value of the rightmost peak element. In case it’s impossible to find a peak, the program should print Impossible.

    Examples

    Input
    Output
    5 7 20 0 8 7
    8
    6 0 2 -1 4 5 7
    2
    3 1 2 3
    Impossible
     

    Constraints

    Time limit: 1 seconds

    Memory limit: 512 MB

    Output limit: 1 MB

    To check your solution you need to sign in
    Sign in to continue