Problem 265911 · easy · Phase 02 Linear Data Structures

Pair Up With Padding

arrays · zipping · iteration

Given two lists a and b and a value fill, return a list of two-element lists [a[i], b[i]] for every index i from 0 up to the length of the longer list. Where the shorter list has no element at index i, use fill in its place.

Examples

Input:  a = [1, 2, 3], b = ['a', 'b'], fill = None
Output: [[1, 'a'], [2, 'b'], [3, None]]

Input:  a = [], b = [7, 8], fill = 0
Output: [[0, 7], [0, 8]]

Constraints

  • 0 <= len(a), len(b) <= 10**5
  • Return a new list of two-element lists (not tuples).
  • Target: O(max(len(a), len(b))) time.

Goals

  • Pair elements by index across two lists
  • Fill missing positions of the shorter list with a given value
  • Produce exactly max(len(a), len(b)) pairs
Starting Python…