Practice Number of Ways of Cutting a Pizza
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Number of Ways of Cutting a Pizza
Problem Statement
Given a rectangular pizza represented as a rows x cols matrix containing the following characters: 'A' (an apple) and '.' (empty cell) and given the integer k. You have to cut the pizza into k pieces using k-1 cuts. For each cut you choose the direction: vertical or horizontal, then you choose a cut position at the cell boundary and cut the pizza into two pieces. If you cut the pizza vertically, give the left part of the pizza to a person. If you cut the pizza horizontally, give the upper part of the pizza to a person. Give the last piece of pizza to the last person. Return the number of ways of cutting the pizza such that each piece contains at least one apple. Since the answer can be a huge number, return this modulo 10^9 + 7.
Source: Number of Ways of Cutting a Pizza on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
pizza = ["A..","AAA","..."], k = 3
3
# Example 2
pizza = ["A..","AA.","..."], k = 3
1
# Example 3
pizza = ["A..","A..","..."], k = 1
1
Constraints
Related LeetCode Problems
Practice more problems similar to Number of Ways of Cutting a Pizza.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.