Last active
January 25, 2022 02:02
-
-
Save FernandoCutire/dfd04ec987d7bd6b92fc613e552ccbd3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def solution(A): | |
#Get rid of all zero and negative #'s | |
A = [i for i in A if i > 0] | |
#At this point, if there were only zero, negative, or combination of both, the answer is 1 | |
if (len(A) == 0): return 1 | |
count = 1 | |
#Get rid of repeating values | |
A = set(A) | |
#At this point, we may have only had the same # repeated. | |
#If repeated 1's answer is 2 | |
#If any other repeated #'s only, then answer is 1 | |
if (len(A) == 1): | |
if (list(A)[0] == 1): | |
return 2 | |
else: | |
return 1 | |
#Sort the array | |
A = sorted(A) | |
for j in range(len(A)): | |
#Test to see if it's >= to count. If so, it exists and is not the lowest integer. | |
if (A[j] <= count): #If the number is lt or equal to the count then continue the count | |
count = count + 1 | |
else: | |
return count | |
return count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment