In this HackerRank Designer PDF Viewer problem There is a list of 26 character heights aligned by index to their letters. For example, 'a' is at index 0, and 'Z is at index 25. There will also be a string. Using the letter heights given, determine the area of the rectangle highlight in mm x mm assuming all letters are 1mm wide.

HackerRank Designer PDF Viewer problem solution


Problem solution in Python programming.

#!/bin/python3

import sys
import string

h = [int(h_temp) for h_temp in input().strip().split(' ')]
word = input().strip()

w_len = len(word)
st = string.ascii_lowercase
max_h = 0

for ch in word:
    i = st.index(ch)
    max_h = max(max_h, h[i])

ans = max_h*w_len

print(ans)


Problem solution in Java Programming.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.stream.*;

public class Solution {

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int[] c = new int[26];
    for (int i = 0; i < 26; ++i) {
      c[i] = in.nextInt();
    }
    String w = in.next();
    int maxH = 0;
    for (char letter : w.toCharArray()) {
      if (c[letter - 'a'] > maxH) maxH = c[letter - 'a'];
    }
    System.out.println(maxH*w.length());
  }



}


Problem solution in C++ programming.

#include <bits/stdc++.h>

using namespace std;

int a[42];
char s[1231212];

int main() {
  for (int i = 0; i < 26; i++) {
    scanf("%d", a + i);
  }
  scanf("%s", s);
  int h = 0;
  int w = 0;
  for (int i = 0; s[i]; i++) {
    w++;
    h = max(h, a[s[i] - 'a']);
  }
  printf("%d\n", h * w);
  return 0;
}


Problem solution in C programming.

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int n = 26;
    int *h = malloc(sizeof(int) * n);
    for(int h_i = 0; h_i < n; h_i++){
       scanf("%d",&h[h_i]);
    }
    char* word = (char *)malloc(512000 * sizeof(char));
    scanf("%s",word);
    
    int len = (int) strlen(word);
    int maxh = 0;
    //printf("%i", len);
    for (int c = 0; c < len; c++){
          if(h[word[c]-97] > maxh){
              maxh = h[word[c]-97];
          }
    }
    printf("%i\n", maxh*len);
    return 0;
}


Problem solution in JavaScript programming.

process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {
  h = readLine().split(' ');
  h = h.map(Number);
  var word = readLine();
  var letters = word.split("");
  var wordLen = letters.length;
  var tallest = 0;
  // console.log(h[letters[1].charCodeAt(0) - 97])
  for(z = 0; z < wordLen; z++){
    if(h[letters[z].charCodeAt(0) - 97] > tallest){
      tallest = h[letters[z].charCodeAt(0) - 97];
    }
  }
  console.log(tallest * wordLen)
  
}