FastPrepBuild Cyclic String Endpoint Pairs

Build Cyclic String Endpoint Pairs

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

Given a nonempty array of nonempty strings treated cyclically, output at index i is the first character of values[i] followed by the last character of values[(i + 1) mod n].

Function

cyclicEndpointPairs(values: String[]) → String[]

Examples

Example 1

values = ["abc","def","ghi"]return = ["af","di","gc"]

Each current first character pairs with the next cyclic last character.

Example 2

values = ["cat","dog","bee"]return = ["cg","de","bt"]

The pairs use c with g, d with e, and b with the wrapped t.

Constraints

  • 1 <= values.length <= 100000
  • Every string is nonempty.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String[] cyclicEndpointPairs(String[] values) {
    // Write your code here.
}
values["abc","def","ghi"]
expected["af", "di", "gc"]
Checking account…