K Items With the Maximum Sum Problem
K Items With the Maximum Sum Problem — ExecCode Easy DSA Practice
Solve the K Items With the Maximum Sum problem on ExecCode. Free online easy DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given four non-negativeintegers numOnes, numZeros, numNegOnes, and k. Your task is to compute the required answer and return the maximum possible sum of numbers written on the items. There is a bag that consists of items, each item has a number 1, 0, or -1 written on it. The bag initially contains: - numOnes items with 1s written on them. - numZeroes items with 0s written on them.
Examples
Input {"numOnes": 3, "numZeros": 2, "numNegOnes": 0, "k": 2}; Output 2. Input {"numOnes": 3, "numZeros": 2, "numNegOnes": 0, "k": 4}; Output 3
Constraints
0 <= numOnes, numZeros, numNegOnes <= 50 0 <= k <= numOnes + numZeros + numNegOnes
Practice K Items With the Maximum Sum free on ExecCode. Browse DSA problems, topic map, and placement guides.