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

arrInterList = sorted(arrInputList)
arrNegInterList = [nElem for nElem in arrInterList if nElem < 0]

arrOutputList = []
if len(arrNegInterList) <= 1:
    arrOutputList = arrInterList[-3:]
else:
    nTempIndx = max(int((len(arrNegInterList) + (0 if len(arrNegInterList) % 2 == 0 else 1)) / 2), 2)

    for nElem in arrNegInterList[:nTempIndx]:
        arrOutputList.append(nElem)

    for nElem in arrInterList[-3 + len(arrOutputList):]:
        arrOutputList.append(nElem)

nProduct = 1
for nElem in arrOutputList:
    nProduct = nProduct * nElem

print (nProduct)