![]() |
VOOZH | about |
Given a string str and an array of words word[], the task is to find whether str is a prefix string of word[].
Examples:
Input: str = "indiaismycountry",
word[] = {"india", "is", "my", "country", "and", "i", "love", "india"}
Output: true
Explanation: String str can be made by concatenating "india", "is", "my" and "country" together.Input: str = "indianism",
word[] = {"india", "is", "my", "country", "and", "i", "love", "india"}
Output: false
Explanation: It is impossible to make str using the prefixes of the word array.
Approach: This is a simple implementation related problem. Follow the steps mentioned below:
Below is the C++ program to implement the above approach-
True
Time Complexity: O(N), N is the size of the word array.
Space Complexity: O(M) where M is the length of str