Write a program to take an 1D integer array which is sorted and also another integer, the key. You have to find whether the key exists in the list or not. If the key does not exist, print -1. Otherwise, print 1.
Answers
Answered by
0
Answer:
print 1
hope its helpful to u
Answered by
0
Answer:Program to check if an array is sorted or not (Iterative and Recursive)
Explanation:
def arraySortedOrNot(arr):
# Calculating length
n = len(arr)
# Array has one or no element or the
# rest are already checked and approved.
if n == 1 or n == 0:
return True
# Recursion applied till last element
return arr[0] <= arr[1] and arraySortedOrNot(arr[1:])
arr = [20, 23, 23, 45, 78, 88]
# Displaying result
if arraySortedOrNot(arr):
print("Yes")
else:
print("No")
Similar questions