-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSolution.java
More file actions
39 lines (33 loc) · 1.14 KB
/
Solution.java
File metadata and controls
39 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package Practice.Algorithms.Implementation.DesignerPdfViewer;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Solution {
private static int designerPdfViewer(int[] h, String word) {
// Build Map of letters to heights
final String alphabet = "abcdefghijklmnopqrstuvwxyz";
Map<Character, Integer> charHeights = new HashMap<>();
// String.charAt(int i) is constant time.
for (int i = 0; i < alphabet.length(); i++) {
charHeights.put(alphabet.charAt(i), h[i]);
}
// Find max height
int max = 0;
for (char c : word.toCharArray()) {
int height = charHeights.get(c);
max = (height > max) ? height : max;
}
return word.length() * max;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] h = new int[26];
for (int h_i = 0; h_i < 26; h_i++) {
h[h_i] = in.nextInt();
}
String word = in.next();
int result = designerPdfViewer(h, word);
System.out.println(result);
in.close();
}
}