-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesignerPdfViewer.cpp
24 lines (21 loc) · 1 KB
/
DesignerPdfViewer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// problem : https://www.hackerrank.com/challenges/designer-pdf-viewer/problem
// soultion O(n*2) ===========================================================
int designerPdfViewer(vector<int> h, string word) {
// for storing bigest value of 'x' char
unsigned int maxValue = 0;
// the idea is making map of all char with their value & then get the bigest one
std::string chars = "abcdefghijklmnopqrstuvwxyz";
// map for our idea :)
std::map<char,unsigned int> chars_map;
// first for-loop , for insert each char with value
for(unsigned int i = 0 ; i < chars.size() ; i += 1){
chars_map.insert({chars[i],h[i]});
}
// second for-loop , for get begest value bettween all chars in map
for(unsigned int i = 0 ; i < word.size() ; i +=1){
if( chars_map[word[i]] > maxValue) maxValue = chars_map[word[i]];
}
// return will be bigest * string size :)
return (maxValue * word.size());
}
// ===========================================================================