Money exchange problem

{1,2,5,10,20,50,100,200,500,2000}

key ->168
mid element -> 50
kya 50 <= 168 return true
ab kyunki true return hua hai to hum array ki right side mein dekhenge {100 ,100,500,2000}
mid element 500
kya 500 <=168 hai
nahi to ab hu is array ke left part mein dekhenge {100,100}
mid element 100 return true
ab hum right side mein dekhenge but kyunki right part hai hi nahi hum yahi ruk jayege . aur iska index return karnege (index of 200 )

nahi to ab hu is array ke left part mein dekhenge {100,100}
mid element 100 return true
ab hum right side mein dekhenge but kyunki right part hai hi nahi hum yahi ruk jayege . aur iska index return karnege (index of 200 )
bhai theek bola aapne bilkul
jaab array mai (100,200) bacha 100 mid hua and mid<=key hai return true hua toh index bhi toh 100 ka return hona chaiye kyuki jaab mid mera 200 hoga toh false return hoga naa

nahi bro ,last updation jo hua tha,uska index deta hai.
last updation 100 pe hua tha aur right ki tarf hua tha (matlab +1 ) hua tha,isliye wo 200 ka index dega.

Compare 50 and 168
Compare 500 and 168
Compare 200 and 168
Compare 100 and 168
bhai ye dekho jaab maine print karaya comparison toh 100 and 168 sabse last mai compare ho raha hai which returns true and aapke according 200 sabse last mai compare hoga
toh jo mere output show ho raha hai uske acc last mai 100 and 168 compare hua which returns true and index of 100 return hona chaiye

100 pe to true ayega na ,
tab phr wo right array mein dekhege

bhai jaab 100 true aaya toh left= right ho jaayega naa kyuki 100 mera last element bacha tha array mai baaki saabke saath comparsion ho chuka hai toh right part aur left part array ka hai he nahi

ye refer karo ,
internal implementation->http://www.cplusplus.com/reference/algorithm/upper_bound/

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.