title: Longest Prefix Also Suffix 1
signature: function longestPrefixAlsoSuffix1(s: string): number {
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.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"}}]
question_info.entry_cls_name: Solution
question_info.test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(s: string, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(s),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver("aabcdaabc", 4);
    console.log(`TEST-0...${result}`);
  
    result = driver("1372494598", 0);
    console.log(`TEST-1...${result}`);
  
    result = driver("110000100001", 1);
    console.log(`TEST-2...${result}`);
  
    result = driver("abcab", 2);
    console.log(`TEST-3...${result}`);
  
    result = driver("488938", 0);
    console.log(`TEST-4...${result}`);
  
    result = driver("011010101011", 3);
    console.log(`TEST-5...${result}`);
  
    result = driver("aaaa", 2);
    console.log(`TEST-6...${result}`);
  
    result = driver("3356203205", 0);
    console.log(`TEST-7...${result}`);
  
    result = driver("1010", 2);
    console.log(`TEST-8...${result}`);
  
    result = driver("kkXiiTZkGeh", 0);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: longestPrefixAlsoSuffix1
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js