NetApp Interview Question for Software Engineer / Developers






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

Similar to binary search.
Divide the matrix into four quarters.
Depending on how k is compared with A[n/2][m/2], k is not contained in either the upper-left or the bottom-right quarter.
So just recurse on the other 3 quarters.
The running time T(n) = 3T(n/4) + O(1), which is clearly O(log n).

- Anonymous August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i am not much convinced with ur idea .. can you plz show it by giving an example..

- Anonymous September 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice approach !

- Anonymous September 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Pseudocode:
Given an M * N matrix, Start from A[M][0](the bottom left corner).
If the element<k, col++;
else if the element >k, row--;
else if element==k return (i,j).

This solution is based on Youngs tableau.

- TikTok August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

good idea....but it is taking o(n)at worst time , cant w do better than this.......

- Anonymous September 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

do we have a better approach than this ?

- bebo December 25, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

find( matrix Arr , int X )
{
     int R=Arr.rowsize();
     int C=Arr.colsize();
     
     int r=R-1,c=0;
     
     while( r>=0 && c<C )
      {
          if( Arr[r][c]==X )
           {
                found ;
                print( r , c );
                return;
                
                } 
                
           else if ( Arr[r][c] > X )
             r-- ;
             
           else
            c++ ;
            
            
            }
            
            
            print( "NOT FOUND" );
            return;
            
            }

- JD September 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="c" line="1" title="CodeMonkey38228" class="run-this">include <stdio.h>

int main(void) {

return 0;
}
</pre><pre title="CodeMonkey38228" input="yes">
</pre>

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

for each row check if the stat element is > and less than end lelement.
If the search element matches the criteria, then do a binary search on the row.
If not, move to next row.

I will be O(m long n)

- sridhar September 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do merge sort on the two rows and do a binary search on the resultant array. this willbe O((m+n)log(m+n))

- Pavan January 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do merge sort on the two rows and do a binary search on the resultant array. this willbe O((m+n)log(m+n))

- Pavan January 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

O( logm * logn )

1. Find a row which might have a key, by looking at first column using modified binary search which will look for interval match.
2. Conventional binary search on the row returned from step 1

Please let me know for any query

Cheers
Ankush

- ankushbindlish January 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please ignore this solution.

- ankushbindlish January 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

BinarySearch2D(int inputArray[][], int m , int n, int key){
int low=0;
int high=n-1;
int mid;
do{
mid = low + (high-low)/2;
if (inputArray[mid][mid] > key){
high = mid;
} else if (inputArray[mid][mid] < key){
low = mid;
} else{
return true;
}

}while(low<high);
return BinarySearch1D(inputArray,key,mid,true) || BinarySearch1D(inputArray,key,mid,false);
}


BinarySearch1D(int inputArray[][],int key, int maxIndex, bool rowConstant){
int low=0;
int high = maxIndex-1;
do{
int mid = low + (high-low)/2;
int midValue = rowConstant ? inputArray[maxIndex][mid] : inputArray[mid][maxIndex];
if (midValue > value){
high = mid-1;
} else if (midValue < value){
low = mid+1;
} else{
return true;
}

}while(low<high);
return false;
}

- ankushbindlish January 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

BinarySearch2D(int inputArray[][], int m , int n, int key){
int low=0;
int high=n-1;
int mid;
do{
    mid = low + (high-low)/2;
    if (inputArray[mid][mid] > key){
        high = mid;
    } else if (inputArray[mid][mid] < key){
        low = mid;
    } else{
            return true;
        }
 
  }while(low<high);
return BinarySearch1D(inputArray,key,mid,true) || BinarySearch1D(inputArray,key,mid,false);
}


BinarySearch1D(int inputArray[][],int key, int maxIndex, bool rowConstant){
int low=0;
int high = maxIndex-1;
do{
    int mid = low + (high-low)/2;
        int midValue = rowConstant ? inputArray[maxIndex][mid] : inputArray[mid][maxIndex];
    if (midValue  > value){
        high = mid-1;
    } else if (midValue < value){
        low = mid+1;
    } else{
            return true;
        }
 
  }while(low<high);
return false;
}

- ankushbindlish January 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

saddleback algorithm

- sugetha May 26, 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