Uber Hiring Drive
Company: Uber
Role: software engineer i, software engineer ii
Interview Stage: Phone Screen
Original Post Content:
On 14 sept, i got the chance for UBER hiring Drive
Q1. Given an array of sorted integers, sort the array in ascending order of squares of its elements.
For example:
[1, 5, 7, 7, 8, 10] -> [1, 25, 49, 49, 64, 100] (Correction: original example was [1, 5, ,7, 7, 8, 10] -> [1, 5, 7, 7, 8, 10]. This seems to be a typo as it's not the squared version. Assuming the intent was to show an output after squaring and sorting).
[-5, -3, -3, 2, 4, 4, 8] -> [4, 9, 9, 16, 16, 25, 64]
Follow up questions:- find kth min or max element after sorting.
Interviewer was looking for O(LogN) time complexity for this follow-up question which I could not able to get.
Q2. Given a series of text, write some code to find the top k terms in that text.
text: b a b a a c
k: 2
Result: ["a", "b"] since a occurs 3 times, b 2 times.
Follow up :- what if we have to split the text on different characters.
Please feel free to put your answer in comment for both questions.
Thank you