InMobi Interview Question for SDE-2s


Country: India




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

The below solution may work upto some extent

static int getDNAAlignment(String dna1, String dna2) {
		final int maxn = 110;
		int b[][] = new int[maxn][maxn];
		int[][] a = new int[300][300];
		a['A']['A'] = 5;
		a['A']['C'] = a['C']['A'] = -1;
		a['A']['G'] = a['G']['A'] = -2;
		a['A']['T'] = a['T']['A'] = -1;
		a['A']['-'] = a['-']['A'] = -3;
		a['C']['C'] = 5;
		a['C']['G'] = a['G']['C'] = -3;
		a['C']['T'] = a['T']['C'] = -2;
		a['C']['-'] = a['-']['C'] = -4;
		a['G']['G'] = 5;
		a['G']['T'] = a['T']['G'] = -2;
		a['G']['-'] = a['-']['G'] = -2;
		a['T']['T'] = 5;
		a['T']['-'] = a['-']['T'] = -1;

		int i = dna1.length();
		int j = dna2.length();
		int s;

		for (int k = 0; k <= i; k++) {
			for (int l = 0; l <= j; l++) {
				if (k == 0 && l == 0)
					b[k][l] = 0;
				else if (k == 0)
					b[k][l] = a['-'][dna2.charAt(l - 1)] + b[k][l - 1];
				else if (l == 0)
					b[k][l] = a[dna1.charAt(k - 1)]['-'] + b[k - 1][l];
				else {
					s = a['-'][dna2.charAt(l - 1)] + b[k][l - 1];

					if (s < a[dna1.charAt(k - 1)]['-'] + b[k - 1][l])
						s = a[dna1.charAt(k - 1)]['-'] + b[k - 1][l];
					if (s < a[dna1.charAt(k - 1)][dna2.charAt(l - 1)]
							+ b[k - 1][l - 1])
						s = a[dna1.charAt(k - 1)][dna2.charAt(l - 1)]
								+ b[k - 1][l - 1];
					b[k][l] = s;
				}
			}
		}
		return b[i][j];
	}

- Karthik, S July 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The java solution is below.. it may work for 90 percent of the cases

static int getDNAAlignment(String dna1, String dna2) {
		final int maxn = 110;
		int b[][] = new int[maxn][maxn];
		int[][] a = new int[300][300];
		a['A']['A'] = 5;
		a['A']['C'] = a['C']['A'] = -1;
		a['A']['G'] = a['G']['A'] = -2;
		a['A']['T'] = a['T']['A'] = -1;
		a['A']['-'] = a['-']['A'] = -3;
		a['C']['C'] = 5;
		a['C']['G'] = a['G']['C'] = -3;
		a['C']['T'] = a['T']['C'] = -2;
		a['C']['-'] = a['-']['C'] = -4;
		a['G']['G'] = 5;
		a['G']['T'] = a['T']['G'] = -2;
		a['G']['-'] = a['-']['G'] = -2;
		a['T']['T'] = 5;
		a['T']['-'] = a['-']['T'] = -1;

		int i = dna1.length();
		int j = dna2.length();
		int s;

		for (int k = 0; k <= i; k++) {
			for (int l = 0; l <= j; l++) {
				if (k == 0 && l == 0)
					b[k][l] = 0;
				else if (k == 0)
					b[k][l] = a['-'][dna2.charAt(l - 1)] + b[k][l - 1];
				else if (l == 0)
					b[k][l] = a[dna1.charAt(k - 1)]['-'] + b[k - 1][l];
				else {
					s = a['-'][dna2.charAt(l - 1)] + b[k][l - 1];

					if (s < a[dna1.charAt(k - 1)]['-'] + b[k - 1][l])
						s = a[dna1.charAt(k - 1)]['-'] + b[k - 1][l];
					if (s < a[dna1.charAt(k - 1)][dna2.charAt(l - 1)]
							+ b[k - 1][l - 1])
						s = a[dna1.charAt(k - 1)][dna2.charAt(l - 1)]
								+ b[k - 1][l - 1];
					b[k][l] = s;
				}
			}
		}
		return b[i][j];
	}

- Karthik S July 09, 2014 | 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