summaryrefslogtreecommitdiff
path: root/progs/a552.py
blob: 5d11019d1e66a0971824f8ee6dc1fb8584a0e255 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def first_Missing_Positive(arr,n): 
    ptr = 0
    for i in range(n):
        if arr[i] == 1:
            ptr = 1
            break
    if ptr == 0:
        return(1)
    for i in range(n):
        if arr[i] <= 0 or arr[i] > n:
            arr[i] = 1
    for i in range(n):
        arr[(arr[i] - 1) % n] += n
    for i in range(n):
        if arr[i] <= n:
            return(i + 1)
    return(n + 1)