Grokking Amazon Coding Interview
Vote
0% completed
Hidden Document
Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content
.....
.....
.....
Like the course? Get enrolled and start learning!
I
ishmamf2003
· a year ago
WrongAnswer0.054 ms <br>
Your Input[8,1,2,3,4,8,9] <br> [4,3,2,1] <br> [5, 5, 4, 6, 4] <br> [4,5] <br> [10, 20, 30, 20, 15, 20, 10] <br> [20,10] <br>
Output <br> [4,3,2,1,8,8,9] <br> [4,4,5,5,6] <br> [20,20,20,10,10,15,30] <br>
Expected <br> [4,3,2,1,8,8,9] <br> [4,4,5,5,6] <br> [20,20,20,10,10,15] <br>
Gopi Kumar
· a year ago
WrongAnswer0.148 ms
Your Input[8,1,2,3,4,8,9] [4,3,2,1] [5, 5, 4, 6, 4] [4,5] [10, 20, 30, 20, 15, 20, 10] [20,10] Output[4,3,2,1,8,8,9] [4,4,5,5,6] [20,20,20,10,10,15,30] Expected[4,3,2,1,8,8,9] [4,4,5,5,6] [20,20,20,10,10,15]
George Ceja
· a day ago
class Solution: def relativeSortArray(self, arr1, arr2): # ToDo: Write Your Code Here. arr1_dict = {} for number in arr1: if number in arr1_dict: arr1_dict[number] += 1 else: arr1_dict[number] = 1 output_array = [] for number in arr2: num_of_occurence = arr1_dict[number] output_array.extend([number] * num_of_occurence) del arr1_dict[number] # We sort first before expanding to avoid sorting large list for curr_num in sorted(arr1_dict.keys()): output_array.extend([curr_num] * arr1_dict[curr_num]) return output_array