title: Longest Prefix Also Suffix 1
signature: def longestPrefixAlsoSuffix1(s: String) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(s: String, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(s),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        "aabcdaabc", 
        4    
      )}")   
  
  
      println(s"TEST-1...${driver(
        "1372494598", 
        0    
      )}")   
  
  
      println(s"TEST-2...${driver(
        "110000100001", 
        1    
      )}")   
  
  
      println(s"TEST-3...${driver(
        "abcab", 
        2    
      )}")   
  
  
      println(s"TEST-4...${driver(
        "488938", 
        0    
      )}")   
  
  
      println(s"TEST-5...${driver(
        "011010101011", 
        3    
      )}")   
  
  
      println(s"TEST-6...${driver(
        "aaaa", 
        2    
      )}")   
  
  
      println(s"TEST-7...${driver(
        "3356203205", 
        0    
      )}")   
  
  
      println(s"TEST-8...${driver(
        "1010", 
        2    
      )}")   
  
  
      println(s"TEST-9...${driver(
        "kkXiiTZkGeh", 
        0    
      )}")   
  
  }
  
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;
  }