×

# AppPerfect question

 0 The following question was asked in our campus for AppPerfect company. If possible someone can suggest a good approach There are n shops of a certain product of given quantity on the x-axis. Each shop either buys the product, represented by +ve value or sells the product, represented by -ve value. You are initially at x = 0 and, our aim to travel minimum distance and satisfy the demands of all the shops who want to buy the product. Input : the first contains n, number of shops presents the second line contains n integers containing the location of shos of the ith shop the third line contains n integers containing the quantity of product it wants to buy or sell Output : A single integer which will be minimum distance by us to satisfy every demand Sample: input: 3 -10 1 2 5 -6 1 output: 14 Explanation: we first go to from 0 to 1 for purchase and then to 2 for selling and then to -10 to sell again Contraints - 1<= n <= 1e3, -1e5 <= cooridnates <= 1e5 -1e5 <= demand <= 1e5 asked 17 Oct '18, 12:47 3★sonu_628 346●8 accept rate: 8%

 1 Could you please explain the sample test case. it is quite unclear answered 17 Oct '18, 13:40 204●5 accept rate: 13%
 0 The sum of all values of demand array is zero always,right? answered 17 Oct '18, 13:53 5★ram_24 146●5 accept rate: 37% not necessary (21 Oct '18, 15:33) sonu_6283★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×92

question asked: 17 Oct '18, 12:47

question was seen: 136 times

last updated: 21 Oct '18, 15:33