Back From Summer '17 P2: Crayola Lightsaber

View as PDF

Submit solution

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

Problem types
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 Outputs

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

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


  • 47
    bariumlanthanum  commented on June 1, 2020, 5:38 p.m. edited

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

    Edit: wow 18 upvotes never expected that many thanks for the likes :D