Implement strstr() Function in C Problem Statement
Given two strings A
and B
, find the index of the first occurrence of A
in B
. If A
is not present in B
, return -1.
Example:
Input:
A = "bc", B = "abcddbc"
Output:
1
Explanation:
The string A
is found at index 1 and 5 (0-based index) in string B
, but we return 1 as it is the first occurrence.
Input:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first and only line of each test case contains two strings A and B, separated by a single space.
Output:
For each test case, print the index of the first occurrence of A in B. If string A is not present in string B then print -1.
Constraints:
1 <= T <= 100
1 <= |A|, |B| <= 5 * 10^4
- Time limit: 1 second
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Be the first one to answer
Add answer anonymously...
Top NetApp Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app