Be the first user to complete this post
|
Add to List |
255. Print all substrings of a given string
Objective: Given a string write an algorithm to print all the possible sub strings.
Example:
String input = “abcd”; Output: Possible sub strings – a a b a b c a b c d b b c b c d c c d d Approach:
- Use nested loops.
- Outer loops will decide the starting point.
- First inner loops will decide the group size. Starting from 1 and goes up string character array size.
- Most inner loop will create the sub strings and print it.
- See the code below for more understanding.
Output:
a a b a b c a b c d b b c b c d c c d d