Interview Questions

158. Given 2 strings S1 and S2, Check the first charaster that is repeated in S2.

Microsoft Interview Questions and Answers


(Continued from previous question...)

158. Given 2 strings S1 and S2, Check the first charaster that is repeated in S2.

Question:
Given 2 strings S1 and S2, Check the first charaster that is repeated in S2.


maybe an answer:


If the question is: "Get the first character from s1 that is repeated in s2." (otherwise, reformulate the question and/or give a sample), then:
-Assume ASCII.
-Create a array a[128] where you set the frequency of the characters from s2.
-For every char in s1, check if the frequency is >= 2.
-O(n+m)



maybe an answer2:


1. Create a new string S3 = S1 + S2;
2. Iterate through char in S3;
3. Find index of each char from S3 in S2 and S3.
4. If index from S2 is !=1 && 2 index are not same them return that character.

(Continued on next question...)

Other Interview Questions