Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Minimum Positive Integer
""" This is a demo task. Write a function: def solution(A) that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. Given A = [1, 2, 3], the function should return 4. Given A = [−1, −3], the function should return 1. Write an efficient algorithm for the following assumptions: N is an integer within the range [1..100,000]; each element of array A is an integer within the range [−1,000,000..1,000,000]. Copyright 2009–2021 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited. """ def solution(A): # write your code in Python 3.6 max_a = max(A) possible_numbers = set(range(1, max_a + 2)) min_list = possible_numbers - set(A) if len(min_list) > 0: return min(min_list) elif max_a < 0: return 1 for test_case in [ [2, 3, 7, 6, 8, -1, -10, 15], [2, 3, -7, 6, 8, 1, -10, 15], [1, 1, 0, -1, -2], ]: print(f"Test Case is {test_case}") print(f"Solution is {solution(test_case)}") print(f"{'*'*88}")
run
|
edit
|
history
|
help
0
Traceback prettyfy.py
Урок 4 задача 4: решить в целых числах уравнение ax=b (python)
Multiply two marrix
square cube function
map lambda list
set, tuple, and dict
linearSearch.py
Mixing string with number
HW L3
rstring