title: Check Occurrences Character Appear Together
signature: function check_occurrences_character_appear_together(s, c)
source_py: def check_occurrences_character_appear_together(s, c):
      oneSeen = False
      i = 0
      n = len(s)
      while (i < n):
          if (s[i] == c):
              if (oneSeen == True):
                  return False
              while ((i < n) and (s[i] == c)):
                  i = (i + 1)
              oneSeen = True
          else:
              i = (i + 1)
      return True
source_cpp: bool check_occurrences_character_appear_together(string s, char c) {
    bool oneSeen = false;
    int i = 0, n = s . length ( );
    while ( i < n ) {
      if ( s [ i ] == c ) {
        if ( oneSeen == true ) return false;
        while ( i < n && s [ i ] == c ) i ++;
        oneSeen = true;
      }
      else i ++;
    }
    return true;
  }
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, c, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(s, c) 
      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("gILrzLimS", 'm', true)
      print(string.format("TEST-0...%s",result))
  
      result = driver("307471222", '2', true)
      print(string.format("TEST-1...%s",result))
  
      result = driver("110", '0', true)
      print(string.format("TEST-2...%s",result))
  
      result = driver("GcAB", 'v', true)
      print(string.format("TEST-3...%s",result))
  
      result = driver("113", '3', true)
      print(string.format("TEST-4...%s",result))
  
      result = driver("011110010", '0', false)
      print(string.format("TEST-5...%s",result))
  
      result = driver("wcwob", 'w', false)
      print(string.format("TEST-6...%s",result))
  
      result = driver("74571582216153", '1', false)
      print(string.format("TEST-7...%s",result))
  
      result = driver("100000011", '0', true)
      print(string.format("TEST-8...%s",result))
  
      result = driver("ryPErkzY", 'q', true)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": true, "inputs": {"s": "gILrzLimS", "c": "m"}}, {"idx": 1, "outputs": true, "inputs": {"s": "307471222", "c": "2"}}, {"idx": 2, "outputs": true, "inputs": {"s": "110", "c": "0"}}, {"idx": 3, "outputs": true, "inputs": {"s": "GcAB", "c": "v"}}, {"idx": 4, "outputs": true, "inputs": {"s": "113", "c": "3"}}, {"idx": 5, "outputs": false, "inputs": {"s": "011110010", "c": "0"}}, {"idx": 6, "outputs": false, "inputs": {"s": "wcwob", "c": "w"}}, {"idx": 7, "outputs": false, "inputs": {"s": "74571582216153", "c": "1"}}, {"idx": 8, "outputs": true, "inputs": {"s": "100000011", "c": "0"}}, {"idx": 9, "outputs": true, "inputs": {"s": "ryPErkzY", "c": "q"}}]
question_info.extension: lua
question_info.entry_fn_name: check_occurrences_character_appear_together
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__