Connection Status:
Competition Arena > OrderlyString
TCC19 South America Prelims · 2019-06-10 · by erinn · Dynamic Programming
Class Name: OrderlyString
Return Type: int
Method Name: longestLength
Arg Types: (string)
Problem Statement

Problem Statement

You are given String s consisting of characters 'A'-'Z'.

You wish to delete some characters from the string, such that the characters that remain are all in non-decreasing order.

Return the length of the longest possible string that remains.

Constraints

  • s will contain between 1 and 200 characters, inclusive.
  • Each character of s will be in the range 'A'-'Z'.
Examples
0)
"ABCDEFG"
Returns: 7

We don't actually need to remove any characters.

1)
"GFEDCBA"
Returns: 1

The characters initially are all in the wrong order, best we can do is leave only one.

2)
"ACBB"
Returns: 3

ABB is the longest.

3)
"AAAAAAA"
Returns: 7
4)
"BBACDEF"
Returns: 6

Submissions are judged against all 30 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class OrderlyString with a public method int longestLength(string s) · 30 test cases · 2 s / 256 MB per case

Submitting as anonymous