public String justify(String[] words, int i, int j, int L) {
    	StringBuilder sb = new StringBuilder();
        sb.append(words[i]);
        
    	if(i+1 < j) {
    		int len = 0;
            for(int k = i; k < j; k++) len += words[k].length();
            
            int blanks = (L - len) / (j - i - 1);
            int extra = L - len - blanks * (j - i - 1);
            if(j == words.length) {
            	blanks = 1;
            	extra = 0;
            }
            
            char[] blk = new char[blanks];
            for(int k = 0; k < blanks; k++) blk[k] = ' ';
            
            for(int k = i + 1; k < j; k++) {
            	sb.append(blk);
            	if(extra > 0) {
            		sb.append(' ');
            		extra--;
            	}
            	sb.append(words[k]);
            }
    	} 
        while(sb.length() < L) sb.append(' ');
        return sb.toString();
    }