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, 5, 7, 7, 8, 10]
[-5, -3, -3, 2, 4, 4, 8] -> [2, -3, -3, 4, 4, -5, 8]
i.e., squares : [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 followup 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