title: Number Of Substrings With Odd Decimal Value In A Binary String
signature: function number_of_substrings_with_odd_decimal_value_in_a_binary_string(s)
source_py: def number_of_substrings_with_odd_decimal_value_in_a_binary_string(s):
      n = len(s)
      auxArr = [0 for i in range(n)]
      if (s[0] == '1'):
          auxArr[0] = 1
      for i in range(0, n):
          if (s[i] == '1'):
              auxArr[i] = (auxArr[(i - 1)] + 1)
          else:
              auxArr[i] = auxArr[(i - 1)]
      count = 0
      for i in range((n - 1), (- 1), (- 1)):
          if (s[i] == '1'):
              count += auxArr[i]
      return count
source_cpp: int number_of_substrings_with_odd_decimal_value_in_a_binary_string(string s) {
    int n = s . length ( );
    int auxArr [ n ] = {
      0 };
      if ( s [ 0 ] == '1' ) auxArr [ 0 ] = 1;
      for ( int i = 1;
      i < n;
      i ++ ) {
        if ( s [ i ] == '1' ) auxArr [ i ] = auxArr [ i - 1 ] + 1;
        else auxArr [ i ] = auxArr [ i - 1 ];
      }
      int count = 0;
      for ( int i = n - 1;
      i >= 0;
      i -- ) if ( s [ i ] == '1' ) count += auxArr [ i ];
      return count;
    }
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(s, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(s) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver("OGiOkJF", 0)
      print(string.format("TEST-0...%s",result))
  
      result = driver("517376", 1)
      print(string.format("TEST-1...%s",result))
  
      result = driver("11", 3)
      print(string.format("TEST-2...%s",result))
  
      result = driver("Ze", 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver("8763644247018", 1)
      print(string.format("TEST-4...%s",result))
  
      result = driver("00111010001", 15)
      print(string.format("TEST-5...%s",result))
  
      result = driver("HGwkBKUOVu", 0)
      print(string.format("TEST-6...%s",result))
  
      result = driver("652", 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver("101000011110", 21)
      print(string.format("TEST-8...%s",result))
  
      result = driver("kvdpG ", 0)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"s": "OGiOkJF"}}, {"idx": 1, "outputs": 1, "inputs": {"s": "517376"}}, {"idx": 2, "outputs": 3, "inputs": {"s": "11"}}, {"idx": 3, "outputs": 0, "inputs": {"s": "Ze"}}, {"idx": 4, "outputs": 1, "inputs": {"s": "8763644247018"}}, {"idx": 5, "outputs": 15, "inputs": {"s": "00111010001"}}, {"idx": 6, "outputs": 0, "inputs": {"s": "HGwkBKUOVu"}}, {"idx": 7, "outputs": 0, "inputs": {"s": "652"}}, {"idx": 8, "outputs": 21, "inputs": {"s": "101000011110"}}, {"idx": 9, "outputs": 0, "inputs": {"s": "kvdpG "}}]
question_info.extension: lua
question_info.entry_fn_name: number_of_substrings_with_odd_decimal_value_in_a_binary_string
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__