title: Painting Fence Algorithm
signature: def paintingFenceAlgorithm(n: Int, k: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(n: Int, k: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(n, k),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        6, 30, 
        725841870    
      )}")   
  
  
      println(s"TEST-1...${driver(
        23, 87, 
        370622679    
      )}")   
  
  
      println(s"TEST-2...${driver(
        89, 31, 
        7554776    
      )}")   
  
  
      println(s"TEST-3...${driver(
        63, 36, 
        76740139    
      )}")   
  
  
      println(s"TEST-4...${driver(
        23, 68, 
        647498520    
      )}")   
  
  
      println(s"TEST-5...${driver(
        44, 66, 
        70208793    
      )}")   
  
  
      println(s"TEST-6...${driver(
        81, 18, 
        227130467    
      )}")   
  
  
      println(s"TEST-7...${driver(
        43, 73, 
        204618786    
      )}")   
  
  
      println(s"TEST-8...${driver(
        9, 42, 
        797370673    
      )}")   
  
  
      println(s"TEST-9...${driver(
        41, 98, 
        903959704    
      )}")   
  
  }
  
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;
  }