I have an input abcde
. I'm trying to output something like this:
a
ab
abc
abcd
abcde
b
bc
bcd
bcde
c
cd
cde
d
de
e
I can't make a code which is without nested loops. My question is what is the solution of this problem with O(n) time complexity?
My code is given below:
s = "abcde"
for i in range(len(s)):
for x in range(i, len(s) + 1):
a = s[i:x]
if a != "": print(a)