This is a verified interview question from Algo-university. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Colorful Construction" covers key patterns like DP.
"You are provided with a fixed number of red and blue blocks for the construction of a colorful monument. The construction must obey the following rules: * The colorful monument consists of some number of floors; * Let the monument consist of n floors, then the first floor of this monument should consist of n blocks, the second floor — of n — 1 blocks, the third one — of n — 2 blocks, and so on — the last floor should consist of only one block; * Each floor may only contain blocks of the same color. Let h be the maximum possible number of floors in the monument that can be built out of the provided number of red and blue blocks. Your task is to determine how many different colorful monuments having h floors can be built out of the available blocks. Two colorful monuments are considered different if there exists atleast one level that consists of red blocks in one tower and blue in the other. Since the answer may be too large, output the number of different possible monuments of height h modulo 10^9 + 7."
Join thousands of developers practicing for Algo-university.