I recently spoke to a junior web developer that had a tough time with Uber’s phone interview. I thought I would share the problems we worked on and see what the Medium community thinks!
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.
If the fractional part is repeating, enclose the repeating part in parentheses.
Input: numerator = 1, denominator = 2
Input: numerator = 3, denominator = 1
Input: numerator = 2, denominator = 3
Some people have been asking for some hints:
- There is no crazy high level math here, just remember back to your long division days
- Try a couple of examples to recognize a pattern. With 1/3 the repeating part is easy, but how about something like 4/333. Do you see a pattern?
- After trying those you will also notice once the remainder starts repeating, so does the divided result.
- Edge cases can hurt you here. Really think about your test cases and list out as many as you can. Test, test and test your code!
Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval
[a, b] (with
a <= b) denotes the set of real numbers
a <= x <= b. The intersection of two closed intervals is a set of real numbers that is either empty, or can be represented as a closed interval. For example, the intersection of [1, 3] and [2, 4] is [2, 3].)
Input: A = [[0,2],[5,10],[13,23],[24,25]], B = [[1,5],[8,12],[15,24],[25,26]]
Reminder: The inputs and the desired output are lists of Interval objects, and not arrays or lists.
0 <= A.length < 1000
0 <= B.length < 1000
0 <= A[i].start, A[i].end, B[i].start, B[i].end < 10^9
*I have also seen this one asked at Facebook*
Good Luck and see you in the comments!