Open hetvi20 opened 1 week ago
can u assign me this issue please!
Hey @Ayush7-BIT , i am solve this issue , so can you marge my pull request
hey @Ayush7-BIT , I am interested in this issue, can you assign this issue me
@Ayush7-BIT i want to solve this issue as a beginner level can you assign this to me
@Ayush7-BIT Could you assign me I have create title of problem and provide solution. 1) Time Complexity: Best case (when the target is at the middle): O(1) Worst case (when the search space is halved until only one element remains): O(log n), where n is the number of elements in the array.
2) Dynamic Input:
The list is dynamically taken as input using input() and converted to integers using map(int, input().split()). The target is also taken dynamically using input().
3) User-Friendly Output:
The result is printed using f-strings to insert variables inside the output message.
Code:
def binarysearch(arry, target) low= 0 high = len(len)-1 while low<= high: mid= (low+high)//2 if arry[mid]== target: return mid elif arry[mid] < target: low= mid+1 else: high= mid-1
return -1
arry= list(map(int, input("enter number separate by space").split() #take a space-separated list of integers and convert them into an integer list using map, input, spilt target= int(input("Enter the target number"))
result = binarysearch(arry, target)
if result!= -1: print(f"Target found at index {result}") #f is use to print value in the string value else: print("Target not found")