Top Coding Interview Question – Solved

2 Live
Profits John is a shopkeeper. He can buy N items from the producer, the ith of which costs cost[i]. He can sell the it item at sell[i]. Initially, he has K dollars and O items in his shop. At any moment, his store can accommodate at most 1 item, which means he has to sell the previous item before buying the next one from the producer. What is the maximum profit he can achieve? Notes - He can buy and sell any number of items. - He can use the profit previously earned to buy new items. - One item can be bought and sold at most once. - Items can be bought and sold in any order and not necessarily in the order given as input. Function description following 4 parameters and returns the solution: - N: Represents the number of items - K: Represents the initial amount - cost: Represents the cost price of items - sell. Represents the selling price of items Input format for custom testing Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code - The first line contains N. denoting the number of items. - The second line contains K, denoting the initial amount. - The third line contains cost, denoting the cost price of items - The fourth line contains sell, denoting the selling price of items Output format Print an integer representing the maximum total profit.

Asked in: No companies listed

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |