title: Longest Prefix Also Suffix 1
signature: class Solution {
  
      public Integer longestPrefixAlsoSuffix1(String 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.extension: java
question_info.entry_fn_name: longestPrefixAlsoSuffix1
question_info.entry_cls_name: Solution
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.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(String s, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(s,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution("aabcdaabc", 4);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution("1372494598", 0);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution("110000100001", 1);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution("abcab", 2);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution("488938", 0);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution("011010101011", 3);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution("aaaa", 2);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution("3356203205", 0);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution("1010", 2);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution("kkXiiTZkGeh", 0);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(String s, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(s),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__