Print Words Vertically

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Given a string s. Return all the words vertically in the same order in which they appear in s.
Words are returned as a list of strings, complete with 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.
LeetCode Problem - 1324
import java.util.*;
class Solution {
// This method prints the vertical representation of a given string.
public List<String> printVertically(String s) {
// Initialize a list to store the vertical representation.
List<String> ans = new ArrayList<>();
// Split the input string into an array of words.
String[] sArray = s.split(" ");
// Convert the array to a list to facilitate finding the maximum length string.
List<String> sArrayList = Arrays.asList(sArray);
// Find the maximum length string in the list.
String maxLengthString = Collections.max(sArrayList, Comparator.comparing(String::length));
int maxLengthStringLen = maxLengthString.length();
// Iterate through each character position vertically.
for (int i = 0; i < maxLengthStringLen; i++) {
StringBuilder sb = new StringBuilder();
// Iterate through each word in the array.
for (int j = 0; j < sArray.length; j++) {
// If the current word has characters left, append the character to the StringBuilder.
if (i < sArray[j].length()) {
char c = sArray[j].charAt(i);
sb.append(c);
}
// If the current word is shorter, append a space.
else {
sb.append(" ");
}
}
// Remove trailing spaces and add the result to the output list.
String stringAns = sb.toString().replaceAll("\\s+$", "");
ans.add(stringAns);
}
return ans;
}
}




