Given two strings, str1 and str2, the task is to print the indices(Consider, indices starting from 0) of occurrence of str2 in str1. If no such index occurs, print “NONE”.
Input : GeeksforGeeks Geeks Output : 0 8 Input : GFG g Output : NONE
A simple solution is to check all substrings of given string one by one. If a substring matches, print its index.
Time Complexity : O(n * n)
An efficient solution is to KMP string matching algorithm.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count maximum occurrence of subsequence in string such that indices in subsequence is in A.P.
- Find the Nth occurrence of a character in the given String
- Find the starting indices of the substrings in string (S) which is made by concatenating all words from a list(L)
- Rearrange given string to maximize the occurrence of string t
- Reverse the substrings of the given String according to the given Array of indices
- Program to count occurrence of a given character in a string
- Lexicographically smallest string which differs from given strings at exactly K indices
- Arrange a binary string to get maximum value within a range of indices
- Minimize the length of string by removing occurrence of only one character
- Count occurrence of a given character in a string using Stream API in Java
- Python | Replacing Nth occurrence of multiple characters in a String with the given character
- Generate two output strings depending upon occurrence of character in input string.
- Generate two output strings depending upon occurrence of character in input string in Python
- Find the occurrence of the given binary pattern in the binary representation of the array elements
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- String Range Queries to find the number of subsets equal to a given String
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Given a string and an integer k, find the kth sub-string when all the sub-strings are sorted according to the given condition
- Find the character in first string that is present at minimum index in second string
- Find the count of palindromic sub-string of a string in its sorted form
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.