diff options
Diffstat (limited to 'challenge-218/eric-cheung/python/ch-1.py')
| -rwxr-xr-x | challenge-218/eric-cheung/python/ch-1.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-218/eric-cheung/python/ch-1.py b/challenge-218/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..8c79d7a99d --- /dev/null +++ b/challenge-218/eric-cheung/python/ch-1.py @@ -0,0 +1,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)
|
