Linkedin Interview Question for Software Engineer / Developers






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

public class EditDistance {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String s1 = "Good Morning";
		String s2 = "Good Mornin";
		EditDistance ed = new EditDistance();
		ed.computeEdit(s1,s2);
	}

	private int computeEdit(String s1, String s2) {
	
	int i,j;
	int lenx = s1.length();
	int leny = s2.length();
	int[][] table = new int[lenx+1][leny+1];

	// Initialize table that will store Edit of all prefix strings.
	// This initialization is for all empty string cases.
	for (i=0; i<=lenx; i++) 
		table[i][0] = 0;
	for (i=0; i<=leny; i++)
		table[0][i] = 0;

	// Fill in each Edit value in order from top row to bottom row,
	// moving left to right.
	for (i = 1; i<=lenx; i++) {
		for (j = 1; j<=leny; j++) {

			// If last characters of prefixes match.
			if (s1.charAt(i-1) == s2.charAt(j-1))
				table[i][j] = table[i-1][j-1];

			// Otherwise, take the minimum .
			else
				table[i][j] = Math.min(table[i][j-1]+1,Math.min(table[i-1][j]+1,table[i-1][j-1]+1));
		}
	}
	System.out.println(table[lenx][leny]);
	return table[lenx][leny];
}


}

- sLion September 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

csse.monash.edu.au/~lloyd/tildeAlgDS/Dynamic/Edit/

- foobar June 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

yes, I had memorized above URL and wrote it down on whiteboard when interviewer asked me this question. That is how I got to round# 2.

- Anonymous December 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Did you get the job, you arrogant lout?

- Anonymous October 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int dp[n+1][m+1];
memset(dp, 0, sizeof(dp));
for (int i=1; i <= n; i++) for (int j=1; j <= n; j++)
   dp[i][j] = min(dp[i-1][j-1] + a[i] == b[j] ? 1 : 0, 1 + dp[i][j-1], 1 + dp[i-1][j]);
return dp[n][m];

- Anonymous October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int dp[n+1][m+1];
memset(dp, 0, sizeof(dp));
for (int i=1; i <= n; i++) for (int j=1; j <= n; j++)
   dp[i][j] = min(dp[i-1][j-1] + a[i] == b[j] ? 1 : 0, 1 + dp[i][j-1], 1 + dp[i-1][j]);
return dp[n][m];

- Anonymous October 04, 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