Problem · Array

Neighboring Record IDs

Learn this problem
EasyZipRecruiterFULLTIMEPHONE SCREEN

Problem statement

You are given records in their current order. Each record is a string whose id appears before the first | character. For each queried id, return the previous and next record ids in the original order.

The answer for one query should be formatted as previousId,nextId. Use None for a missing neighbor or for both values when the queried id is not present.

Function

queryNeighborIds(records: String[], queries: String[]) → String[]

Examples

Example 1

records = ["a|red","b|blue","c|green","d|yellow"]queries = ["a","c","x"]return = ["None,b","b,d","None,None"]

a has no previous id, c is between b and d, and x is not present.

Example 2

records = ["id7|one"]queries = ["id7"]return = ["None,None"]

A single record has no neighbors.

Constraints

Record ids are unique.

More ZipRecruiter problems

drafts saved locally
public String[] queryNeighborIds(String[] records, String[] queries) {
    // write your code here
}
records["a|red","b|blue","c|green","d|yellow"]
queries["a","c","x"]
expected["None", "b", "b", "d", "None", "None"]
checking account