Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
771 views

For proper oa or interview experiences list of all top tech companies visit :

https://oa.desiqna.in

https://interview.desiqna.in

 

image

 

in Online Assessments by Expert (46,090 points) | 771 views

1 Answer

0 like 0 dislike

Given an array of cost of items at every shop . Each time a query is given with amount of
money user has and the starting index of shop . Return the maximum number of items user can buy.

 

Example 
 Item Array : [1,3,5,6,2,1] 
 Here Array[i] denotes the cost of item sold in shop i 
 Query 1 :
 Amount = 11
 Start Position = 2(1-indexed);

 

Soln : So user starts at postion 1(0-indexed) so it can visit shop 1 to the last shop
it will choose items optimally so that it can visit maximum shop within his given amount:
1 + 2 + 3+ 5=11 so it can buy 4 products in total (Products of cost 1, 2, 3 and 5 )

 

by Expert (46,090 points)