Frage im Vorstellungsgespräch bei Google

1) Sort K sorted array. 2) Reverse string.

Antworten zu Vorstellungsgespräch

Anonym

25. Okt. 2015

1. BST. Insertion into a BST takes O(log n), so insertion of k arrays will take O(k log n). 2. What type of string reversal? Do you mean "The End" turns to "End The" or "The End" turns to "dnE ehT"? For the first option, I'd reverse the individual words, then reverse the whole string. That is, "ehT dnE" and reversing that would give "End The". For the second option, just swap the i and length-i index till you reach the middle of the string.

1

Anonym

15. Okt. 2015

1) Use a priority queue. Push front element of each array in to the priority queue. Then pop element from the queue. Add new element in to the priority queue that belongs to the same array as the element you just pop. Repeat doing so until all the elements have been sorted. 2) two pointers, one in the front , one in the end. Front pointer move forward, end pointer move backward, swap elements pointed by these two pointers. Until front pointer is bigger than end pointer