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!
Select
Add answer anonymously...

Wipro Software Engineer interview questions & answers

A Software Engineer was asked 1mo agoQ. Explain the concept of red-black trees.
A Software Engineer was asked 2mo agoQ. What are the key components in ADF?
A Software Engineer was asked 2mo agoQ. What is a function in Python?

Popular interview questions of Software Engineer

A Software Engineer was asked 1mo agoQ1. Explain the concept of red-black trees.
A Software Engineer was asked 1mo agoQ2. What are the key components in ADF?
A Software Engineer was asked 1mo agoQ3. What is a function in Python?

Top HR questions asked in Wipro Software Engineer

A Software Engineer was asked 1w agoQ1. What is your goal?
A Software Engineer was asked 3w agoQ2. How do you handle stress?
A Software Engineer was asked 3w agoQ3. What motivates you?
Wipro Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits