java.lang.Object
g2301_2400.s2320_count_number_of_ways_to_place_houses.Solution

public class Solution extends Object
2320 - Count Number of Ways to Place Houses.<p>Medium</p> <p>There is a street with <code>n * 2</code> <strong>plots</strong> , where there are <code>n</code> plots on each side of the street. The plots on each side are numbered from <code>1</code> to <code>n</code>. On each plot, a house can be placed.</p> <p>Return <em>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</em>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p>Note that if a house is placed on the <code>i<sup>th</sup></code> plot on one side of the street, a house can also be placed on the <code>i<sup>th</sup></code> plot on the other side of the street.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 1</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong></p> <p>Possible arrangements:</p> <ol> <li> <p>All plots are empty.</p> </li> <li> <p>A house is placed on one side of the street.</p> </li> <li> <p>A house is placed on the other side of the street.</p> </li> <li> <p>Two houses are placed, one on each side of the street.</p> </li> </ol> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/05/12/arrangements.png" alt="" /></p> <p><strong>Input:</strong> n = 2</p> <p><strong>Output:</strong> 9</p> <p><strong>Explanation:</strong> The 9 possible arrangements are shown in the diagram above.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countHousePlacements

      public int countHousePlacements(int n)