Pregunta de entrevista de Google

Not difficult. It is like why can not compare two strings. And how to compare one object which initialed as a string with string. The coding quesition is to find the kth in two sorted arrays.

Respuestas de entrevistas

Anónimo

2 sep 2014

Maybe I'd use a binary search on the two arrays... it's tricky, but the solution MUST be fast

1

Anónimo

19 oct 2017

The above solution is m+n. The solution that gets you hired is log(m+n), but it doesn't involve binary search.

Anónimo

19 oct 2017

So the ideas is instead of just cut one number each time, you cut k / 2 numbers every time.

Anónimo

7 jul 2014

First is to write a compareTo function. And the coding problem is simple.

1

Anónimo

26 jul 2014

public void FindKthLargestElement(int[] sorted1, int[] sorted2, int k) { int i = sorted1.Length - 1; int j = sorted2.Length - 1; int kth = -1; while (i >= 0 && j >= 0 && k > 0) { if (sorted1[i] > sorted2[j]) { kth = sorted1[i]; i--; } else { kth = sorted2[j]; j--; } k--; } while (k > 0) { if (i 0) { if (sorted1[i] 0) { if (i > sorted1.Length - 1) { kth = sorted2[j]; j++; k--; } else if (j > sorted2.Length - 1) { kth = sorted1[i]; i++; k--; } } Console.WriteLine(kth); }

1