Uber Interview Question

Search a target number in a Rotated Sorted Array.

Interview Answers

Anonymous

Apr 4, 2016

public int search(int[] nums, int target) { int start = 0; int end = nums.length - 1; while (start = nums[start]) { end = mid - 1; } else { start = mid + 1; } } else { //5 6 7 1 2 3 4, 6 if (target > nums[mid] && target <= nums[end]) { start = mid + 1; } else { // end = mid - 1; } } } return -1; }

1

Anonymous

Oct 27, 2015

Binary search

Anonymous

Dec 10, 2015

I would like to slap your interviewer for asking this question in an interview: "How do you calculate PI, if I just give you a calculator." Definitely he/she don't know what is "problem solving" in software engineering. Btw, I work for Amazon.

Anonymous

Feb 10, 2016

To answer the Pi question- I will first turn the calculator on, press 22, then press '/', then 7, then '='. Then I will test for edge cases where calculator's buttons may not have been pressed properly. -_-

1