Skip to content

Practice Maximize Grid Happiness

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1659
LeetCode Problem

Maximize Grid Happiness

Problem Statement

Place up to introvertsCount introverts and extrovertsCount extroverts in separate cells of an m by n grid; leaving cells empty or people unplaced is allowed. An introvert contributes 120 minus 30 for each occupied side-adjacent neighbor. An extrovert contributes 40 plus 20 for each such neighbor. Compute each resident's contribution independently and maximize their total. Return that maximum happiness.

Source: Maximize Grid Happiness on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
m = 2, n = 3, introvertsCount = 1, extrovertsCount = 2
Output
240

# Example 2

Input
m = 3, n = 1, introvertsCount = 2, extrovertsCount = 1
Output
260

# Example 3

Input
m = 2, n = 2, introvertsCount = 4, extrovertsCount = 0
Output
240

Constraints

1 <= m, n <= 5
0 <= introvertsCount, extrovertsCount <= min(m * n, 6)

Related LeetCode Problems

Practice more problems similar to Maximize Grid Happiness.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.