Daptiv Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Pseudo Code:

string word1 = <<input>>
string word2 = <<input>>
int lengthWord1 = NumberOfChar(Word1)
int lengthWord2 = NumberOfChar(Word2)
int loop = (lengthWord1<lengthWord2)?lengthWord1:lengthWord2
//First replace the common number of characters.
for(int i=0;i<loop;i++)
{
  replaceCharacter(word1[i],word2[i])
}

//If word2 is still longer , insert those extra characters.
for(int i=lengthWord1;i<lengthWord2;i++)
{
  insertCharacter(word1[i],word2[i])
}

//If word2 is smaller than word1 , delete those extra characters.
for(int i=lengthWord2;i<lengthWord1;i++)
{
  deleteCharacter(word1[i]);
}

- KRS June 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Doesn't work!

For example:
String1: ABCMIXABC
String2: MIX

Your code would delete replace all the characters first:

String1: MIXMIXABC
Then delete operation would delete all remaing chars
Total 9 ops...Optimal 6 ops

- Sorcerer June 24, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is a classing DP problem:
Google: Edit distance algorithm

- sorcerer June 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

allisons.org/ll/AlgDS/Dynamic/Edit/

- Anonymous June 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Algorithm:

1) First trace the string to find out whether given word2 is present in word in as in the same order.

Ex: word1 : MIXABCMIX
Word2 : ABC

word1: AMIXBMIXC
Word2: ABC

If after tracing, if the answer is yes, then we can use delete operation. It will take max of 6 operations..

2) If after tracing, if the answer is no, then we can check for the length of the word2. If the length is greater than word1, then we can use replace till the end of word1 and then insert till the end of word2.

3) If the length is less than word1, then we can use replace till end of word 2 and then delete till the end of word1.

- Kalai June 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Algo:

int countSteps(String w1, String w2, int steps){
if (w1 or w2 have length 0)
   then return length of w1(if w2 is of zero length) or vice-versa
   // this is basically the number of insert/delete character steps to make 

else
   if(0th character of both strings are equal)
   then return countSteps(w1[1..n], w2[1..m], steps);
   // current characters match in both strings, so go on to the rest of the string
   else
     find minimum of the following three:
     //replace character
     int steps1 = 1+countSteps(w1.substring(1), w2.substring(1), steps);
     //delete character
     int steps2 = 1+countSteps(w1.substring(1), w2, steps);
     //append character
     int steps3 = 1+countSteps(w1, w2.substring(1), steps);
     return steps+ minStep;
}

- Animesh July 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Solve the longest subsequence problem... then take the sum of the max of respective chunks of chars between each pair of matching chars..

- ashok gupta October 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is the use of dictionary here?

- AlienOnEarth January 07, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More