title: Longest Prefix Also Suffix 1
signature: function longest_prefix_also_suffix_1(s)
source_py: def longest_prefix_also_suffix_1(s):
      n = len(s)
      lps = ([0] * n)
      l = 0
      i = 1
      while (i < n):
          if (s[i] == s[l]):
              l = (l + 1)
              lps[i] = l
              i = (i + 1)
          elif (l != 0):
              l = lps[(l - 1)]
          else:
              lps[i] = 0
              i = (i + 1)
      res = lps[(n - 1)]
      if (res > (n / 2)):
          return (n // 2)
      else:
          return res
source_cpp: int longest_prefix_also_suffix_1(string s) {
    int n = s . length ( );
    int lps [ n ];
    lps [ 0 ] = 0;
    int len = 0;
    int i = 1;
    while ( i < n ) {
      if ( s [ i ] == s [ len ] ) {
        len ++;
        lps [ i ] = len;
        i ++;
      }
      else {
        if ( len != 0 ) {
          len = lps [ len - 1 ];
        }
        else {
          lps [ i ] = 0;
          i ++;
        }
      }
    }
    int res = lps [ n - 1 ];
    return ( res > n / 2 ) ? n / 2 : res;
  }
question_info.entry_fn_name: longest_prefix_also_suffix_1
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
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("aabcdaabc", 4)
      print(string.format("TEST-0...%s",result))
  
      result = driver("1372494598", 0)
      print(string.format("TEST-1...%s",result))
  
      result = driver("110000100001", 1)
      print(string.format("TEST-2...%s",result))
  
      result = driver("abcab", 2)
      print(string.format("TEST-3...%s",result))
  
      result = driver("488938", 0)
      print(string.format("TEST-4...%s",result))
  
      result = driver("011010101011", 3)
      print(string.format("TEST-5...%s",result))
  
      result = driver("aaaa", 2)
      print(string.format("TEST-6...%s",result))
  
      result = driver("3356203205", 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver("1010", 2)
      print(string.format("TEST-8...%s",result))
  
      result = driver("kkXiiTZkGeh", 0)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 4, "inputs": {"s": "aabcdaabc"}}, {"idx": 1, "outputs": 0, "inputs": {"s": "1372494598"}}, {"idx": 2, "outputs": 1, "inputs": {"s": "110000100001"}}, {"idx": 3, "outputs": 2, "inputs": {"s": "abcab"}}, {"idx": 4, "outputs": 0, "inputs": {"s": "488938"}}, {"idx": 5, "outputs": 3, "inputs": {"s": "011010101011"}}, {"idx": 6, "outputs": 2, "inputs": {"s": "aaaa"}}, {"idx": 7, "outputs": 0, "inputs": {"s": "3356203205"}}, {"idx": 8, "outputs": 2, "inputs": {"s": "1010"}}, {"idx": 9, "outputs": 0, "inputs": {"s": "kkXiiTZkGeh"}}]