Given a string S, the duty is to print all phrases with prime size within the given string.
Examples:
Enter: S = “This can be a python programming language”
Output: is
programming
Rationalization: Size of is is 2 and size of programming is 11 each are primesEnter: S = “You might be utilizing geeksforgeeks”
Output: You
are
utilizing
geeksforgeeks
Strategy: To unravel the issue observe the under steps:
- First break up the given string to get an array of house separated strings.
- Begin traversing the phrases from left to proper.
- Calculate the size of every phrase.
- If the size is prime, then print the phrase.
Beneath is the implementation of the above strategy:
Python3
|
Time complexity: O(n * sqrt(x)), the place n is the variety of phrases within the given sentence and x be the size of the biggest string.
Auxiliary House: O(1)