FastPrepValidate ISBN Log Record Syntax

Validate ISBN Log Record Syntax

Amazon logoAmazon● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

A log contains identifiers that should follow the reported ISBN-like syntax. Return the valid records.

For this exercise, assume each input record is one complete candidate identifier. Accept exactly either ten characters, with digits in the first nine positions and a digit or x/X in the final position, or the hyphenated shape d-ddddd-ddd-c, where each d is an ASCII digit and c is a digit or x/X.

For this exercise, return original valid records in input order, retaining duplicates. Do not trim whitespace, extract substrings, normalize characters, or compute an ISBN checksum. This is a syntax validation task; the source examples establish the two accepted forms.

Function

validIsbnRecords(records: String[]) → String[]

Examples

Example 1

records = ["1-23456-789-0","1-23456-789-x","1234567890","1-23456-7890","1-2345w6-789-x","12345-6789x"]return = ["1-23456-789-0","1-23456-789-x","1234567890"]

The first three identifiers use source-reported valid forms. The last three violate width, character or hyphen-position rules.

Example 2

records = ["123456789X","123456789x","123456789X"]return = ["123456789X","123456789x","123456789X"]

Final markers are case-insensitive, and duplicate records keep their original positions.

Example 3

records = ["isbn=1234567890"," 1234567890",""]return = []

For this exercise, each record is the entire identifier; embedded or whitespace-padded identifiers are invalid.

Constraints

  • For this exercise, assume 0 <= records.length <= 300.
  • Each record contains at most 100 ASCII characters.

More Amazon problems

See Amazon hiring insights
public String[] validIsbnRecords(String[] records) {
    // Write your code here
}
records["1-23456-789-0","1-23456-789-x","1234567890","1-23456-7890","1-2345w6-789-x","12345-6789x"]
expected["1-23456-789-0", "1-23456-789-x", "1234567890"]
Checking account…