
Asked in Wipro
Knapsack Problem Statement
There is a potter with a limited amount of pottery clay (denoted as 'K' units) who can make 'N' different items. Each item requires a specific amount of clay and yields a certain profit. The goal is to maximize the total profit by choosing which items to make.
Input:
The first input line contains an integer ‘T’ representing the number of test cases.
For each test case:
- The first line contains two space-separated integers, ‘N’ (number of items) and ‘K’ (units of clay available).
- The second line contains ‘N’ integers, each representing the clay requirement for the corresponding item.
- The third line contains ‘N’ integers, each representing the profit obtainable from selling the corresponding item.
Output:
For each test case, output a single integer on a new line representing the maximum profit the potter can achieve.
Example:
Input:
2
3 50
10 20 30
60 100 120
2 10
5 3
20 30
Output:
220
50
Constraints:
- 1 <= T <= 100
- 1 <= N <= 100
- 1 <= K <= 100
- 1 <= profit[i] <= 10000
- 1 <= Clay[i] <= 2000
- Time Limit: 1 second
Note:
Implement the function; printing has already been handled.

AnswerBot
4mo
The Knapsack Problem involves maximizing profit by choosing which items to make with limited resources.
Understand the problem statement and constraints provided.
Implement a dynamic programming solutio...read more
Mantu Gupta
2y
Gsushshsisbjss. eieheieheheoeh
Help your peers!
Add answer anonymously...
Top Software Engineer Interview Questions Asked at Wipro
Q. Tell me about Wipro.
Q. What is the difference between the equality operators "==" and "===" in programm...read more
Q. What is the difference between the '==' operator and the 'equals()' method in Ja...read more
Interview Questions Asked to Software Engineer at Other Companies
Top Skill-Based Questions for Wipro Software Engineer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

