Given a string str as the input. The task is to print the pattern as shown in the example.
Input : str = “geeks”
* s k
In the first line print the first character in the string.
In the second line print the next two characters in reverse order.
In the third line there are not enough characters to print so append *s and print the characters in reverse order.
Input: str = “orange”
e g n
- Initialize an empty list and a variable x with value 1.
- Traverse through the input string str and append the characters to the list.
- If the length of the list is equal to the value of x then
- Print the characters in the list in reverse order.
- Increment the value of x by 1.
- Empty the list
- If the length of the last printed characters is not 0 and it is less than the value of x then append x-length(x) *s and print it in reverse order.
g e e * s k
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program to print a doormat pattern having a string written in the center in Python
- Program to print the pattern 'G'
- Program to print the pattern ‘D’
- Check if a string follows a^nb^n pattern or not
- Program to print Step Pattern
- Program to print window pattern
- Program to print the Zigzag pattern
- Printing string in plus ‘+’ pattern in the matrix
- Count of occurrences of a "1(0+)1" pattern in a string
- Python Program to print digit pattern
- Python Program for KMP Algorithm for Pattern Searching
- Program to Print Pyramid Pattern using numbers
- Program to print reverse character bridge pattern
- Python | Get the smallest window in a string containing all characters of given pattern
- Check if string follows order of characters defined by a pattern or not | Set 1
- Check if string follows order of characters defined by a pattern or not | Set 2
- Check if string follows order of characters defined by a pattern or not | Set 3
- Python - K elements Reversed Slice
- Python | Reversed Split Strings
- Python Program for Rabin-Karp Algorithm for Pattern Searching
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.