Count Number of Ways to Place Houses LeetCode solution in Java
1class Solution {2int mod = (int) 1e9 + 7;34public int countHousePlacements(int n) {56if (n == 1) return 4;7if (n == 2) return 9;8long a = 2;9long b = 3;10if (n == 1) return (int) (a % mod);11if (n == 2) return (int) (b % mod);12long c = 0;13for (int i = 3; i <= n; i++) {14c = (a + b) % mod;15a = b % mod;16b = c % mod;17}1819return (int) ((c * c) % mod);20}21}