Back From Summer '17 P2: Crayola Lightsaber

View as PDF

Submit solution

Points: 6
Time limit: 1.0s
Memory limit: 128M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
Marker Sword

School's back! You're up to no good again already… While your art teacher, Roger, was looking away, you grab his basket of Crayola™ markers and started connecting them together.

This creates a colorful sword that you can use to hit people that you find annoying with. You want to be able to reach quite far with your sword though, so you keep on connecting.

Although you want your crayon lightsaber to be as long as possible, you also care deeply about it being aesthetically pleasing. For that reason, you choose to never connect two crayons of the same color directly together.

Given the colors of the markers in the basket, what is the longest Crayola™ marker sword you can construct?

Input Specification

The first line will contain an integer (1 \le N \le 10\,000). This will then be followed by a line of N strings that represent the colors of the markers. The colors can be: red, orange, yellow, green, blue, black.

Output Specification

The only output is an integer representing the maximum length possible for the marker sword.

Sample Input 1

red blue green black

Sample Output 1


Sample Input 2

yellow orange yellow yellow yellow

Sample Output 2


Explanation for Sample Input

For the first example you can use every marker to make a sword such as the one in the image above.

The longest sword you can make for the second example is using the markers yellow-orange-yellow, resulting in a length of 3.


  • 4
    balathegreat999  commented on June 1, 2020, 1:38 p.m.

    crayola lightsabers get too flimsy and unstable after the length exceeds 6

  • 1
    nikos  commented on Oct. 7, 2017, 11:20 a.m. edit 3

    Can someone take a look at my code? It works when I test my code in PyCharm, but the first test case always gives me an IR (Name Error). My output(clipped) is 3. Plz, somebody help me!