Sort by

recency

|

2739 Discussions

|

  • + 0 comments

    Python3

    ` def designerPdfViewer(h, word): # Write your code here

    return max([h[(ord(c) - ord('a'))] for c in word]) * len(word)
    

    `

  • + 0 comments
    def designerPdfViewer(h, word):
        # Write your code here
        max_h = max([h[ord(char) - ord('a')] for char in word])
        
        return max_h * len(word)
    
  • + 0 comments
    def designerPdfViewer(h, word):
        # Write your code here
        
        letter_dict = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7,  'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
        
        word_split = list(word)
        max_h = 0
        
        for i in word_split:
            
            index = letter_dict.get(i)
            
            if h[index] > max_h:
                max_h = h[index]
                
        
        return max_h * len(word)
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/tRUU2pSf8fI

    int designerPdfViewer(vector<int> h, string word) {
        int mx = 0;
        for(int el : word) if(h[el - 'a'] > mx) mx = h[el - 'a'];
        return mx * 1 * word.size();
    }
    
  • + 0 comments

    Kotlin:

    fun designerPdfViewer(h: Array<Int>, word: String): Int {
        var max=0
        word.forEach { 
            var count=0
            for(i in 'a'..'z'){
                if(it==i){
                    if(h[count]>max) max=h[count]
                    break
                }
                count++
            }
         }
         return word.length*max
    }