FastPrepWildcard Multi-Delimiter Validation

Wildcard Multi-Delimiter Validation

Tennr logoTennr● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Given a string s containing (, ), <, >, |, and *, return whether it can form a valid, properly nested delimiter string.

The matching pairs are (), <>, and ||. Each * may independently be (, ), or the empty string. A single | can serve as the opening or closing bar according to its matching partner.

Function

isValidDelimiters(s: String) → boolean

Examples

Example 1

s = "<(*)>"return = true

Use the wildcard as the empty string; the remaining delimiters are nested.

Example 2

s = "<|*)|>"return = true

Use the wildcard as an opening parenthesis, producing <|()|>.

Example 3

s = "<(|>)"return = false

The delimiters cross instead of nesting.

Constraints

  • 0 <= s.length <= 80.
  • s contains only (, ), <, >, |, and *.

More Tennr problems

See Tennr hiring insights
public boolean isValidDelimiters(String s) {
    // Write your code here.
}
s"<(*)>"
expectedtrue
Checking account…