Check Array Formation Through Concatenation

EasyArrays & Hashinghashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given an array arr of distinct integers and an array of integer arrays pieces, where all integers across all pieces are also distinct. You want to build arr by concatenating every piece exactly once, in any order you like, but you may not rearrange the integers inside a piece. Return true if this is possible and false otherwise.

Examples

Input: arr = [15,88], pieces = [[88],[15]]
Output: true
Concatenate [15] then [88].
Input: arr = [49,18,16], pieces = [[16,18,49]]
Output: false
The piece matches the values but in the wrong internal order.
Input: arr = [91,4,64,78], pieces = [[78],[4,64],[91]]
Output: true
Use [91], [4,64], then [78].

Constraints

  • 1 <= pieces.length <= arr.length <= 100
  • sum(pieces[i].length) == arr.length
  • 1 <= pieces[i].length <= arr.length
  • 1 <= arr[i], pieces[i][j] <= 100
  • The integers in `arr` are distinct, and the integers across all of `pieces` are distinct

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems