NVIDIA Interview Question






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

arr1[] and arr2[] be the arrays


for(i=0;i<arr1.length();i++)
{
if(arr1[i]>arr2[0])
{
swap(arr[i],arr[0])
for(j=0;j<arr2.length-1;j++)
if(arr2[j]>arr2[j+1])
swap(arr2[j],arr2[j+1]);
else break;
}

- Andrew October 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

missing last brace

for(i=0;i<arr1.length();i++)
{
if(arr1[i]>arr2[0])
{
swap(arr[i],arr[0])
for(j=0;j<arr2.length-1;j++)
if(arr2[j]>arr2[j+1])
swap(arr2[j],arr2[j+1]);
else break;
}
}

- Andrew October 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is inplace merging??

- sairam November 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

let say

aar1=7,14,21
arr2=6,12

after inplace merging(requires no extra space)

arr1=6,7,12
arr2=14,21

- Anonymous November 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

According to me the question is just asking to merge (or combine) two arrays rather than sorting them too.

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

Can something similar to insertion sort do it? Insert every element of arr2 into arr1 in a similar way as in an insertion sort. Time complexity is sort of high...

- Anonymous November 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, Seems like this is a good direction. Imagine Arr1 and Arr2 are just sequential internally and make appropriate changes to Insertion sort.

- peace November 03, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Lets say 2 arrays:
arr1[];
arr2[];

for ( i = 0; i<arr1.length;i++)
{
if ( arr1[i] > arr2[0] )
{
temp = arr1[i];
arr1[i] = arr2[0];
for ( j = 1; j < arr2.length; j++ )
{
if ( arr2[j] < temp )
{
arr2[j-1] = arr2[j];
}
else
{
arr2[j-1] = temp;
break;
}
}// end 2nd for loop
} // end if
}//end first for loop

- TopCoder November 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Lets say 2 arrays:
arr1[];
arr2[];

for ( i = 0; i<arr1.length;i++)
{
if ( arr1[i] > arr2[0] )
{
temp = arr1[i];
arr1[i] = arr2[0];
for ( j = 1; j < arr2.length; j++ )
{
if ( arr2[j] < temp )
{
arr2[j-1] = arr2[j];
}
else
{
arr2[j-1] = temp;
break;
}
}// end 2nd for loop
} // end if
}//end first for loop

- TopCoder November 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming bot arrays are sorted, maintain 2 heaps (arrays -> heaps as heaps are arrays) and then just decrease the size of one of the arrays while increasing the size of the 2nd array....

- kaushal.rules April 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hihihi

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

<pre lang="java" line="1" title="CodeMonkey88227" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String s;
while (!(s=r.readLine()).startsWith("42")) System.out.println(s);
}
}

</pre><pre title="CodeMonkey88227" input="yes">
12</pre>

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

nvidia should expect a C code

- odie January 07, 2012 | 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