Index of First Occurrence Problem Statement
Given two strings A
and B
, determine 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
appears at index 1 and 5 in B
(0-based index), but the first occurrence is at index 1.
Constraints:
1 <= T <= 100
1 <= |A|, |B| <= 5 * 104
- Time limit: 1 second
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Arghya Pal
2y
let a = 'bc';
let b = 'abcddbc';
let bArray = b.split("");
let aArray = a.split("");
console.log(bArray);
var flag = 0;
for(let i=0; i<bArray.length; i++){
if(bArray[i] == aArray[0] && bArray[i+1] == aArray...read more
Help your peers!
Add answer anonymously...
Top Persistent Systems Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Persistent Systems Software Engineer
>
Persistent Systems Software Engineer Interview Questions
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