TopcoderArchive
Archive10 Jun 2019
TCC19 South America Prelims

OrderlyString

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
OrderlyString
Method:
longestLength
Parameters:
String
Returns:
int
Method signature:
int longestLength(String s)
(be sure your method is public)

Constraints

  • s will contain between 1 and 200 characters, inclusive.
  • Each character of s will be in the range 'A'-'Z'.

Examples

  1. "ABCDEFG"
    Returns: 7
    We don't actually need to remove any characters.
  2. "GFEDCBA"
    Returns: 1
    The characters initially are all in the wrong order, best we can do is leave only one.
  3. "ACBB"
    Returns: 3
    ABB is the longest.
Back to all problems