Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike
1,485 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 (44,360 points)

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 (44,360 points)
...