Tap here to switch tabs
Problem
Submissions

Problem: Spiral Matrix IV

med
30 min
Try to solve the Spiral Matrix IV problem.

Statement

You are given two integers m and n, which represent the dimensions of an m×nm \times n matrix. You are also given the head of a linked list of integers.

Generate an m×nm \times n matrix filled with the elements of the linked list in clockwise spiral order, beginning at the top left cell at position (0,0)(0, 0) and proceeding from left to right, then downwards, and so forth.

If there are empty cells remaining in the matrix after exhausting all elements of the linked list, fill these remaining cells with −1-1.

Return the generated matrix.

Constraints:

  • 1≤1 \leq m, n ≤105\leq 10^5

  • 1≤1 \leq m ×\times n ≤105\leq 10^5

  • The number of nodes in the list is in the range [1,[1, m ×\times n]].

  • 0≤0 \leq Node.val ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Spiral Matrix IV

med
30 min
Try to solve the Spiral Matrix IV problem.

Statement

You are given two integers m and n, which represent the dimensions of an m×nm \times n matrix. You are also given the head of a linked list of integers.

Generate an m×nm \times n matrix filled with the elements of the linked list in clockwise spiral order, beginning at the top left cell at position (0,0)(0, 0) and proceeding from left to right, then downwards, and so forth.

If there are empty cells remaining in the matrix after exhausting all elements of the linked list, fill these remaining cells with −1-1.

Return the generated matrix.

Constraints:

  • 1≤1 \leq m, n ≤105\leq 10^5

  • 1≤1 \leq m ×\times n ≤105\leq 10^5

  • The number of nodes in the list is in the range [1,[1, m ×\times n]].

  • 0≤0 \leq Node.val ≤1000\leq 1000