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 assuming all letters are wide.
For example, the highlighted . Assume the heights of the letters are and . The tallest letter is high and there are letters. The hightlighted area will be so the answer is .
Description
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
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.
The second line contains a single word, consisting of lowercase English alphabetic letters.
Output
Print a single integer denoting the area in of highlighted rectangle when the given word is selected. Do not print units of measure.
Question from hackerrank.
Solution in C# -
class Solution {
static int designerPdfViewer(int[] h, string word) {
List<int> lists = new List<int>();
for(int i=0; i<word.Length; i++)
{
int c = word[i] % 97;
lists.Add(h[c]);
}
lists.Sort();
return lists[lists.Count-1] * word.Length;
}
static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int[] h = Array.ConvertAll(Console.ReadLine().Split(' '), hTemp => Convert.ToInt32(hTemp)) ;
string word = Console.ReadLine();
int result = designerPdfViewer(h, word);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
Post a Comment