Panda Guru LogoPanda
Guru

Salesforce OA

Round 1

Questions:

Question 1

Given a circular array of strings, a startIndex, and a targetString, find the minimum steps to reach the targetString.

Example:

["bat","cat","light","mobile","pen","toy","book"], startIndex=5, target="cat"

Answer: 3 steps.

Question 2

Find the total number of times a string s2 is present in s1 as a subsequence.

Example:

s1 = "batwithcar", s2 = "bar"

Answer: 2 as "bar" is present two times at indexes (0,1,9) and (0,8,9).

Candidate's Approach
  • For Question 1:

    • Use two pointers, one moving left and the other right from startIndex.
    • Handle boundary conditions: if left < 0, set left to last index of the array; if right >= array.length, set right to 0.
    • Keep a variable for step count and break the loop when the target is reached, returning the step count.
  • For Question 2:

    • Started with a recursive solution followed by memoization.
Interviewer's Feedback

No feedback provided.