Interview Question

Interview

First Interview: Simple questions: Write a program to find

  a character (and it's occurrence count) in a string. Scale for a paragraph, to a file that doesn't fit in memory to a large set of files split across a network that don't fit in memory of a single machine. Second Interview: Median finding algorithm - find the median of 'n' numbers and a little bit of binary search tree implementation
Tags:
technical
Answer

Interview Answer

2 Answers

1

The first interview went good. But the second interviewer was more intent on looking for solutions that were exactly in line with his thinking. A slight error and he'd cut you off and explain the whole solution and literally ask you to code it and not listen to any other 'ways' of doing it. It was his way or his way. Extremely disappointing. The 45 minute interview only allowed me to write about 20 lines of code without any time for me to ask him any questions.

Interview Candidate on Mar 31, 2013
0

public static float median(int[] a) { Random r = new Random(); return median(a, (a.length - 1) / 2, (a.length % 2) == 0, 0, a.length - 1, r); } public static float median(int[] a, int k, boolean average, int s, int f, Random r) { if (k < 0) return 0.0f; if (s == f) { if (average) { return ((float) a[s] + a[s + 1]) / 2; } else { return a[s]; } } int pivot = a[s + r.nextInt(f - s)]; int numSmaller = 0; int numLarger = 0; while (numSmaller + numLarger < f - s + 1) { if (a[s + numSmaller] < pivot) { numSmaller++; } else { swap(a, s + numSmaller, f - numLarger); numLarger++; } } if (numSmaller > k) { return median(a, k, average, s, f - numLarger, r); } else { return median(a, k - numSmaller, average, s + numSmaller, f, r); } } public static void swap(int[] a, int i, int j) { int t = a[i]; a[i] = a[j]; a[j] = t; }

Rahul on May 3, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.