
Asked in Samsung
0-1 Knapsack Problem Statement
You are tasked with determining the maximum profit a thief can earn. The thief is looting a store and can carry a maximum weight 'W' in his knapsack. There are 'N' items, each with a known weight and value. Considering the capacity constraints of the knapsack, calculate the maximum profit possible.
Input:
The first line contains a single integer 'T' representing the number of test cases.
For each test case:
- The first line contains two integers 'N' and 'W', representing the number of items and the maximum weight capacity of the knapsack.
- The second line contains 'N' space-separated integers denoting the weights of the items.
- The third line contains 'N' space-separated integers denoting the values of the items.
Output:
Output a single integer per test case representing the maximum profit the thief can achieve.
Provide each test case's result on a new line.
Example:
Input:
1
4 10
6 1 5 3
3 6 1 4
Output:
13
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 102
1 ≤ W ≤ 102
1 ≤ weights[i] ≤ 50
1 ≤ values[i] ≤ 102
Note: Items cannot be broken and the thief should take the whole item or none.

AnswerBot
4mo
The 0-1 Knapsack Problem involves maximizing profit by selecting items with known weights and values within a given weight capacity.
Understand the problem: Given items with weights and values, determi...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Samsung
Q. Suppose an array of length n sorted in ascending order is rotated between 1 and ...read more
Q. What are the ACID properties in DBMS?
Q. Sum of Digits Problem Statement Given an integer 'N', continue summing its digit...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Samsung Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design 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

