From 3d5a5da375ca49a1d84aca62f5ad6a3e1672d6d9 Mon Sep 17 00:00:00 2001 From: Chris Lopes <54064653+chickenCHRISpy@users.noreply.github.com> Date: Wed, 5 Oct 2022 23:22:34 +0530 Subject: [PATCH] added a classic dsa problem --- DSA/find_Insert_position.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 DSA/find_Insert_position.py diff --git a/DSA/find_Insert_position.py b/DSA/find_Insert_position.py new file mode 100644 index 0000000..6f6f7f7 --- /dev/null +++ b/DSA/find_Insert_position.py @@ -0,0 +1,18 @@ + + +# Function to find insert position of K +def find_index(arr, n, K): + + for i in range(n): + if arr[i] == K: + return i + + elif arr[i] > K: + return i + + return n + +arr = [1, 3, 5, 6, 8] +n = len(arr) +K = 2 +print(find_index(arr, n, K))