Skip to content

Commit 66954e3

Browse files
solves designer pdf viewer
1 parent 7859570 commit 66954e3

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ I have also solved other domains on HackerRank that can be viewed at:
9292
| [Picking Numbers](https://www.hackerrank.com/challenges/picking-numbers) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/hackerrank-algorithms/blob/master/src/implimentation/PickingNumbers.java) |
9393
| [Climbing The Leaderboard](https://www.hackerrank.com/challenges/climbing-the-leaderboard) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/hackerrank-algorithms/blob/master/src/implimentation/ClimbingTheLeaderboard.java) |
9494
| [The Hurdle Race](https://www.hackerrank.com/challenges/the-hurdle-race) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/hackerrank-algorithms/blob/master/src/implimentation/TheHurdleRace.java) |
95-
| [Designer PDF Viwer](https://www.hackerrank.com/challenges/designer-pdf-viewer) | Easy | |
95+
| [Designer PDF Viewer](https://www.hackerrank.com/challenges/designer-pdf-viewer) | Easy | |
9696
| [Utopian Tree](https://www.hackerrank.com/challenges/utopian-tree) | Easy | |
9797
| [Angry Professor](https://www.hackerrank.com/challenges/angry-professor) | Easy | |
9898
| [Beautiful Days at the movies](https://www.hackerrank.com/challenges/beautiful-days-at-the-movies) | Easy | |
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// https://www.hackerrank.com/challenges/designer-pdf-viewer/problem
2+
3+
package implimentation;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.Scanner;
8+
9+
public class DesignerPdfViewer {
10+
private static final Scanner scanner = new Scanner(System.in);
11+
12+
public static void main(String[] args) {
13+
Map<Character, Integer> alphabetHeights = getAlphabetHeights();
14+
String word = scanner.next();
15+
System.out.println(area(word, alphabetHeights));
16+
}
17+
18+
private static int area(String word, Map<Character, Integer> alphabetHeights) {
19+
int maxHeight = getMaxHeight(word, alphabetHeights);
20+
return maxHeight * word.length();
21+
}
22+
23+
private static int getMaxHeight(String word, Map<Character, Integer> heights) {
24+
int result = 0;
25+
for (int index = 0 ; index < word.length() ; index++) {
26+
char character = word.charAt(index);
27+
result = Math.max(result, heights.get(character));
28+
}
29+
return result;
30+
}
31+
32+
private static Map<Character, Integer> getAlphabetHeights() {
33+
Map<Character, Integer> heights = new HashMap<>();
34+
for (char character = 'a' ; character <= 'z' ; character++) {
35+
heights.put(character, scanner.nextInt());
36+
}
37+
return heights;
38+
}
39+
}

0 commit comments

Comments
 (0)