MAGMA Interview Question for Software Engineer / Developers






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

1. I could not answer this question. Interviewer explained me the possible answer.

2. str1[] length is n
str2[] length is m

3. find all combinations of str1 i.e 2^n .

e.g 1) n = 2 , str1 = "AB"
possible combinations { "","A", "B","AB" }
total 4 combinationsi.e 2^2
e.g 2) n=3, str1 ="ABC"
Possible combinations {"","A","B","C","AB","AC","BC","ABC" } .
total 8 combinationsi.e 2^3

4. find all combinations of str2 i.e 2^m .

5. now have to match each str1 combination with str2 combination .
If it matches and greater than Previous matched string length, then store it as a best match. Otherwise goto next match.

6. Time complecxity O(2^n * 2^m) = O(2^(m+n) )

- siva.sai.2020 February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Interviewer told me, we can solve this problem in two ways 1. Brute force 2. Dynamic programming . After that he explained Brute Force method .

- siva.sai.2020 February 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How can we find all combinations of a string.... ???

- Rahul March 10, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Isnt this just a Longest Common Subsequence question (unless I am missing something).It has a simple dynamic solution.

- vinod. February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Perform dynamic programming on two strings as below.

Subseq(i,j) = max(Subseq(i,j-1),Subseq(i-1,j),{SubSeq(i,j)+1 if(a[i] == b[j]})

- Messi February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

^I cant make head or tail of this statement. could you please explain a little more?
Thanks.

- Anonymous February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

str1: ABCDEF
str2: ZACYEFX
Largest common sequence : ACEF

Approch:

1#Take two pointer ptr1 and ptr2 pointing to first char of strings(str1 ,str2).
2#check whether both of the pointer pointing to same char.
3#if YES then append the char into a new string 'commenSTR' and move both of the pointer to next char.
4#if NOT
4.1#check pointer PTR2 is pointing to null.If YES move pointer PTR1 to next and PTR2 to first char of STR2.Repeat from step-2.
4.2#check pointer PTR1 is pointing to null.If YES return 'commenSTR'.
4.3#move pointer str2 to next and Repeat from step-2.

- PKT February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

str1: ABCDEF..
if str2 is ZYEFXCA...(the order of occurence of 'C', 'A' are changed)
Your algo will still give 'ACEF' as the longest subsequence which is wrong..

corrrect me if I am wrong..:)

- kiran February 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

en.wikipedia.org/wiki/Longest_common_subsequence_problem#Example

- blueskin.neo February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is straight out of CLR. i am surprised at interviewers answer..did he mention he was giving brute force?

- Anony February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

He told me, we can solve this problem in two ways 1. Brute force 2. Dynamic programming . After that he explained Brute Force method .

- siva.sai.2020 February 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int LCS[1024][1024];

int LongestCommonSubsequence( char pattern1[], int m, char pattern2[], int n)
{
	if ( m >= 1024 || n >= 1024)
	{
		printf("\n too long pattern \n");
		return -1; // return error -1
	}
	else
	{
		int i=0,j=0;

		while(i<m)
		{
			LCS[i++][n] = 0;
		}
		while(j<n)
		{
			LCS[m][j++] = 0;
		}

		for( i = m-1; i>= 0 ; i-- )
		{
			for( j= n-1; j>=0 ;j--)
			{
				LCS[i][j] = LCS[i+1][j+1];

				if(Pattern1[i] == pattern2[j] )
					LCS[i][j]++;

				if( LCS[i+1][j] > LCS[i][j] )
					LCS[i][j] = LCS[i+1][j];
				if(LCS[i][j+1] > LCS[i][j])
					LCS[i][j] = LCS[i][j+1];
			}
		}
		return LCS[0][0];
	}
}

Time complexity O(mn)

- siva.sai.2020 February 18, 2013 | 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