HackerRank Solution: Designer PDF Viewer

Sakshi Singh
1 min readApr 17, 2019

--

import java.io.*;

import java.math.*;

import java.security.*;

import java.text.*;

import java.util.*;

import java.util.concurrent.*;

import java.util.regex.*;

public class Solution {

// Complete the designerPdfViewer function below.

static int designerPdfViewer(int[] h, String word) {

char ch[] = word.toCharArray();

int n = ch.length;

int max = 0;

for(int i=0;i<n;i++)

{

int k = (int)ch[i] — 97;

if(max < h[k])

max = h[k];

}

int res = max * n;

return res;

}

private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) throws IOException {

BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv(“OUTPUT_PATH”)));

int[] h = new int[26];

String[] hItems = scanner.nextLine().split(“ “);

scanner.skip(“(\r\n|[\n\r\u2028\u2029\u0085])?”);

for (int i = 0; i < 26; i++) {

int hItem = Integer.parseInt(hItems[i]);

h[i] = hItem;

}

String word = scanner.nextLine();

int result = designerPdfViewer(h, word);

bufferedWriter.write(String.valueOf(result));

bufferedWriter.newLine();

bufferedWriter.close();

scanner.close();

}

}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sakshi Singh
Sakshi Singh

No responses yet

Write a response