Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Designer PDF Viewer in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To Algorithm
The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.
Advantages of Algorithms:
- It is easy to understand.
- Algorithm is a step-wise representation of a solution to a given problem.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.
Link for the Problem – Designer PDF Viewer – Hacker Rank Solution
Designer PDF Viewer – Hacker Rank Solution
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:
![Designer PDF Viewer in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 2 PDF-highighting.png](https://s3.amazonaws.com/hr-challenge-images/22869/1471640108-6c01750b16-PDF-highighting.png)
![Designer PDF Viewer in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 3 image 77](https://technorj.com/wp-content/uploads/2021/12/image-77.png)
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
![Designer PDF Viewer in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 4 image 80](https://technorj.com/wp-content/uploads/2021/12/image-80.png)
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
![Designer PDF Viewer in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 5 image 78](https://technorj.com/wp-content/uploads/2021/12/image-78.png)
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
![Designer PDF Viewer in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 6 image 79](https://technorj.com/wp-content/uploads/2021/12/image-79.png)
Designer PDF Viewer – Hacker Rank Solution
import java.util.Scanner; /** * @author Techno-RJ * */ public class DesignerPDFViewer { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a[] = new int[26]; for (int i = 0; i < 26; i++) { a[i] = sc.nextInt(); } int maxHeight = 0; String word = sc.next(); for (int i = 0; i < word.length(); i++) { int index = word.charAt(i) - 'a'; if (a[index] > maxHeight) { maxHeight = a[index]; } } System.out.println(maxHeight * word.length()); sc.close(); } }