aboutsummaryrefslogtreecommitdiff
path: root/challenge-345/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-10-27 14:35:15 +0000
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-10-27 14:35:15 +0000
commitabe996e9ac2cb8caef4b993c2135a7f0d14bf455 (patch)
tree1543b42b2ad0f71f82d85e59cef798e5b7c6ea3a /challenge-345/eric-cheung/python
parentdd0b42d3cf5d83c2b6d38485422b5778a32f1e6a (diff)
downloadperlweeklychallenge-club-abe996e9ac2cb8caef4b993c2135a7f0d14bf455.tar.gz
perlweeklychallenge-club-abe996e9ac2cb8caef4b993c2135a7f0d14bf455.tar.bz2
perlweeklychallenge-club-abe996e9ac2cb8caef4b993c2135a7f0d14bf455.zip
- Added solutions by Eric Cheung.
- Added solutions by Mark Anderson. - Added solutions by Lubos Kolouch. - Added solutions by Ali Moradi. - Added solutions by Feng Chang. - Added solutions by Andreas Mahnke. - Added solutions by Peter Campbell Smith.
Diffstat (limited to 'challenge-345/eric-cheung/python')
-rwxr-xr-xchallenge-345/eric-cheung/python/ch-1.py23
-rwxr-xr-xchallenge-345/eric-cheung/python/ch-2.py25
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-345/eric-cheung/python/ch-1.py b/challenge-345/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..fffcde2be1
--- /dev/null
+++ b/challenge-345/eric-cheung/python/ch-1.py
@@ -0,0 +1,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)
diff --git a/challenge-345/eric-cheung/python/ch-2.py b/challenge-345/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..5a4b728ca3
--- /dev/null
+++ b/challenge-345/eric-cheung/python/ch-2.py
@@ -0,0 +1,25 @@
+
+## Ref.:
+## https://leetcode.com/problems/last-visited-integers/description/
+
+## arrInts = [5, -1, -1] ## Example 1
+## arrInts = [3, 7, -1, -1, -1] ## Example 2
+## arrInts = [2, -1, 4, -1, -1] ## Example 3
+## arrInts = [10, 20, -1, 30, -1, -1] ## Example 4
+## arrInts = [-1, -1, 5, -1] ## Example 5
+
+## arrInts = [1, 2, -1, -1, -1] ## Example 6
+arrInts = [1, -1, 2, -1, -1] ## Example 7
+
+arrSeen = []
+arrAns = []
+arrMinusOne = []
+
+for nElem in arrInts:
+ if nElem > 0:
+ arrSeen.insert(0, nElem)
+ else:
+ arrAns.append(arrSeen[len(arrMinusOne)] if len(arrMinusOne) < len(arrSeen) else nElem)
+ arrMinusOne.append(nElem)
+
+print (arrAns)