Designer PDF Hackerrank Solution

9 min read

Designer PDF Hackerrank Solution


CODE



#include <bits/stdc++.h>
using namespace std;
int main(){
int height[26];
string s;
for(int i=0;i<26;i++){
cin>>height[i];
}
cin>>s;
int l;
l=s.length();
int h=0;
int temp;
int local;
for(int i=0;i<l;i++){
char c=s[i];
temp=int(c);
temp=temp-97;
local=height[temp];
if(local>=h){
h=local;
}
}
cout<<l*h<<endl;
}
view raw designerpdf hosted with ❤ by GitHub



PROBLEM

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

PDF-highighting.png

There is a list of  character heights aligned by index to their letters. For example, 'a' is at index  and 'z' is at index . There will also be a string. Using the letter heights given, determine the area of the rectangle highlight in  assuming all letters are  wide.


Example

 

The heights are  and . The tallest letter is  high and there are  letters. The hightlighted area will be  so the answer is .

Function Description

Complete the designerPdfViewer function in the editor below.

designerPdfViewer has the following parameter(s):

  • int h[26]: the heights of each letter
  • string word: a string

Returns

  • int: the size of the highlighted area

Input Format

The first line contains  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

  • , where  is an English lowercase letter.
  •  contains no more than  letters.

Sample Input 0

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

9

Explanation 0

We are highlighting the word abc:

Letter heights are  and . The tallest letter, b, is  high. The selection area for this word is .

Note: Recall that the width of each character is .

Sample Input 1

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

28

Explanation 1

The tallest letter in  is  at . The selection area for this word is .

Men' fashion , Dating Tips , Relationship Advice

You may like these posts

  • PROBLEMGiven five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and …
  • Equalize the Array Hackerrank SolutionCODE Given an array of integers, determine the minimum number of elements to delete to leave only elements of equal value.ExampleDe…
  •  Electronics Shop Hackerrank SolutionCODE A person wants to determine the most expensive computer keyboard and USB drive that can be purchased with a give budget. Given pric…
  • Designer PDF Hackerrank SolutionCODE PROBLEMWhen a contiguous block of text is selected in a PDF viewer, the selection is highlighted with a blue rectangle. In this PDF viewer…
  •  CODE : Given an array of integers, find the longest subarray where the absolute difference between any two elements is less than or equal to .ExampleThere are two subar…

Post a Comment