Determining the existence of a substring is a straightforward task. A simple approach involves implementing a nested loop to check if the substring can be formed.
What is a substring?
A substring is a contiguous sequence of characters within a string. In other words, it's a subset of characters taken from a larger string without changing their order. For example, consider the string "hello." Some of its substrings include "h," "he," "hell," "hello," "e," "el," and so on.
Therefore we need to check if the string S(fractional part) is a substring of the Sni(Name of the person). To do that, We will first run a loop which will start from 0 to the difference of the two strings. Why’s that? Casuse otherwise it will go out of bounds, giving us runtime error. Then, well run another loop from 0 to fractional part length.
After that we will check if the fractional part character and the people name character matches or not. We can use a if condition for that. If it matches we increase the counter, else we break it.
If all characters match, then the substring exists.

The time complexity of this approach is O(n^2), where n is the length of the main string and m is the length of the substring. This is because the nested loop iterates over all possible substring positions in the main string.

Statistics

100% Solution Ratio
sourov.cseEarliest, 5M ago
munyim.3725Fastest, 0.0s
Rakin.1859Lightest, 5.9 MB
Shahriar.888Shortest, 628B
Toph uses cookies. By continuing you agree to our Cookie Policy.