title: Painting Fence Algorithm
signature: function paintingFenceAlgorithm(n: number, k: number): number {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(n: number, k: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(n, k),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(6, 30, 725841870);
    console.log(`TEST-0...${result}`);
  
    result = driver(23, 87, 370622679);
    console.log(`TEST-1...${result}`);
  
    result = driver(89, 31, 7554776);
    console.log(`TEST-2...${result}`);
  
    result = driver(63, 36, 76740139);
    console.log(`TEST-3...${result}`);
  
    result = driver(23, 68, 647498520);
    console.log(`TEST-4...${result}`);
  
    result = driver(44, 66, 70208793);
    console.log(`TEST-5...${result}`);
  
    result = driver(81, 18, 227130467);
    console.log(`TEST-6...${result}`);
  
    result = driver(43, 73, 204618786);
    console.log(`TEST-7...${result}`);
  
    result = driver(9, 42, 797370673);
    console.log(`TEST-8...${result}`);
  
    result = driver(41, 98, 903959704);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
source_py: def painting_fence_algorithm(n, k):
      total = k
      mod = 1000000007
      (same, diff) = (0, k)
      for i in range(2, (n + 1)):
          same = diff
          diff = (total * (k - 1))
          diff = (diff % mod)
          total = ((same + diff) % mod)
      return total
source_cpp: long painting_fence_algorithm(int n, int k) {
    long total = k;
    int mod = 1000000007;
    int same = 0, diff = k;
    for ( int i = 2;
    i <= n;
    i ++ ) {
      same = diff;
      diff = total * ( k - 1 );
      diff = diff % mod;
      total = ( same + diff ) % mod;
    }
    return total;
  }