aboutsummaryrefslogtreecommitdiff
path: root/challenge-345/eric-cheung/python/ch-1.py
blob: fffcde2be1decb1ec44b653a7a2f15e6c44b2187 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## arrInts = [1, 3, 2]  ## Example 1
## arrInts = [2, 4, 6, 5, 3]  ## Example 2
## arrInts = [1, 2, 3, 2, 4, 1]  ## Example 3
## arrInts = [5, 3, 1]  ## Example 4
arrInts = [1, 5, 1, 5, 1, 5, 1]  ## Example 5

arrOutput = []

for nIndx, nElem in enumerate(arrInts):
    bIsPeak = False

    if nIndx == 0 and nElem > arrInts[nIndx + 1]:
        bIsPeak = True
    elif nIndx == len(arrInts) - 1 and nElem > arrInts[nIndx - 1]:
        bIsPeak = True
    elif nElem > arrInts[nIndx - 1] and nElem > arrInts[nIndx + 1]:
        bIsPeak = True

    if bIsPeak:
        arrOutput.append(nIndx)

print (arrOutput)