aboutsummaryrefslogtreecommitdiff
path: root/challenge-075/abigail/node/ch-2.js
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-07-08 20:39:53 +0200
committerAbigail <abigail@abigail.be>2021-07-09 01:35:21 +0200
commit22c000b4f7870e2ee0cb1dbfd349dbcfc5ac4752 (patch)
tree3448d88bf75552676518a22c538aca16a9248e8c /challenge-075/abigail/node/ch-2.js
parent1f9fd3507cfe52a7e394838835f2dd9958100db0 (diff)
downloadperlweeklychallenge-club-22c000b4f7870e2ee0cb1dbfd349dbcfc5ac4752.tar.gz
perlweeklychallenge-club-22c000b4f7870e2ee0cb1dbfd349dbcfc5ac4752.tar.bz2
perlweeklychallenge-club-22c000b4f7870e2ee0cb1dbfd349dbcfc5ac4752.zip
Node.js solutions for week 075
Diffstat (limited to 'challenge-075/abigail/node/ch-2.js')
-rw-r--r--challenge-075/abigail/node/ch-2.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-075/abigail/node/ch-2.js b/challenge-075/abigail/node/ch-2.js
new file mode 100644
index 0000000000..64b04898ad
--- /dev/null
+++ b/challenge-075/abigail/node/ch-2.js
@@ -0,0 +1,43 @@
+#!/usr/local/bin/node
+
+//
+// See ../README.md
+//
+
+//
+// Run as: node ch-2.js < input-file
+//
+
+ require ('readline')
+. createInterface ({input: process . stdin})
+. on ('line', line => {
+ let heights = line . split (" ") . map (_ => +_)
+ let max_height = Math . max (... heights)
+
+ let max_area = 0
+ let i, h
+ for (h = 1; h <= max_height; h ++) {
+ let cur = 0
+ let max = 0
+ for (i = 0; i < heights . length; i ++) {
+ if (heights [i] >= h) {
+ cur ++
+ }
+ else {
+ if (max < cur) {
+ max = cur
+ }
+ cur = 0
+ }
+ }
+ if (max < cur) {
+ max = cur
+ }
+
+ let area = max * h
+ if (max_area < area) {
+ max_area = area
+ }
+ }
+ console . log (max_area)
+})