title: Minimum Time Write Characters Using Insert Delete Copy Operation
signature: class Solution {
  
      public Integer minimumTimeWriteCharactersUsingInsertDeleteCopyOperation(Integer n, Integer insrt, Integer remov, Integer cpy) {
source_py: def minimum_time_write_characters_using_insert_delete_copy_operation(N, insrt, remov, cpy):
      if (N == 0):
          return 0
      if (N == 1):
          return insrt
      dp = ([0] * (N + 1))
      for i in range(1, (N + 1)):
          if ((i % 2) == 0):
              dp[i] = min((dp[(i - 1)] + insrt), (dp[(i // 2)] + cpy))
          else:
              dp[i] = min((dp[(i - 1)] + insrt), ((dp[((i + 1) // 2)] + cpy) + remov))
      return dp[N]
source_cpp: int minimum_time_write_characters_using_insert_delete_copy_operation(int N, int insert, int remove, int copy) {
    if ( N == 0 ) return 0;
    if ( N == 1 ) return insert;
    int dp [ N + 1 ];
    memset ( dp, 0, sizeof ( dp ) );
    for ( int i = 1;
    i <= N;
    i ++ ) {
      if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert, dp [ i / 2 ] + copy );
      else dp [ i ] = min ( dp [ i - 1 ] + insert, dp [ ( i + 1 ) / 2 ] + copy + remove );
    }
    return dp [ N ];
  }
question_info.extension: java
question_info.entry_fn_name: minimumTimeWriteCharactersUsingInsertDeleteCopyOperation
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 351, "inputs": {"n": 59, "insrt": 75, "remov": 12, "cpy": 45}}, {"idx": 1, "outputs": 382, "inputs": {"n": 66, "insrt": 68, "remov": 32, "cpy": 41}}, {"idx": 2, "outputs": 195, "inputs": {"n": 98, "insrt": 55, "remov": 69, "cpy": 5}}, {"idx": 3, "outputs": 76, "inputs": {"n": 63, "insrt": 4, "remov": 41, "cpy": 12}}, {"idx": 4, "outputs": 460, "inputs": {"n": 99, "insrt": 37, "remov": 98, "cpy": 55}}, {"idx": 5, "outputs": 147, "inputs": {"n": 45, "insrt": 28, "remov": 59, "cpy": 7}}, {"idx": 6, "outputs": 405, "inputs": {"n": 60, "insrt": 53, "remov": 40, "cpy": 52}}, {"idx": 7, "outputs": 392, "inputs": {"n": 11, "insrt": 96, "remov": 50, "cpy": 50}}, {"idx": 8, "outputs": 694, "inputs": {"n": 96, "insrt": 95, "remov": 48, "cpy": 84}}, {"idx": 9, "outputs": 244, "inputs": {"n": 54, "insrt": 6, "remov": 50, "cpy": 82}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(Integer n, Integer insrt, Integer remov, Integer cpy, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(n, insrt, remov, cpy,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(59, 75, 12, 45, 351);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(66, 68, 32, 41, 382);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(98, 55, 69, 5, 195);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(63, 4, 41, 12, 76);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(99, 37, 98, 55, 460);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(45, 28, 59, 7, 147);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(60, 53, 40, 52, 405);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(11, 96, 50, 50, 392);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(96, 95, 48, 84, 694);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(54, 6, 50, 82, 244);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(Integer n, Integer insrt, Integer remov, Integer cpy, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(n, insrt, remov, cpy),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__