MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / check

Function check

Hackerrank_problems/ElectronicShop/solution2.py:8–22  ·  view source on GitHub ↗
(arr,start,end,n1,max)

Source from the content-addressed store, hash-verified

6#check() return maximum price of the USB drive which is less than or equal to our budget
7#This uses the binary search approach to find the required maximum value
8def check(arr,start,end,n1,max):
9 if end==start+1 or end==start:
10 if arr[end]>max and arr[end]<=n1:
11 max=arr[end]
12 return max
13 if arr[start]>max and arr[start]<=n1:
14 max=arr[start]
15 return max
16 mid=(start+end)//2
17 num=arr[mid]
18 if num<=n1:
19 if max<num:
20 max=num
21 return check(arr,mid,end,n1,max)
22 return check(arr,start,mid,n1,max)
23
24
25#getMoneySpent() will return the amount required to buy the most expensive keyboard and USB drive. If not not possible returns -1.

Callers 1

getMoneySpentFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected