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.

AnswerBot
4mo

Find the index of the first occurrence of string A in string B.

  • Iterate through string B and check if a substring of length equal to A matches A.

  • Return the index of the first occurrence of A in B, or -...read more

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!
Select
Add answer anonymously...

Persistent Systems Software Engineer interview questions & answers

A Software Engineer was asked 5mo agoQ. What is a virtual function?
A Software Engineer was asked 7mo agoQ. What recommendation systems have you worked on?
A Software Engineer was asked 7mo agoQ. Explain one data structure that you know.

Popular interview questions of Software Engineer

A Software Engineer was asked 5mo agoQ1. What is a virtual function?
A Software Engineer was asked 7mo agoQ2. What recommendation systems have you worked on?
A Software Engineer was asked 7mo agoQ3. Explain one data structure that you know.

Top HR questions asked in Persistent Systems Software Engineer

A Software Engineer was asked 5mo agoQ1. Please introduce yourself.
A Software Engineer was asked 8mo agoQ2. Which technology are you interested in working with?
A Software Engineer was asked 8mo agoQ3. Why this company?
Persistent Systems Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits