PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This Coding & Algorithms question evaluates a candidate's ability to perform combinatorial optimization and benefit-based assignment reasoning on arrays, testing algorithm design, complexity-aware implementation, and quantitative decision-making in constrained assignment problems.

  • easy
  • MathWorks
  • Coding & Algorithms
  • Software Engineer

How to maximize rewards with exactly k tasks

Company: MathWorks

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are assigning **n** independent tasks to **two interns**. - Each task must be done by exactly one intern. - If intern 1 does task *i*, you earn `reward1[i]` points. - If intern 2 does task *i*, you earn `reward2[i]` points. - Intern 1 must be assigned **exactly `k` tasks**; intern 2 gets the remaining `n - k` tasks. - Tasks can be assigned in any order (no contiguity requirement). **Goal:** Return the **maximum total points** achievable. ### Input - `reward1`: integer array of length `n` - `reward2`: integer array of length `n` - `k`: integer (`0 ≤ k ≤ n`) ### Output - An integer: the maximum possible total reward. ### Notes / Expected Complexity Design an algorithm that works efficiently for large `n` (e.g., up to `10^5`).

Quick Answer: This Coding & Algorithms question evaluates a candidate's ability to perform combinatorial optimization and benefit-based assignment reasoning on arrays, testing algorithm design, complexity-aware implementation, and quantitative decision-making in constrained assignment problems.

Assign exactly k tasks to intern 1 and the rest to intern 2 to maximize total reward.

Examples

Input: ([10, 20, 30], [5, 50, 5], 2)

Expected Output: 90

Explanation: Choose largest deltas.

Input: ([1, 2], [10, 20], 0)

Expected Output: 30

Explanation: All intern 2.

Input: ([5, 1], [1, 5], 2)

Expected Output: 6

Explanation: All intern 1.

Hints

  1. Start with all tasks assigned to intern 2, then choose the k largest reward differences.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimize shortest path by adding weight-1 edges - MathWorks (easy)
  • Maximize minimum after K decrements - MathWorks (easy)
  • Maximize minimum value after k decrements - MathWorks (medium)
  • Determine Whether P's Position Is Unique - MathWorks (medium)
  • Minimize reduction cost and validate equal-sum pairs - MathWorks (medium)