You are given a shuffled set of records. Record i has three fields: starts[i], ends[i], and payloads[i].
The records form exactly one chain. If record A has ends[A] == starts[B], then record A must appear immediately before record B in the chain.
Order the records by this chaining rule and concatenate their payloads in that order.
Complete the function concatenateOrderedPayloads in the editor below.
concatenateOrderedPayloads has the following parameters:
String[] starts: the start keysString[] ends: the end keysString[] payloads: the payload fragments
Returns
String: the concatenated payload string after ordering the chain.
Examples
01 · Example 1
starts = ["aaa", "bbb", "ccc"] ends = ["bbb", "ccc", "ddd"] payloads = ["2", "1", "3"] return = "213"
The only valid order is aaa -> bbb -> ccc -> ddd, so the payloads join as 2 + 1 + 3.
02 · Example 2
starts = ["p"] ends = ["q"] payloads = ["X"] return = "X"
A single record is already ordered.
Constraints
1 <= starts.length == ends.length == payloads.length <= 2 * 10^5- The records form exactly one valid chain.
More Microsoft problems
- Rank Open BusinessesPHONE SCREEN · Seen May 2026
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW · Seen Feb 2026
- Distinct Number Line MovesOA · Seen Oct 2025
- Minimum Round Trip LengthsOA · Seen Aug 2025
- Programmer StringsOA · Seen Aug 2025
- Get Minimum TimeSeen Jun 2025
public String concatenateOrderedPayloads(String[] starts, String[] ends, String[] payloads) {
// write your code here
}
starts["aaa", "bbb", "ccc"]
ends["bbb", "ccc", "ddd"]
payloads["2", "1", "3"]
expected"213"
sign in to submit