
Asked in NetApp
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.

AnswerBot
4mo
Implement the strstr() function in C to find the index of the first occurrence of one string in another.
Iterate through the main string and check if the substring matches at each position.
Return the i...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at NetApp
Q. Define IP tables.
Q. Write a program to traverse a linked list
Q. In a knockout football tournament with n teams, how many matches need to be play...read more
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for NetApp Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

