Sort by

recency

|

2716 Discussions

|

  • + 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();
    }
    
  • + 1 comment
        public static int designerPdfViewer(List<int> h, string word)
        {
            var maxHeight = 1;
            foreach(var c in word) {
                var alphabetIndex = GetAlphabetIndex(c);
                var characterHeight = h[alphabetIndex];
                
                if(characterHeight > maxHeight) {
                    maxHeight = characterHeight;
                }
            }
            
            return maxHeight * word.Length;        
        }
        
        public static int GetAlphabetIndex(char character)
        {
            character = char.ToUpper(character); // Convert to uppercase for consistency
    
            return character - 'A'; // 'A' becomes 0, 'B' becomes 1, etc.
        }
    
  • + 0 comments

    js solution

    javascript
    function designerPdfViewer(h, word) {
      // Write your code here
    
      // data setup for character(s) and height(s)
      const letters = [];
      for (let index = 97; index < 123; index++) {
        letters.push({
          char: String.fromCharCode(index),
          height: h[index - 97],
        });
      }
      // find height
      let heightArray = [];
      for (let index = 0; index < word.length; index++) {
        const element = word.toLowerCase()[index]; // index 0 = a , 1 = b, 2 = c
        const findHeight = letters.find((letter) => letter.char === element);
        heightArray.push(findHeight.height);
      }
    
      // calculate
      const maxHeight = heightArray.sort((a, b) => b - a)[0];
      return maxHeight * word.length;
    }
    
  • + 0 comments

    Python3 Using list comprehension

    def designerPdfViewer(h, word):
        # Write your code here
        letters = 'abcdefghijklmnopqrstuvwxyz'
        width = len(word)
        index_list = [letters.index(x) for x in word]
        length = max([h[x] for x in index_list])
        return width*length
    
  • + 0 comments

    Simple Java Code to Understand

     public static int designerPdfViewer(List<Integer> h, String word) {
        
            Map<Character,Integer> map = new HashMap<>();
            Character ch = 'a';
            for(int i=0;i<h.size();i++){
                map.put(ch, h.get(i));
                
                if(ch == 'z'){
                 break;   
                }
                ch++;
            }
            
            char[] chArray = word.toCharArray();
            List<Integer> itr = new ArrayList<>();
            for(Character chr : chArray){    
                itr.add(map.get(chr));
            }
            
            int highestValue = Collections.max(itr);
            int n = itr.size();
            
            int areaOfRech = highestValue * n;
            
            return areaOfRech;
    
        }