Maximum Crayon Removal Score
Updated
Problem statement
You are given a string colors representing crayons arranged in a row. Equal letters represent equal colors.
In one operation, choose a contiguous group of x crayons of the same color, remove it, and earn x * x points. The remaining crayons close the gap and may form new contiguous groups.
Remove every crayon and return the maximum total score.
Function
maximumCrayonScore(colors: String) → intExamples
Example 1
colors = "abcccbaba"return = 23Remove ccc for 9, then one b for 1, then the merged bbb for 9, and finally aa for 4.
Example 2
colors = "aba"return = 5Remove b for 1, then remove the merged aa for 4.
Example 3
colors = "aaa"return = 9Remove all three crayons in one operation.
Example 4
colors = "ab"return = 2The two different crayons must be removed separately for one point each.
Constraints
1 <= colors.length <= 60.colorscontains lowercase English letters.
More Wells Fargo Online Assessment questions
- Server Upgrade PlanningOA · Seen Nov 2026
- Student and Course EnrollmentOA · Seen Nov 2026
- Bond Interest Summary Above 3%OA · Seen Oct 2026
- Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
- Event Statistics AggregatorOA · Seen Sep 2026
- Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
- Longest Subsequence That Is a SubstringOA · Seen Jul 2026
- Overloaded Game Account InventoriesOA · Seen Jul 2026
- Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
- Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026
Similar questions at other companies
- Shuffle a String by Swapping Tree ChildrenNutanix · OANutanix interview questions
- Scramble StringExpedia · ONSITE INTERVIEWExpedia interview questions
- Edit DistanceAstrotalk · PHONE SCREEN
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Minimum Dictionary SegmentsGoogle · PHONE SCREENGoogle interview questions
- Wildcard Pattern MatchingMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Lexicographically Largest IdentifierAmazon · OA
- Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
- String Formation (Also for AI/ML Software Engineer Intern :)Snowflake · OASnowflake interview questions