Created
May 18, 2022 12:54
-
-
Save les-peters/68d47eeba7898fbf4448d2844acaabab to your computer and use it in GitHub Desktop.
Maximized Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
question = """ | |
Given two integer arrays of size n, return a new array of size n such that | |
n consists of only unique elements and the sum of all its elements is maximum. | |
Example: | |
let arr1 = [7, 4, 10, 0, 1] | |
let arr2 = [9, 7, 2, 3, 6] | |
$ maximizedArray(arr1, arr2) | |
$ [9, 7, 6, 4, 10] | |
""" | |
def maximizedArray(a1, a2): | |
a = {} | |
l = len(a1) | |
for i in a1: | |
a[i] = 1 | |
for i in a2: | |
a[i] = 1 | |
print(sorted(map(lambda x: int(x), a.keys()))[l-1:]) | |
return | |
arr1 = [7, 4, 10, 0, 1] | |
arr2 = [9, 7, 2, 3, 6] | |
maximizedArray(arr1, arr2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment