Skip to content

Practice Count Number of Ways to Place Houses

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

Medium#2320
LeetCode Problem

Count Number of Ways to Place Houses

Problem Statement

There is a street with n * 2 plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed. Return the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street. Since the answer may be very large, return it modulo 10^9 + 7. Note that if a house is placed on the ith plot on one side of the street, a house can also be placed on the ith plot on the other side of the street.

Source: Count Number of Ways to Place Houses on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 1
Output
4

# Example 2

Input
n = 2
Output
9

Constraints

1 <= n <= 10^4

Related LeetCode Problems

Practice more problems similar to Count Number of Ways to Place Houses.

Review your practice with PhantomCodeAI

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