Designer PDF Viewer

Designer PDF Viewer

When you select a contiguous block of text in a PDF viewer, the selection is highlighted with a blue rectangle. In this PDF viewer, each word is highlighted independently. For example:

In this challenge, you will be given a list of letter heights in the alphabet and a string. Using the letter heights given, determine the area of the rectangle highlight in mm2 assuming all letters are 1mm wide.

For example, the highlighted word = torn. Assume the heights of the letters are t = 2, o = 1, r = 1 and n = 1. The tallest letter is 2 high and there are 4 letters. The hightlighted area will be 2 * 4 = 8mm2 so the answer is 8.

Function Description

Complete the designerPdfViewer function in the editor below. It should return an integer representing the size of the highlighted area.

designerPdfViewer has the following parameter(s):

  • h: an array of integers representing the heights of each letter
  • word: a string

Input Format

The first line contains 26 space-separated integers describing the respective heights of each consecutive lowercase English letter, ascii[a-z].

The second line contains a single word, consisting of lowercase English alphabetic letters.

Constraints

  • 1 <= h[?] <= 7, where ? is an English lowercase letter.
  • word contains no more than 10 letters.

Output Format

Print a single integer denoting the area in mm2 of highlighted rectangle when the given word is selected. Do not print units of measure.

Sample Input 0

1
2
1 3 1 3 1 4 1 3 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
abc

Sample Output 0

1
9

Explanation 0

We are highlighting the word abc:

Letter heights are a = 1, b = 3 and c = 1. The tallest letter, b, is 3mm high. The selection area for this word is

.

Note: Recall that the width of each character is 1mm.

Sample Input 1

1
2
1 3 1 3 1 4 1 3 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7
zaba

Sample Output 1

1
28

Explanation 1

The tallest letter in zaba is z at 7mm. The selection area for this word is .


Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Complete the designerPdfViewer function below.
function designerPdfViewer(h, word) {
let { code, values } = new Array(26).fill(0).reduce((target, value, index) => {
target['values'][String.fromCharCode(target['code'])] = h[index];
target['code']++;

return target;
}, { code: 97, values: new Object() });

let { height, max } = [...`${word}`].reduce((target, value, index) => {
target['height'] = values[word.charAt(index)];
target['max'] = Math.max(target['max'], target['height']);

return target;
}, { height: 0, max: 0 });

return (word.length * max);
}
Buy Me A Coffee

Comments

10Days of JS 30Days of Code Algorithm Android Debug Bridge Android Debugging Basic for Web Blog Browsers Chrome으로 Android Debugging 방법 Correctness and the Loop Invariant hackerrank solution in javascript Debug Tools Development Environment in MacOS ES6 Front-End Funny String of Algorithms hackerrank solution in javascript Funny String of Algorithms hackerrank solution in typescript Generator Github Page with Hexo Github Pages HackerRank HackerRank in a String of Algorithms hackerrank solution in javascript HackerRank in a String of Algorithms hackerrank solution in typescript Hexo Hexo Icarus theme Hexo 블로그 만들기 Hexo+Github How Browsers work Insertion Sort - Part 1 hackerrank solution in javascript Insertion Sort - Part 2 hackerrank solution in javascript JS Library JavaScript Level1 Level2 Loops MacOS 개발 환경 설정하기 Mobile web Debugging Node.js Pangrams of Algorithms hackerrank solution in javascript Pangrams of Algorithms hackerrank solution in typescript Problem Solving Programmers Quicksort 1 - Partition hackerrank solution in javascript React RoadMap Running Time of Algorithms hackerrank solution in javascript Safari Debugging Safari Technology Preview Settings Sorting String Strings Strong Password of Algorithms hackerrank solution in javascript TypeScript blog iPhone Safari Debugging 방법 insertion sort 모바일 웹 디버깅 아이폰 사파리를 디버깅하는 방법 안드로이드 디버그 브리지 안드로이드 디버깅하는 방법
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×