o1-preview-2024-09-12· OpenAI
WildChat-4.8M (AI2)
A sequence of n positive integers is given. Determine whether it is a permutation of the…
- User
A sequence of n positive integers is given. Determine whether it is a permutation of the first n positive integers. Write code in python
Input. One line contains first number n (n ≤ 10000), then n positive integers separated by a space. It is known that each of the positive integers is less than 2000000.
The output Print 0 if the sequence is a permutation. Otherwise print the minimum number that is not in this sequence.
Examples Input #1 3 2 1 3 Answer #1 0 Input #2 3 1 4 2 Answer #2 3
Translated with DeepL.com (free version)
- Assistantpython
tokens = input().split() n = int(tokens[0]) numbers = list(map(int, tokens[1:])) # In case the numbers continue on the next lines while len(numbers) < n: tokens = input().split() numbers.extend(map(int, tokens)) present = [False] * (n + 1) for x in numbers: if 1 <= x <= n: present[x] = True missing_number = 0 for i in range(1, n + 1): if not present[i]: missing_number = i break print(missing_number)