Connection Status:
Competition Arena > Arrows
SRM 330 · 2006-12-13 · by soul-net · Search, String Manipulation
Class Name: Arrows
Return Type: int
Method Name: longestArrow
Arg Types: (string)
Problem Statement

Problem Statement

In this problem, a left single arrow is defined as a "less than" character ('<') immediately followed by zero or more consecutive hyphen characters ('-'). A left double arrow is a "less than" character ('<') immediately followed by zero or more consecutive equals characters ('='). A right single arrow is zero or more hyphen characters ('-') immediately followed by a "greater than" character ('>'). A right double arrow is zero or more equals characters ('=') immediately followed by a "greater than" character ('>'). For example, the following are arrows (quotes for clarity only): "==>", "<-", "<", "<===", "--->", ">". The length of an arrow is the number of characters it contains.

You will be given a String s. Return the length of the longest arrow in s, or -1 if it does not contain any arrows.

Notes

  • Arrows may overlap. See examples for further clarifications.

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character in s will be one of '<', '>', '-' or '='.
Examples
0)
"<--->--==>"
Returns: 4

The arrows contained in s in this case are, by order of appearance: "<", "<-", "<--", "<---", "--->", "-->", "->", ">", "==>", "=>" and ">". Note that many of these arrows, including some pairs with one left arrow and one right arrow, are overlapping.

1)
"<<<<<<<<<<"
Returns: 1

All arrows are of length 1. Note that "<" is both a left single arrow and a left double arrow according to the definition.

2)
"----==-"
Returns: -1

No arrows contained.

3)
"<----=====>"
Returns: 6
4)
">----=====<"
Returns: 1
5)
"=========>"
Returns: 10

s is an arrow itself. There are several other arrows, but everyone is of course smaller.

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

Coding Area

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

Submitting as anonymous