Mentor Graphics Interview Question for MTSs

• 0
of 0 votes

Country: India
Interview Type: In-Person

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

1)start from top right corner
2) until curr_elem==elem_to_search || you go out of matrix, go down if curr_elem<elem_to_search else go left

complexity= O(m+n)

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

thr is a specific name of such kinds of matrices....ny idea nyone?

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

yup , there is a name it's called Young's tableau.

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

Yes

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

Do u mean that rows and columns are sorted in themselves independently ? ie.
3 6 7 12
7 9 10 13
9 12 13 14

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

number of solutions are possible :
1) if min(m,n)==1 use binary search.

2) if min(m,n)<<small linear search in zig-zag manner starting at top right corner. O(max(m,n))

3) if both m and n large use 2D binary-search O(log(n)*log(m))

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

``````public static void findInArray(int[][] inpArr, int num) {
int count = 1;
boolean flag = true;
int i = 0;
int j = (inpArr[0].length)-1;
int currentNum = inpArr[i][j];
while(num!=currentNum) {
count++;
if(num>currentNum) {
i++;
} else {
j--;
}
try {
currentNum = inpArr[i][j];
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println(num + " not found in input array");
flag = false;
break;
}
}
if(flag) System.out.println(num + "fount at (" + i +","+ j + ") position in " + count + " comparision(s).");
}``````

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

While this solution is correct, it does not make use of sorted columns and rows.
Following is the algo:
1. Look along diagonal for element greater than element to be found. Let's call this point (row, col) as pivot.
2. The pivot point cuts the array into 4 quadrant. Our element can only be present in the quadrant that is
2(a) above and towards right
2(b) below and towards left of this pivot point.
3. Apply this recursively to get the ans.

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