Statistics

Problem Statement for "PalindromePath"

Problem Statement

You are given an undirected graph with n nodes, labeled 0 through n-1. You are given the description of its edges in int[]s a and b and in the String c. For each valid i, the vertices a[i] and b[i] are connected by an edge, and the character c[i] is the label of that edge.

A walk in the graph is any sequence of consecutive edges. (In other words, a walk is a path that may visit the same vertex and also use the same edge multiple times.) The length of a walk is the number of edges it contains. The label of a walk is the concatenation of labels of edges it contains, in order.

A palindrome is a string that reads the same forwards and backwards. Some palindromes: "a", "abba", "racecar", "steponnopets".

We are interested in walks that go from node 0 to node 1 and have a palindromic label. Return the length of the shortest such walk. If there is no such walk, return -1 instead.

Definition

Class:
PalindromePath
Method:
shortestLength
Parameters:
int, int[], int[], String
Returns:
int
Method signature:
int shortestLength(int n, int[] a, int[] b, String c)
(be sure your method is public)

Constraints

  • n will be between 2 and 20, inclusive.
  • a will contain between 1 and n*(n-1)/2 elements, inclusive.
  • a, b and c will contain the same number of elements.
  • Each element in a will be between 0 and n-1, inclusive.
  • Each element in b will be between 0 and n-1, inclusive.
  • Each character in c will be a lowercase English letter ('a'-'z').
  • For each valid i, a[i] != b[i].
  • If i!=j then {a[i], b[i]} != {a[j], b[j]}.

Examples

  1. 5

    {2,2,0,3,4}

    {0,1,3,4,1}

    "abxyx"

    Returns: 3

    The shortest walk between 0 and 1 is 0-2-1. However, the label of this walk is "ab" which is not a palindrome. The shortest walk that has a palindromic label is 0-3-4-1.

  2. 5

    {2,2,0,3,4}

    {0,1,3,4,1}

    "abxyz"

    Returns: -1

    This time there is no such path.

  3. 7

    {0,0,3,4,5,6}

    {2,3,4,5,6,1}

    "abaaaa"

    Returns: 9

    Note that sometimes you need to use an edge more than once: the optimal solution is 0-2-0-2-0-3-4-5-6-1.

  4. 6

    {0,0,3,4,5}

    {2,3,4,5,1}

    "abaaa"

    Returns: -1

  5. 2

    {0}

    {1}

    "x"

    Returns: 1

  6. 20

    {18}

    {19}

    "z"

    Returns: -1

  7. 19

    {0,2,3,0,4,5,6,7,8,9,10,1,12,13,14,15,16,17}

    {2,3,1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}

    "aabaaaaaaaaaaaaaaa"

    Returns: 5

  8. 20

    {0,2,2,4,4,6,6,8,8,10,10,1,11,12,13,14,15,16,17,17,18}

    {2,3,4,5,6,7,8,9,10,1,11,11,12,13,14,15,16,17,18,19,19}

    "yaxayaxatyaaaaaaaaaax"

    Returns: 73

  9. 20

    {0,18,5,1,2,11,13,1,15,11,12,15,11,13,11,7,17,1,16,2,0,8,10,10,13,3,16,16,4,3,13,18,17,6,4,9,17,10,11,4,7,17,3,9,0,15,4,3,2,16,8,4,13,18,7,8}

    {9,2,1,11,7,4,12,16,7,18,7,14,2,4,13,4,19,9,15,8,2,6,9,6,8,4,0,11,19,17,15,4,6,1,12,17,12,1,12,6,11,7,5,18,11,10,17,15,10,14,19,1,19,0,8,3}

    "kcphaoqiapblddkkleokejqpjkqkcknmlrgdkgikhprlgfcjnemamihf"

    Returns: 7

  10. 5

    {3,4,4,0}

    {4,1,2,3}

    "dfvo"

    Returns: -1

  11. 12

    {11,6,2,2,10,11,2,4,6,0}

    {8,0,5,1,4,10,11,3,8,2}

    "avohnhpcfm"

    Returns: -1

  12. 10

    {9,6,2,9,5,0,1,9,8,7,9,9,8,5,5,3,3,6,4,3,4,9}

    {2,1,1,7,2,3,8,5,6,2,4,6,2,4,0,9,5,5,1,6,6,1}

    "cflgalleefhmbaiiijmhhk"

    Returns: -1

  13. 19

    {15,17,14,10,2,6,18,6,17,0,1,7,15,1,10,14,4,9,6,16,8,15,12,5,10,10,16,16,10,8,11,18,4,4,1,10,3,8,5,18,10,3,8,12,16,16,5,3,4,6,4,12,16,7,11,15,14,0,8,2,12,5,4,7,1,13,8,10,5,4,8,3,11,3,4,17,5,3,12,17,2,2,3,2,6}

    {10,10,15,9,15,3,15,4,15,15,6,8,8,5,8,13,5,8,5,18,12,16,4,7,12,7,2,14,6,4,2,14,7,0,17,13,15,1,9,11,14,14,11,17,8,6,11,9,11,17,10,1,5,17,9,5,7,14,18,9,18,17,13,16,18,17,3,11,13,3,17,16,16,13,2,4,0,1,2,11,5,14,5,3,12}

    "jikonlrmaimoccophpjqoiornolebdfaefqcniprkedciblnhobabomdhlblmllgjprcncgmbomlocjfgkqng"

    Returns: 3

  14. 14

    {11,1,9,1,9,1,10,0,5,11,8,12,11,10,5,12,4,0,13,2,7,4,10,6,13,3,7,7,9,5,6,5,3,0,8,9,9,11,4,0,13,3,2,10,4,10,10,11}

    {1,5,12,13,10,12,13,8,12,8,9,6,3,6,13,0,12,9,12,5,13,5,11,0,11,13,0,2,3,6,4,10,12,2,1,4,2,7,10,4,8,6,10,0,1,12,1,4}

    "lqjtapexxljligpptlcwrudipippjofmrdbiooqnjaeljqge"

    Returns: 2

  15. 18

    {6,17,5,17,13,9,2,1,0,15,8,14,2,16,13,7,12,3,8,10,4,7,7,14,1,15,17,15,10,13,11,3,10,6,6,9,17,10,16,5,11,3,9,12,7,4,12,8,1,3,0,11,9,0,8,14,9,9,6,0,1,9,10,14,5,16,9,6,3,5,6,5,17,13,3,12,4,16}

    {10,5,4,16,0,2,11,8,11,3,15,16,15,7,3,15,3,6,2,11,6,13,5,15,6,13,4,10,0,14,7,2,5,15,2,16,6,17,15,3,6,10,0,4,9,8,14,10,2,14,5,8,4,12,16,5,10,12,9,4,3,14,13,4,2,2,17,5,9,11,12,1,14,8,11,10,13,3}

    "aedbcabebbdceeedeecaabadbddebbdaadbebbecbddccededbdedebacacacaacdbbeaabacacced"

    Returns: 3

  16. 12

    {6,8,3,8,10,9,6,9,3,6,11,8,10,6,4,4,5,11,6,10,6,3,0,11,5,1,10,1,9,5,11,1,5,7,2,1,0}

    {7,6,4,10,11,3,11,4,0,3,0,2,5,4,7,2,7,8,10,0,9,10,7,2,8,4,9,6,8,9,1,2,6,11,6,8,2}

    "bcbbbabccaacbacacabcacabbabacaccaaaba"

    Returns: 3

  17. 18

    {15}

    {17}

    "e"

    Returns: -1

  18. 7

    {3,5}

    {2,0}

    "id"

    Returns: -1

  19. 20

    {0,18,5,1,2,11,13,1,15,11,12,15,11,13,11,7,17,1,16,2,0,8,10,10,13,3,16,16,4,3,13,18,17,6,4,9,17,10,11,4,7,17,3,9,0,15,4,3,2,16,8,4,13,18,7,8}

    {9,2,1,11,7,4,12,16,7,18,7,14,2,4,13,4,19,9,15,8,2,6,9,6,8,4,0,11,19,17,15,4,6,1,12,17,12,1,12,6,11,7,5,18,11,10,17,15,10,14,19,1,19,0,8,3}

    "kcphaoqiapblddkkleokejqpjkqkcknmlrgdkgikhprlgfcjnemamihf"

    Returns: 7

  20. 5

    {3,4,4,0}

    {4,1,2,3}

    "dfvo"

    Returns: -1

  21. 12

    {11,6,2,2,10,11,2,4,6,0}

    {8,0,5,1,4,10,11,3,8,2}

    "avohnhpcfm"

    Returns: -1

  22. 10

    {9,6,2,9,5,0,1,9,8,7,9,9,8,5,5,3,3,6,4,3,4,9}

    {2,1,1,7,2,3,8,5,6,2,4,6,2,4,0,9,5,5,1,6,6,1}

    "cflgalleefhmbaiiijmhhk"

    Returns: -1

  23. 19

    {15,17,14,10,2,6,18,6,17,0,1,7,15,1,10,14,4,9,6,16,8,15,12,5,10,10,16,16,10,8,11,18,4,4,1,10,3,8,5,18,10,3,8,12,16,16,5,3,4,6,4,12,16,7,11,15,14,0,8,2,12,5,4,7,1,13,8,10,5,4,8,3,11,3,4,17,5,3,12,17,2,2,3,2,6}

    {10,10,15,9,15,3,15,4,15,15,6,8,8,5,8,13,5,8,5,18,12,16,4,7,12,7,2,14,6,4,2,14,7,0,17,13,15,1,9,11,14,14,11,17,8,6,11,9,11,17,10,1,5,17,9,5,7,14,18,9,18,17,13,16,18,17,3,11,13,3,17,16,16,13,2,4,0,1,2,11,5,14,5,3,12}

    "jikonlrmaimoccophpjqoiornolebdfaefqcniprkedciblnhobabomdhlblmllgjprcncgmbomlocjfgkqng"

    Returns: 3

  24. 14

    {11,1,9,1,9,1,10,0,5,11,8,12,11,10,5,12,4,0,13,2,7,4,10,6,13,3,7,7,9,5,6,5,3,0,8,9,9,11,4,0,13,3,2,10,4,10,10,11}

    {1,5,12,13,10,12,13,8,12,8,9,6,3,6,13,0,12,9,12,5,13,5,11,0,11,13,0,2,3,6,4,10,12,2,1,4,2,7,10,4,8,6,10,0,1,12,1,4}

    "lqjtapexxljligpptlcwrudipippjofmrdbiooqnjaeljqge"

    Returns: 2

  25. 18

    {6,17,5,17,13,9,2,1,0,15,8,14,2,16,13,7,12,3,8,10,4,7,7,14,1,15,17,15,10,13,11,3,10,6,6,9,17,10,16,5,11,3,9,12,7,4,12,8,1,3,0,11,9,0,8,14,9,9,6,0,1,9,10,14,5,16,9,6,3,5,6,5,17,13,3,12,4,16}

    {10,5,4,16,0,2,11,8,11,3,15,16,15,7,3,15,3,6,2,11,6,13,5,15,6,13,4,10,0,14,7,2,5,15,2,16,6,17,15,3,6,10,0,4,9,8,14,10,2,14,5,8,4,12,16,5,10,12,9,4,3,14,13,4,2,2,17,5,9,11,12,1,14,8,11,10,13,3}

    "aedbcabebbdceeedeecaabadbddebbdaadbebbecbddccededbdedebacacacaacdbbeaabacacced"

    Returns: 3

  26. 12

    {6,8,3,8,10,9,6,9,3,6,11,8,10,6,4,4,5,11,6,10,6,3,0,11,5,1,10,1,9,5,11,1,5,7,2,1,0}

    {7,6,4,10,11,3,11,4,0,3,0,2,5,4,7,2,7,8,10,0,9,10,7,2,8,4,9,6,8,9,1,2,6,11,6,8,2}

    "bcbbbabccaacbacacabcacabbabacaccaaaba"

    Returns: 3

  27. 18

    {15}

    {17}

    "e"

    Returns: -1

  28. 7

    {3,5}

    {2,0}

    "id"

    Returns: -1

  29. 20

    {0,18,5,1,2,11,13,1,15,11,12,15,11,13,11,7,17,1,16,2,0,8,10,10,13,3,16,16,4,3,13,18,17,6,4,9,17,10,11,4,7,17,3,9,0,15,4,3,2,16,8,4,13,18,7,8}

    {9,2,1,11,7,4,12,16,7,18,7,14,2,4,13,4,19,9,15,8,2,6,9,6,8,4,0,11,19,17,15,4,6,1,12,17,12,1,12,6,11,7,5,18,11,10,17,15,10,14,19,1,19,0,8,3}

    "kcphaoqiapblddkkleokejqpjkqkcknmlrgdkgikhprlgfcjnemamihf"

    Returns: 7

  30. 5

    {3,4,4,0}

    {4,1,2,3}

    "dfvo"

    Returns: -1

  31. 12

    {11,6,2,2,10,11,2,4,6,0}

    {8,0,5,1,4,10,11,3,8,2}

    "avohnhpcfm"

    Returns: -1

  32. 10

    {9,6,2,9,5,0,1,9,8,7,9,9,8,5,5,3,3,6,4,3,4,9}

    {2,1,1,7,2,3,8,5,6,2,4,6,2,4,0,9,5,5,1,6,6,1}

    "cflgalleefhmbaiiijmhhk"

    Returns: -1

  33. 19

    {15,17,14,10,2,6,18,6,17,0,1,7,15,1,10,14,4,9,6,16,8,15,12,5,10,10,16,16,10,8,11,18,4,4,1,10,3,8,5,18,10,3,8,12,16,16,5,3,4,6,4,12,16,7,11,15,14,0,8,2,12,5,4,7,1,13,8,10,5,4,8,3,11,3,4,17,5,3,12,17,2,2,3,2,6}

    {10,10,15,9,15,3,15,4,15,15,6,8,8,5,8,13,5,8,5,18,12,16,4,7,12,7,2,14,6,4,2,14,7,0,17,13,15,1,9,11,14,14,11,17,8,6,11,9,11,17,10,1,5,17,9,5,7,14,18,9,18,17,13,16,18,17,3,11,13,3,17,16,16,13,2,4,0,1,2,11,5,14,5,3,12}

    "jikonlrmaimoccophpjqoiornolebdfaefqcniprkedciblnhobabomdhlblmllgjprcncgmbomlocjfgkqng"

    Returns: 3

  34. 14

    {11,1,9,1,9,1,10,0,5,11,8,12,11,10,5,12,4,0,13,2,7,4,10,6,13,3,7,7,9,5,6,5,3,0,8,9,9,11,4,0,13,3,2,10,4,10,10,11}

    {1,5,12,13,10,12,13,8,12,8,9,6,3,6,13,0,12,9,12,5,13,5,11,0,11,13,0,2,3,6,4,10,12,2,1,4,2,7,10,4,8,6,10,0,1,12,1,4}

    "lqjtapexxljligpptlcwrudipippjofmrdbiooqnjaeljqge"

    Returns: 2

  35. 18

    {6,17,5,17,13,9,2,1,0,15,8,14,2,16,13,7,12,3,8,10,4,7,7,14,1,15,17,15,10,13,11,3,10,6,6,9,17,10,16,5,11,3,9,12,7,4,12,8,1,3,0,11,9,0,8,14,9,9,6,0,1,9,10,14,5,16,9,6,3,5,6,5,17,13,3,12,4,16}

    {10,5,4,16,0,2,11,8,11,3,15,16,15,7,3,15,3,6,2,11,6,13,5,15,6,13,4,10,0,14,7,2,5,15,2,16,6,17,15,3,6,10,0,4,9,8,14,10,2,14,5,8,4,12,16,5,10,12,9,4,3,14,13,4,2,2,17,5,9,11,12,1,14,8,11,10,13,3}

    "aedbcabebbdceeedeecaabadbddebbdaadbebbecbddccededbdedebacacacaacdbbeaabacacced"

    Returns: 3

  36. 12

    {6,8,3,8,10,9,6,9,3,6,11,8,10,6,4,4,5,11,6,10,6,3,0,11,5,1,10,1,9,5,11,1,5,7,2,1,0}

    {7,6,4,10,11,3,11,4,0,3,0,2,5,4,7,2,7,8,10,0,9,10,7,2,8,4,9,6,8,9,1,2,6,11,6,8,2}

    "bcbbbabccaacbacacabcacabbabacaccaaaba"

    Returns: 3

  37. 18

    {15}

    {17}

    "e"

    Returns: -1

  38. 7

    {3,5}

    {2,0}

    "id"

    Returns: -1

  39. 20

    {0,18,5,1,2,11,13,1,15,11,12,15,11,13,11,7,17,1,16,2,0,8,10,10,13,3,16,16,4,3,13,18,17,6,4,9,17,10,11,4,7,17,3,9,0,15,4,3,2,16,8,4,13,18,7,8}

    {9,2,1,11,7,4,12,16,7,18,7,14,2,4,13,4,19,9,15,8,2,6,9,6,8,4,0,11,19,17,15,4,6,1,12,17,12,1,12,6,11,7,5,18,11,10,17,15,10,14,19,1,19,0,8,3}

    "kcphaoqiapblddkkleokejqpjkqkcknmlrgdkgikhprlgfcjnemamihf"

    Returns: 7

  40. 5

    {3,4,4,0}

    {4,1,2,3}

    "dfvo"

    Returns: -1

  41. 12

    {11,6,2,2,10,11,2,4,6,0}

    {8,0,5,1,4,10,11,3,8,2}

    "avohnhpcfm"

    Returns: -1

  42. 10

    {9,6,2,9,5,0,1,9,8,7,9,9,8,5,5,3,3,6,4,3,4,9}

    {2,1,1,7,2,3,8,5,6,2,4,6,2,4,0,9,5,5,1,6,6,1}

    "cflgalleefhmbaiiijmhhk"

    Returns: -1

  43. 19

    {15,17,14,10,2,6,18,6,17,0,1,7,15,1,10,14,4,9,6,16,8,15,12,5,10,10,16,16,10,8,11,18,4,4,1,10,3,8,5,18,10,3,8,12,16,16,5,3,4,6,4,12,16,7,11,15,14,0,8,2,12,5,4,7,1,13,8,10,5,4,8,3,11,3,4,17,5,3,12,17,2,2,3,2,6}

    {10,10,15,9,15,3,15,4,15,15,6,8,8,5,8,13,5,8,5,18,12,16,4,7,12,7,2,14,6,4,2,14,7,0,17,13,15,1,9,11,14,14,11,17,8,6,11,9,11,17,10,1,5,17,9,5,7,14,18,9,18,17,13,16,18,17,3,11,13,3,17,16,16,13,2,4,0,1,2,11,5,14,5,3,12}

    "jikonlrmaimoccophpjqoiornolebdfaefqcniprkedciblnhobabomdhlblmllgjprcncgmbomlocjfgkqng"

    Returns: 3

  44. 14

    {11,1,9,1,9,1,10,0,5,11,8,12,11,10,5,12,4,0,13,2,7,4,10,6,13,3,7,7,9,5,6,5,3,0,8,9,9,11,4,0,13,3,2,10,4,10,10,11}

    {1,5,12,13,10,12,13,8,12,8,9,6,3,6,13,0,12,9,12,5,13,5,11,0,11,13,0,2,3,6,4,10,12,2,1,4,2,7,10,4,8,6,10,0,1,12,1,4}

    "lqjtapexxljligpptlcwrudipippjofmrdbiooqnjaeljqge"

    Returns: 2

  45. 18

    {6,17,5,17,13,9,2,1,0,15,8,14,2,16,13,7,12,3,8,10,4,7,7,14,1,15,17,15,10,13,11,3,10,6,6,9,17,10,16,5,11,3,9,12,7,4,12,8,1,3,0,11,9,0,8,14,9,9,6,0,1,9,10,14,5,16,9,6,3,5,6,5,17,13,3,12,4,16}

    {10,5,4,16,0,2,11,8,11,3,15,16,15,7,3,15,3,6,2,11,6,13,5,15,6,13,4,10,0,14,7,2,5,15,2,16,6,17,15,3,6,10,0,4,9,8,14,10,2,14,5,8,4,12,16,5,10,12,9,4,3,14,13,4,2,2,17,5,9,11,12,1,14,8,11,10,13,3}

    "aedbcabebbdceeedeecaabadbddebbdaadbebbecbddccededbdedebacacacaacdbbeaabacacced"

    Returns: 3

  46. 12

    {6,8,3,8,10,9,6,9,3,6,11,8,10,6,4,4,5,11,6,10,6,3,0,11,5,1,10,1,9,5,11,1,5,7,2,1,0}

    {7,6,4,10,11,3,11,4,0,3,0,2,5,4,7,2,7,8,10,0,9,10,7,2,8,4,9,6,8,9,1,2,6,11,6,8,2}

    "bcbbbabccaacbacacabcacabbabacaccaaaba"

    Returns: 3

  47. 18

    {15}

    {17}

    "e"

    Returns: -1

  48. 7

    {3,5}

    {2,0}

    "id"

    Returns: -1

  49. 20

    {0,18,5,1,2,11,13,1,15,11,12,15,11,13,11,7,17,1,16,2,0,8,10,10,13,3,16,16,4,3,13,18,17,6,4,9,17,10,11,4,7,17,3,9,0,15,4,3,2,16,8,4,13,18,7,8}

    {9,2,1,11,7,4,12,16,7,18,7,14,2,4,13,4,19,9,15,8,2,6,9,6,8,4,0,11,19,17,15,4,6,1,12,17,12,1,12,6,11,7,5,18,11,10,17,15,10,14,19,1,19,0,8,3}

    "kcphaoqiapblddkkleokejqpjkqkcknmlrgdkgikhprlgfcjnemamihf"

    Returns: 7

  50. 5

    {3,4,4,0}

    {4,1,2,3}

    "dfvo"

    Returns: -1

  51. 12

    {11,6,2,2,10,11,2,4,6,0}

    {8,0,5,1,4,10,11,3,8,2}

    "avohnhpcfm"

    Returns: -1

  52. 10

    {9,6,2,9,5,0,1,9,8,7,9,9,8,5,5,3,3,6,4,3,4,9}

    {2,1,1,7,2,3,8,5,6,2,4,6,2,4,0,9,5,5,1,6,6,1}

    "cflgalleefhmbaiiijmhhk"

    Returns: -1

  53. 19

    {15,17,14,10,2,6,18,6,17,0,1,7,15,1,10,14,4,9,6,16,8,15,12,5,10,10,16,16,10,8,11,18,4,4,1,10,3,8,5,18,10,3,8,12,16,16,5,3,4,6,4,12,16,7,11,15,14,0,8,2,12,5,4,7,1,13,8,10,5,4,8,3,11,3,4,17,5,3,12,17,2,2,3,2,6}

    {10,10,15,9,15,3,15,4,15,15,6,8,8,5,8,13,5,8,5,18,12,16,4,7,12,7,2,14,6,4,2,14,7,0,17,13,15,1,9,11,14,14,11,17,8,6,11,9,11,17,10,1,5,17,9,5,7,14,18,9,18,17,13,16,18,17,3,11,13,3,17,16,16,13,2,4,0,1,2,11,5,14,5,3,12}

    "jikonlrmaimoccophpjqoiornolebdfaefqcniprkedciblnhobabomdhlblmllgjprcncgmbomlocjfgkqng"

    Returns: 3

  54. 14

    {11,1,9,1,9,1,10,0,5,11,8,12,11,10,5,12,4,0,13,2,7,4,10,6,13,3,7,7,9,5,6,5,3,0,8,9,9,11,4,0,13,3,2,10,4,10,10,11}

    {1,5,12,13,10,12,13,8,12,8,9,6,3,6,13,0,12,9,12,5,13,5,11,0,11,13,0,2,3,6,4,10,12,2,1,4,2,7,10,4,8,6,10,0,1,12,1,4}

    "lqjtapexxljligpptlcwrudipippjofmrdbiooqnjaeljqge"

    Returns: 2

  55. 18

    {6,17,5,17,13,9,2,1,0,15,8,14,2,16,13,7,12,3,8,10,4,7,7,14,1,15,17,15,10,13,11,3,10,6,6,9,17,10,16,5,11,3,9,12,7,4,12,8,1,3,0,11,9,0,8,14,9,9,6,0,1,9,10,14,5,16,9,6,3,5,6,5,17,13,3,12,4,16}

    {10,5,4,16,0,2,11,8,11,3,15,16,15,7,3,15,3,6,2,11,6,13,5,15,6,13,4,10,0,14,7,2,5,15,2,16,6,17,15,3,6,10,0,4,9,8,14,10,2,14,5,8,4,12,16,5,10,12,9,4,3,14,13,4,2,2,17,5,9,11,12,1,14,8,11,10,13,3}

    "aedbcabebbdceeedeecaabadbddebbdaadbebbecbddccededbdedebacacacaacdbbeaabacacced"

    Returns: 3

  56. 12

    {6,8,3,8,10,9,6,9,3,6,11,8,10,6,4,4,5,11,6,10,6,3,0,11,5,1,10,1,9,5,11,1,5,7,2,1,0}

    {7,6,4,10,11,3,11,4,0,3,0,2,5,4,7,2,7,8,10,0,9,10,7,2,8,4,9,6,8,9,1,2,6,11,6,8,2}

    "bcbbbabccaacbacacabcacabbabacaccaaaba"

    Returns: 3

  57. 18

    {15}

    {17}

    "e"

    Returns: -1

  58. 7

    {3,5}

    {2,0}

    "id"

    Returns: -1

  59. 20

    {0,18,5,1,2,11,13,1,15,11,12,15,11,13,11,7,17,1,16,2,0,8,10,10,13,3,16,16,4,3,13,18,17,6,4,9,17,10,11,4,7,17,3,9,0,15,4,3,2,16,8,4,13,18,7,8}

    {9,2,1,11,7,4,12,16,7,18,7,14,2,4,13,4,19,9,15,8,2,6,9,6,8,4,0,11,19,17,15,4,6,1,12,17,12,1,12,6,11,7,5,18,11,10,17,15,10,14,19,1,19,0,8,3}

    "kcphaoqiapblddkkleokejqpjkqkcknmlrgdkgikhprlgfcjnemamihf"

    Returns: 7

  60. 5

    {3,4,4,0}

    {4,1,2,3}

    "dfvo"

    Returns: -1

  61. 12

    {11,6,2,2,10,11,2,4,6,0}

    {8,0,5,1,4,10,11,3,8,2}

    "avohnhpcfm"

    Returns: -1

  62. 10

    {9,6,2,9,5,0,1,9,8,7,9,9,8,5,5,3,3,6,4,3,4,9}

    {2,1,1,7,2,3,8,5,6,2,4,6,2,4,0,9,5,5,1,6,6,1}

    "cflgalleefhmbaiiijmhhk"

    Returns: -1

  63. 19

    {15,17,14,10,2,6,18,6,17,0,1,7,15,1,10,14,4,9,6,16,8,15,12,5,10,10,16,16,10,8,11,18,4,4,1,10,3,8,5,18,10,3,8,12,16,16,5,3,4,6,4,12,16,7,11,15,14,0,8,2,12,5,4,7,1,13,8,10,5,4,8,3,11,3,4,17,5,3,12,17,2,2,3,2,6}

    {10,10,15,9,15,3,15,4,15,15,6,8,8,5,8,13,5,8,5,18,12,16,4,7,12,7,2,14,6,4,2,14,7,0,17,13,15,1,9,11,14,14,11,17,8,6,11,9,11,17,10,1,5,17,9,5,7,14,18,9,18,17,13,16,18,17,3,11,13,3,17,16,16,13,2,4,0,1,2,11,5,14,5,3,12}

    "jikonlrmaimoccophpjqoiornolebdfaefqcniprkedciblnhobabomdhlblmllgjprcncgmbomlocjfgkqng"

    Returns: 3

  64. 14

    {11,1,9,1,9,1,10,0,5,11,8,12,11,10,5,12,4,0,13,2,7,4,10,6,13,3,7,7,9,5,6,5,3,0,8,9,9,11,4,0,13,3,2,10,4,10,10,11}

    {1,5,12,13,10,12,13,8,12,8,9,6,3,6,13,0,12,9,12,5,13,5,11,0,11,13,0,2,3,6,4,10,12,2,1,4,2,7,10,4,8,6,10,0,1,12,1,4}

    "lqjtapexxljligpptlcwrudipippjofmrdbiooqnjaeljqge"

    Returns: 2

  65. 18

    {6,17,5,17,13,9,2,1,0,15,8,14,2,16,13,7,12,3,8,10,4,7,7,14,1,15,17,15,10,13,11,3,10,6,6,9,17,10,16,5,11,3,9,12,7,4,12,8,1,3,0,11,9,0,8,14,9,9,6,0,1,9,10,14,5,16,9,6,3,5,6,5,17,13,3,12,4,16}

    {10,5,4,16,0,2,11,8,11,3,15,16,15,7,3,15,3,6,2,11,6,13,5,15,6,13,4,10,0,14,7,2,5,15,2,16,6,17,15,3,6,10,0,4,9,8,14,10,2,14,5,8,4,12,16,5,10,12,9,4,3,14,13,4,2,2,17,5,9,11,12,1,14,8,11,10,13,3}

    "aedbcabebbdceeedeecaabadbddebbdaadbebbecbddccededbdedebacacacaacdbbeaabacacced"

    Returns: 3

  66. 12

    {6,8,3,8,10,9,6,9,3,6,11,8,10,6,4,4,5,11,6,10,6,3,0,11,5,1,10,1,9,5,11,1,5,7,2,1,0}

    {7,6,4,10,11,3,11,4,0,3,0,2,5,4,7,2,7,8,10,0,9,10,7,2,8,4,9,6,8,9,1,2,6,11,6,8,2}

    "bcbbbabccaacbacacabcacabbabacaccaaaba"

    Returns: 3

  67. 18

    {15}

    {17}

    "e"

    Returns: -1

  68. 7

    {3,5}

    {2,0}

    "id"

    Returns: -1

  69. 20

    {0,18,5,1,2,11,13,1,15,11,12,15,11,13,11,7,17,1,16,2,0,8,10,10,13,3,16,16,4,3,13,18,17,6,4,9,17,10,11,4,7,17,3,9,0,15,4,3,2,16,8,4,13,18,7,8}

    {9,2,1,11,7,4,12,16,7,18,7,14,2,4,13,4,19,9,15,8,2,6,9,6,8,4,0,11,19,17,15,4,6,1,12,17,12,1,12,6,11,7,5,18,11,10,17,15,10,14,19,1,19,0,8,3}

    "kcphaoqiapblddkkleokejqpjkqkcknmlrgdkgikhprlgfcjnemamihf"

    Returns: 7

  70. 5

    {3,4,4,0}

    {4,1,2,3}

    "dfvo"

    Returns: -1

  71. 12

    {11,6,2,2,10,11,2,4,6,0}

    {8,0,5,1,4,10,11,3,8,2}

    "avohnhpcfm"

    Returns: -1

  72. 10

    {9,6,2,9,5,0,1,9,8,7,9,9,8,5,5,3,3,6,4,3,4,9}

    {2,1,1,7,2,3,8,5,6,2,4,6,2,4,0,9,5,5,1,6,6,1}

    "cflgalleefhmbaiiijmhhk"

    Returns: -1

  73. 19

    {15,17,14,10,2,6,18,6,17,0,1,7,15,1,10,14,4,9,6,16,8,15,12,5,10,10,16,16,10,8,11,18,4,4,1,10,3,8,5,18,10,3,8,12,16,16,5,3,4,6,4,12,16,7,11,15,14,0,8,2,12,5,4,7,1,13,8,10,5,4,8,3,11,3,4,17,5,3,12,17,2,2,3,2,6}

    {10,10,15,9,15,3,15,4,15,15,6,8,8,5,8,13,5,8,5,18,12,16,4,7,12,7,2,14,6,4,2,14,7,0,17,13,15,1,9,11,14,14,11,17,8,6,11,9,11,17,10,1,5,17,9,5,7,14,18,9,18,17,13,16,18,17,3,11,13,3,17,16,16,13,2,4,0,1,2,11,5,14,5,3,12}

    "jikonlrmaimoccophpjqoiornolebdfaefqcniprkedciblnhobabomdhlblmllgjprcncgmbomlocjfgkqng"

    Returns: 3

  74. 14

    {11,1,9,1,9,1,10,0,5,11,8,12,11,10,5,12,4,0,13,2,7,4,10,6,13,3,7,7,9,5,6,5,3,0,8,9,9,11,4,0,13,3,2,10,4,10,10,11}

    {1,5,12,13,10,12,13,8,12,8,9,6,3,6,13,0,12,9,12,5,13,5,11,0,11,13,0,2,3,6,4,10,12,2,1,4,2,7,10,4,8,6,10,0,1,12,1,4}

    "lqjtapexxljligpptlcwrudipippjofmrdbiooqnjaeljqge"

    Returns: 2

  75. 18

    {6,17,5,17,13,9,2,1,0,15,8,14,2,16,13,7,12,3,8,10,4,7,7,14,1,15,17,15,10,13,11,3,10,6,6,9,17,10,16,5,11,3,9,12,7,4,12,8,1,3,0,11,9,0,8,14,9,9,6,0,1,9,10,14,5,16,9,6,3,5,6,5,17,13,3,12,4,16}

    {10,5,4,16,0,2,11,8,11,3,15,16,15,7,3,15,3,6,2,11,6,13,5,15,6,13,4,10,0,14,7,2,5,15,2,16,6,17,15,3,6,10,0,4,9,8,14,10,2,14,5,8,4,12,16,5,10,12,9,4,3,14,13,4,2,2,17,5,9,11,12,1,14,8,11,10,13,3}

    "aedbcabebbdceeedeecaabadbddebbdaadbebbecbddccededbdedebacacacaacdbbeaabacacced"

    Returns: 3

  76. 12

    {6,8,3,8,10,9,6,9,3,6,11,8,10,6,4,4,5,11,6,10,6,3,0,11,5,1,10,1,9,5,11,1,5,7,2,1,0}

    {7,6,4,10,11,3,11,4,0,3,0,2,5,4,7,2,7,8,10,0,9,10,7,2,8,4,9,6,8,9,1,2,6,11,6,8,2}

    "bcbbbabccaacbacacabcacabbabacaccaaaba"

    Returns: 3

  77. 18

    {15}

    {17}

    "e"

    Returns: -1

  78. 7

    {3,5}

    {2,0}

    "id"

    Returns: -1

  79. 7

    {0, 0, 3, 4, 5, 6 }

    {2, 3, 4, 5, 6, 1 }

    "abaaaa"

    Returns: 9

  80. 8

    {1, 2, 3, 4, 5, 0, 7 }

    {2, 3, 4, 5, 6, 7, 6 }

    "aaaabab"

    Returns: -1

  81. 2

    {0 }

    {1 }

    "x"

    Returns: 1

  82. 5

    {0, 0, 4, 1, 3 }

    {2, 4, 1, 3, 2 }

    "accab"

    Returns: 2

  83. 20

    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 17, 17, 18 }

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 11, 12, 13, 14, 15, 16, 17, 18, 19, 12, 13, 14, 15, 16, 17, 18, 19, 13, 14, 15, 16, 17, 18, 19, 14, 15, 16, 17, 18, 19, 15, 16, 17, 18, 19, 16, 17, 18, 19, 17, 18, 19, 18, 19, 19 }

    "phqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenzkycxfxtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhmsncbxcoksfz"

    Returns: 1

  84. 6

    {0, 2, 3, 1, 4 }

    {2, 3, 4, 5, 1 }

    "aabab"

    Returns: 6


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: