Program to print a string in vertical in Java
Description: You have a string and you need to print its characters vertically, starting from left to right of the string.
An array of characters can be referred to as a string. In this case, the program is built to print the letters vertically, beginning on the left side of the string and moving right. The string's characters are printed one per line. For instance, the string "ABC" has the three letters (or characters) "A," "B," and "C." This letter will now be printed in three distinct vertical lines as:
The small-letter characters will be changed to upper case, and the upper case characters should then be printed. To print the characters in this manner, each character is first accessible using its respective index position (the index starts from 0). The text will be printed in upper case if it is in lower case, and after each character is printed, the cursor should be moved to the next line so that the following character can be printed once more. The string's final character will be reached by repeating this technique.
Time Complexity: This program has an O(n) time complexity, where n is the number of characters in the string.
Space Complexity: This program has an O(n) space complexity, where n is the string's character count.
Print a string in a vertical zigzag manner
The job is to print the supplied string in a vertical zigzag pattern with respect to the given number of rows when given a string, S, of size N and a number of rows, R, as shown in the examples.
Approach: The goal is to determine the distance between the major columns and a step value for the in-between columns in order to print the spaces until the string's final character is reached. To solve this issue, adhere to the methods listed below:
Below is the implementation of the above approach:
Program code in Java
Time Complexity: O(R2*N)
Auxiliary Space: O(1)