Given a string S of size N, discover the sample of the strings as proven under within the examples.
Examples:
Enter: S = “Geek”
Output: Geek, Gee, Ge, G
Rationalization: Lower one character after every lineEnter: S = “G*g”
Output: G*g, G*, G
Rationalization: Lower one character after every line
Utilizing two Nested loops:
Use the next thought to resolve the issue:
The concept to resolve this downside relies on the truth that now we have to print string N time in several traces and print the string by lowering the size of the string from the tip every time.
So, iterate two nested loops one for printing string into totally different traces for N time and different loop for print the string by lowering the size of the string.
Comply with the under steps to resolve the issue:
- Discover the size of the given string say N
- Run a loop on i from 0 until i < N
- Run nested loop on j from 0 until j < N – i
- Print character on the jth index of the string
- Print the following line character i.e. ‘n’
- Run nested loop on j from 0 until j < N – i
Under is the implementation of the above strategy.
C++
|
Time Complexity: O(N2)
Auxiliary House: O(1)