![]() ![]() If the find() method returns -1, exit the loop.Ĭ. Find the index of the K character in test_str starting from the index position using the find() method.ī. Method #5: Using the string method find() and string slicing.ġ-Initialize the input string test_str, the character to find K, and the Nth occurrence N.Ģ-Initialize a variable index to 0 and a variable count to 0.Ī. This is because the algorithm only stores the index of Nth occurrence of K and the extracted substring in memory, and these variables have constant size regardless of the input size. ![]() The loop runs N times and, in each iteration, it searches for the next occurrence of K in the substring of test_str, which has an average length of K.Īuxiliary Space: O(1), which means it uses a constant amount of extra memory to execute. Time Complexity: O(N*K), where N is the value of N and K is the average length of the substring between two occurrences of K in the test_str.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |