Problem Statement
Substring
A substring is a contiguous sequence of characters within a string.
Example: "cod" is a substring of "coding". Whereas "cdng" is not as the characters taken are not contiguous
The first and only line of input contains a string without any leading and trailing spaces. All the characters in the string would be in lower case.
Print all the substrings possible, where every substring is printed on a separate line.
Note:
The order in which the substrings are printed does not matter.
Constraints:
0 <= N <= 10^3
Where N is the length of the input string.
Time Limit: 1 second
Sample Input 1:
abc
Sample Output 1:
a
ab
abc
b
bc
c
Sample Input 2:
co
Sample Output 2:
c
co
o
def printSubstrings(string) :
for i in range(len(string)):
for j in range(i+1,len(string)+1):
print(string[i:j])
#Your code goes here.
#main
string = input();
printSubstrings(string)
Comments
Post a Comment