Hackerrrank best solution for Designer PDF viewer

Here is a simple and easiest way to implement this function in c++: 



int designerPdfViewer(vector<int> h, string word) {

    vector<int> height;
    for(int i=0; i<word.length(); i++){
        char ch= word.at(i);
        int l=ch-97;
        cout<<l<<" ";
        height.push_back(h[l]);
    }
    int max=*max_element(height.begin(), height.end());
    return max*word.length();
}

Comments

Popular posts from this blog

Varibale sized arrays in c++