File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Hackerrank
3
+ * Complete the designerPdfViewer function in the editor below. It should return an integer representing the size of the highlighted area.
4
+ * designerPdfViewer has the following parameter(s):
5
+ * - h: an array of integers representing the heights of each letter
6
+ * - word: a string
7
+ *
8
+ * Constraints:
9
+ * 1. 1 <= h[?] <= 7 where ? is an Englisher lowercase letter
10
+ * 2. word contains no more thant 10 letters
11
+ *
12
+ * This solution got 20 points
13
+ * Problem link: http://hr.gs/vnu
14
+ */
15
+
16
+ /**
17
+ * @param {number[] } h Height of each letter in [a-z]
18
+ * @param {string } word The word to be evaluated to find the area to be highlighted
19
+ * @return {number } Area to be highlighted
20
+ */
21
+ function designerPdfViewer ( h , word ) {
22
+ // Edge case
23
+ if ( ! word || word . length === 0 ) {
24
+ return 0 ;
25
+ }
26
+ const aCharCode = 'a' . charCodeAt ( 0 ) ;
27
+ let maxHeight = - Infinity ;
28
+ for ( let i = 0 ; i < word . length ; i ++ ) {
29
+ const height = h [ word . charCodeAt ( i ) % aCharCode ] ;
30
+ if ( height > maxHeight ) {
31
+ maxHeight = height ;
32
+ }
33
+ }
34
+ return maxHeight * word . length ;
35
+ }
You can’t perform that action at this time.
0 commit comments