Given a string s.&nbsp;Return&nbsp;all the words vertically in the same order in which they appear in s.
Words are returned as a list of strings, complete with&nbsp;spaces when is necessary. (Trailing spaces are not allowed).
Each word would be put on only one column and that in one column there will be only one word.

&nbsp;
Example 1:

Input: s = "HOW ARE YOU"
Output: ["HAY","ORO","WEU"]
Explanation: Each word is printed vertically. 
 "HAY"
&nbsp;"ORO"
&nbsp;"WEU"


Example 2:

Input: s = "TO BE OR NOT TO BE"
Output: ["TBONTB","OEROOE","   T"]
Explanation: Trailing spaces is not allowed. 
"TBONTB"
"OEROOE"
"   T"


Example 3:

Input: s = "CONTEST IS COMING"
Output: ["CIC","OSO","N M","T I","E N","S G","T"]


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 200
	s&nbsp;contains only upper case English letters.
	It's guaranteed that there is only one&nbsp;space between 2 words.

class Solution:
    def getMaxLen(self, words):
        max_len = 0
        for word in words:
            max_len = max(max_len, len(word))
        return max_len
    
    def printVertically(self, s: str) -> List[str]:
        words = s.split()
        max_len = self.getMaxLen(words)
        
        res = list()
        for i in range(max_len):
            s = ""
            for word in words:
                if i < len(word):
                    s += word[i]
                else:
                    s += " "
            s = s.rstrip()
            res.append(s)
        return res
            
            
        
		
class Solution {
    public List<String> printVertically(String s) {
        s = s.replace(" ",",");
        String str="";
        List<String> a=new ArrayList<>();

        int max=0;
        for(int i =0;i<s.length();i++){
           char ch=s.charAt(i);
            if(ch==','){
                a.add(str);
                max=Math.max(max,str.length());
                str="";
                continue;
            }
            else if(i==s.length()-1){
                str+=ch;
                a.add(str);
                max=Math.max(max,str.length());
                str="";
                continue;
            }
            str+=ch;

        }

        String [] arr=new String[max];
        for(int i =0;i<max;i++){
            arr[i]="";

        }

        for(int i =0;i<a.size();i++){
            String x=a.get(i);

            for(int j=0;j<max;j++){

                if(j<x.length()){
                    arr[j]+=x.charAt(j);
                }
                else{
                    arr[j]+=" ";
                }
            }

        }

        a=new ArrayList<>();
        for(int i=0;i<arr.length;i++){

            String x=arr[i];
            x=trim(x);

            a.add(x);
        }

        return a;
    }

    public String trim(String str) {
        int len = str.length();
        int st = 0;

        char[] val = str.toCharArray();

        while ((st < len) && (val[len - 1] <= ' ')) {
            len--;
        }
        return str.substring(st, len);
    }
}
class Solution {
public:
    vector<string> printVertically(string s) {

        int row = 0, col = 0;

        stringstream sso(s);
        string buffer;

        while (sso >> buffer)
        {
            row++;
            col = max((int)buffer.size(),col);
        }

        vector<vector<char>> matrix(row, vector<char>(col,' '));

        sso = stringstream(s);

        int i = 0;
        while (sso >> buffer)
        {
            for (int j = 0; j < buffer.size(); j++)
                matrix[i][j] = buffer[j];
            i++;
        }

        vector<string> res;
        for (int j = 0; j < col; j++)
        {
            string item;
            for (int i = 0; i < row; i++)
                item.push_back(matrix[i][j]);

            for (int i = item.size()-1; i >= 0; i--)
            {
                if (item[i] != ' ')
                {
                    item.erase(item.begin()+i+1,item.end());
                    break;
                }
            }
            res.push_back(item);
        }

        return res;
    }
};
/**
 * @param {string} s
 * @return {string[]}
 */

 var printVertically = function(s)
{
    let arr = s.split(' '),
        max = arr.reduce((last, curr) => Math.max(last, curr.length), 0),
        ans = [];

    arr = arr.map(el => el + ' '.repeat(max - el.length));

    for (let i = 0; i < max; i++)
    {
        let word = '';

        for (let j = 0; j < arr.length; j++)
            word += arr[j][i];

        ans.push(word.replace(new RegExp('\\s+$'), ''));
    }

    return ans;
};
Print Words Vertically