Practice Manhattan Distances of All Arrangements of Pieces
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given three integers m, n, and k. There is a rectangular grid of size m × n containing k identical pieces. Return the sum of Manhattan distances between every pair of pieces over all valid arrangements of pieces. A valid arrangement is a placement of all k pieces on the grid with at most one piece per cell. Since the answer may be very large, return it modulo 10^9 + 7. The Manhattan Distance between two cells (xi, yi) and (xj, yj) is |xi - xj| + |yi - yj|.
Source: Manhattan Distances of All Arrangements of Pieces on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
m = 2, n = 2, k = 2
8
# Example 2
m = 1, n = 4, k = 3
20
Constraints
Related LeetCode Problems
Practice more problems similar to Manhattan Distances of All Arrangements of Pieces.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.