We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'introTutorial' function below.## The function is expected to return an INTEGER.# The function accepts following parameters:# 1. INTEGER V# 2. INTEGER_ARRAY arr#defsearch(arr,V,low,high):iflow==high:ifarr[low]==V:returnlowelse:return-1third=(high-low+1)// 3mid1=low+thirdmid2=high-thirdifarr[mid1]==V:returnmid1ifarr[mid2]==V:returnmid2ifV<arr[mid1]:returnsearch(arr,V,low,mid1-1)elifV>arr[mid2]:returnsearch(arr,V,mid2+1,high)else:returnsearch(arr,V,mid1+1,mid2-1)defintroTutorial(V,arr):# Write your code herereturnsearch(arr,V,0,len(arr)-1)if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')V=int(input().strip())n=int(input().strip())arr=list(map(int,input().rstrip().split()))result=introTutorial(V,arr)fptr.write(str(result)+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Intro to Tutorial Challenges
You are viewing a single comment's thread. Return to all comments →
My solution using Python.