References:
        # https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring#Python2
324505
def longest_common_substring(s1, s2):
    
    m = [[0] * (1 + len(s2)) for i in range(1 + len(s1))]
    longest, x_longest = 0, 0
    for x in range(1, 1 + len(s1)):
        for y in range(1, 1 + len(s2)):
            if s1[x - 1] == s2[y - 1]:
                m[x][y] = m[x - 1][y - 1] + 1
                if m[x][y] > longest:
                    longest = m[x][y]
                    x_longest = x
            else:
                m[x][y] = 0
    return s1[x_longest - longest: x_longest]
1062138
def chars2str(chars) -> List[str]:
    
    strings = collections.deque()
    for subchars in chars:
        substrings = collections.deque()
        for char in subchars:
            if char:
                substrings.append(char.decode('utf-8'))
            else:
                substrings.append('')
        strings.append(''.join(substrings))
    return list(strings)
511142
function endsWith(longStr, shortStr) {
		var longLen = longStr.length, shortLen = shortStr.length;
		return (longLen >= shortLen) &&
			(longStr.substr(longLen - shortLen) === shortStr);
	}
1076510
def common_prefix(s1, s2):
    ""
    if not s1 or not s2:
        return ""
    k = 0
    while s1[k] == s2[k]:
        k = k + 1
        if k >= len(s1) or k >= len(s2):
            return s1[0:k]
    return s1[0:k]
460178
def longest_increasing_subsequence(x):
    
    n = len(x)
    p = [None] * n
    h = [None]
    b = [float('-inf')]  # - infinity
    for i in range(n):
        if x[i] > b[-1]:
            p[i] = h[-1]
            h.append(i)
            b.append(x[i])
        else:
            #   -- binary search: b[k - 1] < x[i] <= b[k]
            k = bisect_left(b, x[i])
            h[k] = i
            b[k] = x[i]
            p[i] = h[k - 1]
    # extract solution
    q = h[-1]
    s = []
    while q is not None:
        s.append(x[q])
        q = p[q]
    return s[::-1]
945018
function substr(astralSafeCharacterArray, len) {
        // var boundary, cutted, result
        var cutted = astralSafeCharacterArray.slice(0, len).join('');
        if (!this.reserveLastWord) {
            return cutted;
        }
        var boundary = astralSafeCharacterArray.slice(len - 1, len + 1).join('');
        // if truncate at word boundary, just return
        if (/\W/.test(boundary)) {
            return cutted;
        }
        if (this.reserveLastWord < 0) {
            var result = cutted.replace(/\w+$/, '');
            // if the cutted is not the first and the only word
            //   then return result, or return the whole word
            if (!(result.length === 0 && cutted.length === this.options.length)) {
                return result;
            }
        }
        // set max exceeded to 10 if this.reserveLastWord is true or > 0
        var maxExceeded = this.reserveLastWord !== true && this.reserveLastWord > 0
            ? this.reserveLastWord
            : 10;
        var mtc = astralSafeCharacterArray.slice(len).join('').match(/(\w+)/);
        var exceeded = mtc ? mtc[1] : '';
        return cutted + exceeded.substr(0, maxExceeded);
    }
14825
public static int longestCommonContiguousSubstring(String s, String t) {
    if (s.length() == 0 || t.length() == 0) {
      return 0;
    }
    int M = s.length();
    int N = t.length();
    int[][] d = new int[M + 1][N + 1];
    for (int j = 0; j <= N; j++) {
      d[0][j] = 0;
    }
    for (int i = 0; i <= M; i++) {
      d[i][0] = 0;
    }

    int max = 0;
    for (int i = 1; i <= M; i++) {
      for (int j = 1; j <= N; j++) {
        if (s.charAt(i - 1) == t.charAt(j - 1)) {
          d[i][j] = d[i - 1][j - 1] + 1;
        } else {
          d[i][j] = 0;
        }

        if (d[i][j] > max) {
          max = d[i][j];
        }
      }
    }
    // System.err.println("LCCS(" + s + "," + t + ") = " + max);
    return max;
  }
939244
public int DamerauLevenshteinDistance(String string2, int maxDistance) {
        if (baseString == null) return string2 == null ? 0 : string2.length(); //string2 ?? "").Length;
        if (string2 == null || string2.isEmpty()) return baseString.length();
        if(maxDistance == 0) return baseString.equals(string2) ? 0 : -1;

        // if strings of different lengths, ensure shorter string is in string1. This can result in a little
        // faster speed by spending more time spinning just the inner loop during the main processing.
        String string1;
        if (baseString.length() > string2.length()) {
            string1 = string2;
            string2 = baseString;
        } else {
            string1 = baseString;
        }
        int sLen = string1.length(); // this is also the minimun length of the two strings
        int tLen = string2.length();

        // suffix common to both strings can be ignored
        while ((sLen > 0) && (string1.charAt(sLen - 1) == string2.charAt(tLen - 1))) { sLen--; tLen--; }

        int start = 0;
        if ((string1.charAt(0) == string2.charAt(0)) || (sLen == 0)) { // if there'string1 a shared prefix, or all string1 matches string2'string1 suffix
            // prefix common to both strings can be ignored
            while ((start < sLen) && (string1.charAt(start) == string2.charAt(start))) start++;
            sLen -= start; // length of the part excluding common prefix and suffix
            tLen -= start;

            // if all of shorter string matches prefix and/or suffix of longer string, then
            // edit distance is just the delete of additional characters present in longer string
            if (sLen == 0) return tLen;

            string2 = string2.substring(start, start + tLen); // faster than string2[start+j] in inner loop below
        }
        int lenDiff = tLen - sLen;
        if ((maxDistance < 0) || (maxDistance > tLen)) {
            maxDistance = tLen;
        } else if (lenDiff > maxDistance) return -1;

        if (tLen > v0.length)
        {
            v0 = new int[tLen];
            v2 = new int[tLen];
        } else {
            for(int i = 0; i < tLen; i++) v2[i] = 0;    // Substituting Array.clear(v2, 0, tLen)
        }
        int j;
        for (j = 0; j < maxDistance; j++) v0[j] = j + 1;
        for (; j < tLen; j++) v0[j] = maxDistance + 1;

        int jStartOffset = maxDistance - (tLen - sLen);
        boolean haveMax = maxDistance < tLen;
        int jStart = 0;
        int jEnd = maxDistance;
        char sChar = string1.charAt(0);
        int current = 0;
        for (int i = 0; i < sLen; i++) {
            char prevsChar = sChar;
            sChar = string1.charAt(start+i);
            char tChar = string2.charAt(0);
            int left = i;
            current = left + 1;
            int nextTransCost = 0;
            // no need to look beyond window of lower right diagonal - maxDistance cells (lower right diag is i - lenDiff)
            // and the upper left diagonal + maxDistance cells (upper left is i)
            jStart += (i > jStartOffset) ? 1 : 0;
            jEnd += (jEnd < tLen) ? 1 : 0;
            for (j = jStart; j < jEnd; j++) {
                int above = current;
                int thisTransCost = nextTransCost;
                nextTransCost = v2[j];
                v2[j] = current = left; // cost of diagonal (substitution)
                left = v0[j];    // left now equals current cost (which will be diagonal at next iteration)
                char prevtChar = tChar;
                tChar = string2.charAt(j);
                if (sChar != tChar) {
                    if (left < current) current = left;   // insertion
                    if (above < current) current = above; // deletion
                    current++;
                    if ((i != 0) && (j != 0)
                            && (sChar == prevtChar)
                            && (prevsChar == tChar)) {
                        thisTransCost++;
                        if (thisTransCost < current) current = thisTransCost; // transposition
                    }
                }
                v0[j] = current;
            }
            if (haveMax && (v0[i + lenDiff] > maxDistance)) return -1;
        }
        return (current <= maxDistance) ? current : -1;
    }
572063
def iter_long(self, string):
		
		state = self.root
		last  = None

		index = 0
		while index < len(string):
			c = string[index]

			if c in state.children:
				state = state.children[c]

				if state.output is not nil:
					# save the last node on the path
					last = (state.output, index)

				index += 1
			else:
				if last:
					# return the saved match
					yield last

					# and start over, as we don't want overlapped results
					# Note: this leads to quadratic complexity in the worst case
					index = last[1] + 1
					state = self.root
					last  = None
				else:
					# if no output, perform classic Aho-Corasick algorithm
					while c not in state.children:
						state = state.fail

		# corner case
		if last:
			yield last
1342963
def trim_common_suffixes(strs, min_len=0):
    

    if len(strs) < 2:
        return 0, strs

    rev_strs = [s[::-1] for s in strs]

    trimmed, rev_strs = trim_common_prefixes(rev_strs, min_len)

    if trimmed:
        strs = [s[::-1] for s in rev_strs]

    return trimmed, strs
551359
def str2long(s):
    """"""
    if type(s) not in (types.StringType, types.UnicodeType):
        raise ValueError('the input must be a string')

    l = 0
    for i in s:
        l <<= 8
        l |= ord(i)

    return l
81560
function longestCommonPathPrefix(stra, strb) {
  const minlen = min(stra.length, strb.length);
  let common = 0;
  let lastSep = -1;
  for (; common < minlen; ++common) {
    const chr = stra[common];
    if (chr !== strb[common]) {
      break;
    }
    if (chr === sep) {
      lastSep = common;
    }
  }
  if (common === minlen &&
      (stra.length === minlen ?
        strb.length === minlen || strb[minlen] === sep :
        stra[minlen] === sep)) {
    return minlen + 1;
  }
  return lastSep + 1;
}
567548
function substr(val, start, length){
  utils.assertString(val, 'val');
  utils.assertType(start, 'unit', 'start');
  length = length && length.val;
  var res = val.string.substr(start.val, length);
  return val instanceof nodes.Ident
      ? new nodes.Ident(res)
      : new nodes.String(res);
}
1154183
function(str, end) {
    return (str.length >= end.length &&
            str.substring(str.length - end.length) === end);
  }
738643
private function longestCommonPrefixLength($s, $t)
    {
        $length = min(strlen($s), strlen($t));
        $i = 0;
        while ($i < $length) {
            if ($s [$i] !== $t [$i]) {
                break;
            }
            $i++;
        }
        return $i;
    }
362615
def limit_value_string_length(value):
    
    if isinstance(value, string_types) and len(value) > constants.MAX_VALUE_LABEL_TEXT_LENGTH:
        value = value[:constants.MAX_VALUE_LABEL_TEXT_LENGTH] + "..."
        final_string = " " + value + " "
    elif isinstance(value, (dict, list)) and len(str(value)) > constants.MAX_VALUE_LABEL_TEXT_LENGTH:
        value_text = str(value)[:constants.MAX_VALUE_LABEL_TEXT_LENGTH] + "..."
        final_string = " " + value_text + " "
    else:
        final_string = " " + str(value) + " "

    return final_string
830697
public static List<int[]> hunks(String s0, String s1) {
        List<int[]> lcs = longestCommonSubsequence(s0 ,s1);
        List<int[]> hunks = new ArrayList<int[]>();
        int inf0 = -1;
        int inf1 = -1;
        int last0 = -1;
        int last1 = -1;
        for (int i = 0; i < lcs.size(); i++) {
            int[] match = lcs.get(i);
            if (inf0 == -1 || inf1 == -1) {
                inf0 = match[0];
                inf1 = match[1];
            } else if (last0 + 1 != match[0] || last1 + 1 != match[1]) {
                hunks.add(new int[] {inf0, last0 + 1, inf1, last1 + 1});
                inf0 = match[0];
                inf1 = match[1];
            } else if (i == lcs.size() - 1) {
                hunks.add(new int[] {inf0, match[0] + 1, inf1, match[1] + 1});
                break;
            }
            last0 = match[0];
            last1 = match[1];
        }
        return hunks;
    }