-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathNoble_Integer.py
More file actions
37 lines (32 loc) · 830 Bytes
/
Noble_Integer.py
File metadata and controls
37 lines (32 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
''' An integer x is said to be Noble given an array
if the number of integers greater than x are equal to x.
If noble integer is not found output is -1.
'''
# To find the noble integer from the given list
def nobleint():
x = 0
lst.sort()
for i in range(0, num - 1):
if lst[i] == lst[i + 1]:
continue
if lst[i] == num - i - 1:
x = 1
return num - i - 1
if x == 0:
return -1
if __name__ == '__main__':
num = int(input('Enter the number of elements:'))
lst = list(map(int, input('Enter the elements:').split()))
print nobleint(lst, num)
'''
Sample Output
Enter the number of elements:4
Enter the elements:7 3 9 81
3
Enter the number of elements:3
Enter the elements:2 2 2
-1
Complexities
Time Complexity:O(nlogn)
Space Complexity:O(1)
'''