-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathwaterBlocks.js
More file actions
40 lines (36 loc) · 1.16 KB
/
waterBlocks.js
File metadata and controls
40 lines (36 loc) · 1.16 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
/////////////////////////////////////////////////////////////
// Water Blocks
// ---------------------------------------------------------
// You are given an input array whose each element represents
// the height of a line towers. The width of every tower is 1.
// It starts raining. How much water is collected between the towers?
//
// Ex.
//
// Water blocks:
// Input: [3,2,5,2,1,3]
// Output: 4
// Visualization:
// #
// #
// #-#--#
// ####-#
// ######
//
// '-' is water
// '#' is a block
/////////////////////////////////////////////////////////////
var waterBlocks = function (blocks) {
// TODO: Implement
};
//////////////////////////////////////////////////
// TEST CASES
//////////////////////////////////////////////////
console.log('Pass? ', waterBlocks([1,5,2,3,5,6]) === 5);
console.log('Pass? ', waterBlocks([1,5,2,3,5,6]) === 5);
console.log('Pass? ', waterBlocks([10,10,10,10]) === 0);
console.log('Pass? ', waterBlocks([0]) === 0);
console.log('Pass? ', waterBlocks([0,0,10,0,0]) === 0);
console.log('Pass? ', waterBlocks([0,1,2,3,4,5]) === 0);
console.log('Pass? ', waterBlocks([5,4,3,2,1,0]) === 0);
console.log('Pass? ', waterBlocks([10,0,10]) === 10);