Programming Challenge from Kattis: Distinctive CharactersHackers Ranking String SimilarityRemoving accents from certain charactersFinding longest substring containing k distinct charactersFunny String Java SolutionProgramming Challenge from Kattis: ApparatusReturn characters in a string in alphabetical orderLeetcode: String to Integer (atoi)Sliding window to solve “longest substring, no repeating chars”Morgan and a String HackerRank challengeProgramming Challenge from Kattis: Watchdog

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

Unable to deploy metadata from Partner Developer scratch org because of extra fields

Why is consensus so controversial in Britain?

What does the "remote control" for a QF-4 look like?

Watching something be written to a file live with tail

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Can a Cauchy sequence converge for one metric while not converging for another?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

What would happen to a modern skyscraper if it rains micro blackholes?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

Has there ever been an airliner design involving reducing generator load by installing solar panels?

How does one intimidate enemies without having the capacity for violence?

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

Important Resources for Dark Age Civilizations?

Codimension of non-flat locus

Add text to same line using sed

Revoked SSL certificate

Malformed Address '10.10.21.08/24', must be X.X.X.X/NN or

What's the output of a record needle playing an out-of-speed record

Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?

Perform and show arithmetic with LuaLaTeX

Rock identification in KY

RSA: Danger of using p to create q

Is it inappropriate for a student to attend their mentor's dissertation defense?



Programming Challenge from Kattis: Distinctive Characters


Hackers Ranking String SimilarityRemoving accents from certain charactersFinding longest substring containing k distinct charactersFunny String Java SolutionProgramming Challenge from Kattis: ApparatusReturn characters in a string in alphabetical orderLeetcode: String to Integer (atoi)Sliding window to solve “longest substring, no repeating chars”Morgan and a String HackerRank challengeProgramming Challenge from Kattis: Watchdog






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0












$begingroup$


I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. Similarity between two strings is measured by increasing the similarity by 1 if both strings have the same character in the same position. E.g: "01001" "11110" has similarity 1, because they both have 1 in their 2nd position, and for every other position they have different characters. An input starts with one line giving two numbers N and P, being first the number of strings in the list, and then the length of each string. The rest of the input is then N lines of single strings. The output should be a string that has the least possible similarity to any string in the input.



I'd like suggestions on how to reduce the number of calls I'm doing in my solution to this problem. Likely by some algorithmic magic.



Example input:



3 5
01001
11100
10111


Example output:



00010


My code:



import sys
import itertools


def similarity(sx, sy):
'''Naively calculates similarity between two
strings.'''
result = 0
for i in range(n_feat):
if sx[i] == sy[i]:
result += 1
return result


line_1 = sys.stdin.readline()
line_1 = line_1.split()
N = int(line_1[0])
n_feat = int(line_1[1])

characters = set()
for i in range(N):
characters.add(str(sys.stdin.readline()))


# Generate all possible ways to write n_feat long string with alphabet 0,1
all_pos_chars = ["".join(seq) for seq in itertools.product("01", repeat=n_feat)]
# Subset actually possible (removed ones have similarity == n_feat)
pos_chars = [pos_char for pos_char in all_pos_chars if pos_char not in characters]

# Impossibly high starting-point.
curr_min = n_feat+1
curr_small = ""
for pos_char in pos_chars:
curr = max(similarity(pos_char, character) for character in characters)
if curr == 0:
curr_small = pos_char
break;
if curr <= curr_min:
curr_min = curr
curr_small = pos_char

print(curr_small)


This solution works fine for smaller inputs. For example, I ran python -m cProfile -s cumtime dischar.py < 1.in where 1.in is the example input given above and received this:



 300 function calls in 0.001 seconds

Ordered by: cumulative time

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.001 0.001 built-in method builtins.exec
1 0.000 0.000 0.001 0.001 dischar2.py:1(<module>)
1 0.000 0.000 0.000 0.000 built-in method builtins.print
31 0.000 0.000 0.000 0.000 built-in method builtins.max
124 0.000 0.000 0.000 0.000 dischar2.py:34(<genexpr>)
93 0.000 0.000 0.000 0.000 dischar2.py:5(similarity)
4 0.000 0.000 0.000 0.000 method 'readline' of '_io.TextIOWrapper' objects
1 0.000 0.000 0.000 0.000 dischar2.py:26(<listcomp>)
2 0.000 0.000 0.000 0.000 cp1252.py:22(decode)
32 0.000 0.000 0.000 0.000 method 'join' of 'str' objects
1 0.000 0.000 0.000 0.000 dischar2.py:28(<listcomp>)
2 0.000 0.000 0.000 0.000 built-in method _codecs.charmap_decode
2 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
3 0.000 0.000 0.000 0.000 method 'add' of 'set' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects


But I was worried about the number of calls at line:34, which is this bit of code: curr = max(similarity(pos_char, character) for character in characters), and then onwards to line:5 which is the similartiy-function. I made a 6.in, where the first line is 10000 20, and the next 10000 lines are 20 zeros:



python -m cProfile -s cumtime dischar2.py < 6.in
11111111111111111111
7360118 function calls in 9.280 seconds

Ordered by: cumulative time

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 9.280 9.280 built-in method builtins.exec
1 0.756 0.756 9.280 9.280 dischar2.py:1(<module>)
1048575 0.663 0.000 7.700 0.000 built-in method builtins.max
3145725 0.777 0.000 7.037 0.000 dischar2.py:34(<genexpr>)
2097150 6.260 0.000 6.260 0.000 dischar2.py:5(similarity)
1 0.325 0.325 0.656 0.656 dischar2.py:26(<listcomp>)
1048576 0.332 0.000 0.332 0.000 method 'join' of 'str' objects
1 0.161 0.161 0.161 0.161 dischar2.py:28(<listcomp>)
10001 0.004 0.000 0.005 0.000 method 'readline' of '_io.TextIOWrapper' objects
10000 0.001 0.000 0.001 0.000 method 'add' of 'set' objects
28 0.000 0.000 0.001 0.000 cp1252.py:22(decode)
28 0.001 0.000 0.001 0.000 built-in method _codecs.charmap_decode
1 0.000 0.000 0.000 0.000 built-in method builtins.print
28 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects


As you can see, this adds up quickly! I think my solution is sound, it provides the correct output for every case I can test for. But there has to be some trick that I'm not seeing, because Kattis expects the solution to run within 2 CPU-seconds. Any suggestions?









share







New contributor




RoyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$


















    0












    $begingroup$


    I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. Similarity between two strings is measured by increasing the similarity by 1 if both strings have the same character in the same position. E.g: "01001" "11110" has similarity 1, because they both have 1 in their 2nd position, and for every other position they have different characters. An input starts with one line giving two numbers N and P, being first the number of strings in the list, and then the length of each string. The rest of the input is then N lines of single strings. The output should be a string that has the least possible similarity to any string in the input.



    I'd like suggestions on how to reduce the number of calls I'm doing in my solution to this problem. Likely by some algorithmic magic.



    Example input:



    3 5
    01001
    11100
    10111


    Example output:



    00010


    My code:



    import sys
    import itertools


    def similarity(sx, sy):
    '''Naively calculates similarity between two
    strings.'''
    result = 0
    for i in range(n_feat):
    if sx[i] == sy[i]:
    result += 1
    return result


    line_1 = sys.stdin.readline()
    line_1 = line_1.split()
    N = int(line_1[0])
    n_feat = int(line_1[1])

    characters = set()
    for i in range(N):
    characters.add(str(sys.stdin.readline()))


    # Generate all possible ways to write n_feat long string with alphabet 0,1
    all_pos_chars = ["".join(seq) for seq in itertools.product("01", repeat=n_feat)]
    # Subset actually possible (removed ones have similarity == n_feat)
    pos_chars = [pos_char for pos_char in all_pos_chars if pos_char not in characters]

    # Impossibly high starting-point.
    curr_min = n_feat+1
    curr_small = ""
    for pos_char in pos_chars:
    curr = max(similarity(pos_char, character) for character in characters)
    if curr == 0:
    curr_small = pos_char
    break;
    if curr <= curr_min:
    curr_min = curr
    curr_small = pos_char

    print(curr_small)


    This solution works fine for smaller inputs. For example, I ran python -m cProfile -s cumtime dischar.py < 1.in where 1.in is the example input given above and received this:



     300 function calls in 0.001 seconds

    Ordered by: cumulative time

    ncalls tottime percall cumtime percall filename:lineno(function)
    1 0.000 0.000 0.001 0.001 built-in method builtins.exec
    1 0.000 0.000 0.001 0.001 dischar2.py:1(<module>)
    1 0.000 0.000 0.000 0.000 built-in method builtins.print
    31 0.000 0.000 0.000 0.000 built-in method builtins.max
    124 0.000 0.000 0.000 0.000 dischar2.py:34(<genexpr>)
    93 0.000 0.000 0.000 0.000 dischar2.py:5(similarity)
    4 0.000 0.000 0.000 0.000 method 'readline' of '_io.TextIOWrapper' objects
    1 0.000 0.000 0.000 0.000 dischar2.py:26(<listcomp>)
    2 0.000 0.000 0.000 0.000 cp1252.py:22(decode)
    32 0.000 0.000 0.000 0.000 method 'join' of 'str' objects
    1 0.000 0.000 0.000 0.000 dischar2.py:28(<listcomp>)
    2 0.000 0.000 0.000 0.000 built-in method _codecs.charmap_decode
    2 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
    1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
    3 0.000 0.000 0.000 0.000 method 'add' of 'set' objects
    1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects


    But I was worried about the number of calls at line:34, which is this bit of code: curr = max(similarity(pos_char, character) for character in characters), and then onwards to line:5 which is the similartiy-function. I made a 6.in, where the first line is 10000 20, and the next 10000 lines are 20 zeros:



    python -m cProfile -s cumtime dischar2.py < 6.in
    11111111111111111111
    7360118 function calls in 9.280 seconds

    Ordered by: cumulative time

    ncalls tottime percall cumtime percall filename:lineno(function)
    1 0.000 0.000 9.280 9.280 built-in method builtins.exec
    1 0.756 0.756 9.280 9.280 dischar2.py:1(<module>)
    1048575 0.663 0.000 7.700 0.000 built-in method builtins.max
    3145725 0.777 0.000 7.037 0.000 dischar2.py:34(<genexpr>)
    2097150 6.260 0.000 6.260 0.000 dischar2.py:5(similarity)
    1 0.325 0.325 0.656 0.656 dischar2.py:26(<listcomp>)
    1048576 0.332 0.000 0.332 0.000 method 'join' of 'str' objects
    1 0.161 0.161 0.161 0.161 dischar2.py:28(<listcomp>)
    10001 0.004 0.000 0.005 0.000 method 'readline' of '_io.TextIOWrapper' objects
    10000 0.001 0.000 0.001 0.000 method 'add' of 'set' objects
    28 0.000 0.000 0.001 0.000 cp1252.py:22(decode)
    28 0.001 0.000 0.001 0.000 built-in method _codecs.charmap_decode
    1 0.000 0.000 0.000 0.000 built-in method builtins.print
    28 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
    1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
    1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects


    As you can see, this adds up quickly! I think my solution is sound, it provides the correct output for every case I can test for. But there has to be some trick that I'm not seeing, because Kattis expects the solution to run within 2 CPU-seconds. Any suggestions?









    share







    New contributor




    RoyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      0












      0








      0





      $begingroup$


      I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. Similarity between two strings is measured by increasing the similarity by 1 if both strings have the same character in the same position. E.g: "01001" "11110" has similarity 1, because they both have 1 in their 2nd position, and for every other position they have different characters. An input starts with one line giving two numbers N and P, being first the number of strings in the list, and then the length of each string. The rest of the input is then N lines of single strings. The output should be a string that has the least possible similarity to any string in the input.



      I'd like suggestions on how to reduce the number of calls I'm doing in my solution to this problem. Likely by some algorithmic magic.



      Example input:



      3 5
      01001
      11100
      10111


      Example output:



      00010


      My code:



      import sys
      import itertools


      def similarity(sx, sy):
      '''Naively calculates similarity between two
      strings.'''
      result = 0
      for i in range(n_feat):
      if sx[i] == sy[i]:
      result += 1
      return result


      line_1 = sys.stdin.readline()
      line_1 = line_1.split()
      N = int(line_1[0])
      n_feat = int(line_1[1])

      characters = set()
      for i in range(N):
      characters.add(str(sys.stdin.readline()))


      # Generate all possible ways to write n_feat long string with alphabet 0,1
      all_pos_chars = ["".join(seq) for seq in itertools.product("01", repeat=n_feat)]
      # Subset actually possible (removed ones have similarity == n_feat)
      pos_chars = [pos_char for pos_char in all_pos_chars if pos_char not in characters]

      # Impossibly high starting-point.
      curr_min = n_feat+1
      curr_small = ""
      for pos_char in pos_chars:
      curr = max(similarity(pos_char, character) for character in characters)
      if curr == 0:
      curr_small = pos_char
      break;
      if curr <= curr_min:
      curr_min = curr
      curr_small = pos_char

      print(curr_small)


      This solution works fine for smaller inputs. For example, I ran python -m cProfile -s cumtime dischar.py < 1.in where 1.in is the example input given above and received this:



       300 function calls in 0.001 seconds

      Ordered by: cumulative time

      ncalls tottime percall cumtime percall filename:lineno(function)
      1 0.000 0.000 0.001 0.001 built-in method builtins.exec
      1 0.000 0.000 0.001 0.001 dischar2.py:1(<module>)
      1 0.000 0.000 0.000 0.000 built-in method builtins.print
      31 0.000 0.000 0.000 0.000 built-in method builtins.max
      124 0.000 0.000 0.000 0.000 dischar2.py:34(<genexpr>)
      93 0.000 0.000 0.000 0.000 dischar2.py:5(similarity)
      4 0.000 0.000 0.000 0.000 method 'readline' of '_io.TextIOWrapper' objects
      1 0.000 0.000 0.000 0.000 dischar2.py:26(<listcomp>)
      2 0.000 0.000 0.000 0.000 cp1252.py:22(decode)
      32 0.000 0.000 0.000 0.000 method 'join' of 'str' objects
      1 0.000 0.000 0.000 0.000 dischar2.py:28(<listcomp>)
      2 0.000 0.000 0.000 0.000 built-in method _codecs.charmap_decode
      2 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
      1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
      3 0.000 0.000 0.000 0.000 method 'add' of 'set' objects
      1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects


      But I was worried about the number of calls at line:34, which is this bit of code: curr = max(similarity(pos_char, character) for character in characters), and then onwards to line:5 which is the similartiy-function. I made a 6.in, where the first line is 10000 20, and the next 10000 lines are 20 zeros:



      python -m cProfile -s cumtime dischar2.py < 6.in
      11111111111111111111
      7360118 function calls in 9.280 seconds

      Ordered by: cumulative time

      ncalls tottime percall cumtime percall filename:lineno(function)
      1 0.000 0.000 9.280 9.280 built-in method builtins.exec
      1 0.756 0.756 9.280 9.280 dischar2.py:1(<module>)
      1048575 0.663 0.000 7.700 0.000 built-in method builtins.max
      3145725 0.777 0.000 7.037 0.000 dischar2.py:34(<genexpr>)
      2097150 6.260 0.000 6.260 0.000 dischar2.py:5(similarity)
      1 0.325 0.325 0.656 0.656 dischar2.py:26(<listcomp>)
      1048576 0.332 0.000 0.332 0.000 method 'join' of 'str' objects
      1 0.161 0.161 0.161 0.161 dischar2.py:28(<listcomp>)
      10001 0.004 0.000 0.005 0.000 method 'readline' of '_io.TextIOWrapper' objects
      10000 0.001 0.000 0.001 0.000 method 'add' of 'set' objects
      28 0.000 0.000 0.001 0.000 cp1252.py:22(decode)
      28 0.001 0.000 0.001 0.000 built-in method _codecs.charmap_decode
      1 0.000 0.000 0.000 0.000 built-in method builtins.print
      28 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
      1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
      1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects


      As you can see, this adds up quickly! I think my solution is sound, it provides the correct output for every case I can test for. But there has to be some trick that I'm not seeing, because Kattis expects the solution to run within 2 CPU-seconds. Any suggestions?









      share







      New contributor




      RoyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. Similarity between two strings is measured by increasing the similarity by 1 if both strings have the same character in the same position. E.g: "01001" "11110" has similarity 1, because they both have 1 in their 2nd position, and for every other position they have different characters. An input starts with one line giving two numbers N and P, being first the number of strings in the list, and then the length of each string. The rest of the input is then N lines of single strings. The output should be a string that has the least possible similarity to any string in the input.



      I'd like suggestions on how to reduce the number of calls I'm doing in my solution to this problem. Likely by some algorithmic magic.



      Example input:



      3 5
      01001
      11100
      10111


      Example output:



      00010


      My code:



      import sys
      import itertools


      def similarity(sx, sy):
      '''Naively calculates similarity between two
      strings.'''
      result = 0
      for i in range(n_feat):
      if sx[i] == sy[i]:
      result += 1
      return result


      line_1 = sys.stdin.readline()
      line_1 = line_1.split()
      N = int(line_1[0])
      n_feat = int(line_1[1])

      characters = set()
      for i in range(N):
      characters.add(str(sys.stdin.readline()))


      # Generate all possible ways to write n_feat long string with alphabet 0,1
      all_pos_chars = ["".join(seq) for seq in itertools.product("01", repeat=n_feat)]
      # Subset actually possible (removed ones have similarity == n_feat)
      pos_chars = [pos_char for pos_char in all_pos_chars if pos_char not in characters]

      # Impossibly high starting-point.
      curr_min = n_feat+1
      curr_small = ""
      for pos_char in pos_chars:
      curr = max(similarity(pos_char, character) for character in characters)
      if curr == 0:
      curr_small = pos_char
      break;
      if curr <= curr_min:
      curr_min = curr
      curr_small = pos_char

      print(curr_small)


      This solution works fine for smaller inputs. For example, I ran python -m cProfile -s cumtime dischar.py < 1.in where 1.in is the example input given above and received this:



       300 function calls in 0.001 seconds

      Ordered by: cumulative time

      ncalls tottime percall cumtime percall filename:lineno(function)
      1 0.000 0.000 0.001 0.001 built-in method builtins.exec
      1 0.000 0.000 0.001 0.001 dischar2.py:1(<module>)
      1 0.000 0.000 0.000 0.000 built-in method builtins.print
      31 0.000 0.000 0.000 0.000 built-in method builtins.max
      124 0.000 0.000 0.000 0.000 dischar2.py:34(<genexpr>)
      93 0.000 0.000 0.000 0.000 dischar2.py:5(similarity)
      4 0.000 0.000 0.000 0.000 method 'readline' of '_io.TextIOWrapper' objects
      1 0.000 0.000 0.000 0.000 dischar2.py:26(<listcomp>)
      2 0.000 0.000 0.000 0.000 cp1252.py:22(decode)
      32 0.000 0.000 0.000 0.000 method 'join' of 'str' objects
      1 0.000 0.000 0.000 0.000 dischar2.py:28(<listcomp>)
      2 0.000 0.000 0.000 0.000 built-in method _codecs.charmap_decode
      2 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
      1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
      3 0.000 0.000 0.000 0.000 method 'add' of 'set' objects
      1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects


      But I was worried about the number of calls at line:34, which is this bit of code: curr = max(similarity(pos_char, character) for character in characters), and then onwards to line:5 which is the similartiy-function. I made a 6.in, where the first line is 10000 20, and the next 10000 lines are 20 zeros:



      python -m cProfile -s cumtime dischar2.py < 6.in
      11111111111111111111
      7360118 function calls in 9.280 seconds

      Ordered by: cumulative time

      ncalls tottime percall cumtime percall filename:lineno(function)
      1 0.000 0.000 9.280 9.280 built-in method builtins.exec
      1 0.756 0.756 9.280 9.280 dischar2.py:1(<module>)
      1048575 0.663 0.000 7.700 0.000 built-in method builtins.max
      3145725 0.777 0.000 7.037 0.000 dischar2.py:34(<genexpr>)
      2097150 6.260 0.000 6.260 0.000 dischar2.py:5(similarity)
      1 0.325 0.325 0.656 0.656 dischar2.py:26(<listcomp>)
      1048576 0.332 0.000 0.332 0.000 method 'join' of 'str' objects
      1 0.161 0.161 0.161 0.161 dischar2.py:28(<listcomp>)
      10001 0.004 0.000 0.005 0.000 method 'readline' of '_io.TextIOWrapper' objects
      10000 0.001 0.000 0.001 0.000 method 'add' of 'set' objects
      28 0.000 0.000 0.001 0.000 cp1252.py:22(decode)
      28 0.001 0.000 0.001 0.000 built-in method _codecs.charmap_decode
      1 0.000 0.000 0.000 0.000 built-in method builtins.print
      28 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
      1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
      1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects


      As you can see, this adds up quickly! I think my solution is sound, it provides the correct output for every case I can test for. But there has to be some trick that I'm not seeing, because Kattis expects the solution to run within 2 CPU-seconds. Any suggestions?







      python performance algorithm python-3.x programming-challenge





      share







      New contributor




      RoyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      RoyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      RoyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 7 mins ago









      RoyMRoyM

      284




      284




      New contributor




      RoyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      RoyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      RoyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          0






          active

          oldest

          votes












          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          RoyM is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216960%2fprogramming-challenge-from-kattis-distinctive-characters%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          RoyM is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          RoyM is a new contributor. Be nice, and check out our Code of Conduct.












          RoyM is a new contributor. Be nice, and check out our Code of Conduct.











          RoyM is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216960%2fprogramming-challenge-from-kattis-distinctive-characters%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

          Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

          Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar