Sorted insert position



Problem to find which index is perfect to insert the k value for ascending order.



Example-1:


Input    : n = [ 3, 8, 9, 29]  k = 4
Output   : 1
Explain  : If insert the k value in index 1 to become list in ascending order.  


Example-2:


Input    : n = [ 1, 2, 4, 5]  k = 7
Output   : 4
Explain  : If insert the k value in index 4 to become list in ascending order.  


Example-3:


Input    : n = [ 3, 5, 7, 9]  k = 2
Output   : 0
Explain  : If insert the k value in index 0 to become list in ascending order.  







Solution




n = [ 3, 8, 9, 29]

k = 4

if(k in n):

    a = n.index(k)

    print(a)

else:

    n.append(k)

    n = sorted(n)

    c = n.index(k)

    print(c)



Output



1