FastPrepCenter-Outward Number Spiral
Problems/Center-Outward Number Spiral

Center-Outward Number Spiral

ZipRecruiter logoZipRecruiter● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report shows the spiral direction on a 7 by 7 matrix but does not define even sizes or numeric limits. Our version is about 97% the same as the reported question.

Given a positive odd integer n, construct an n by n matrix containing every integer from 1 through n * n.

Place 1 in the center cell. Continue with consecutive integers while moving in an outward spiral:

  1. Move down first.
  2. Turn right relative to the current movement after completing each leg, so the directions repeat as down, left, up, right.
  3. Increase the leg length after every two legs.
  4. Stop after placing n * n.

Return the completed matrix.

Function

centerOutwardSpiral(n: int) → int[][]

Examples

Example 1

n = 3return = [[5,6,7],[4,1,8],[3,2,9]]

The spiral starts at the center with 1, moves down to 2, then expands through left, up, and right turns until 9 reaches the bottom-right corner.

Example 2

n = 1return = [[1]]

A one-cell matrix contains only the center value 1.

Constraints

  • 1 <= n <= 99
  • n is odd.

More ZipRecruiter Phone Screen questions

  • Neighboring Record IDsPHONE SCREEN · Seen May 2026
  • Restaurant Vote LeadersPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
  • Most Frequent Word across Grouped ArraysPHONE SCREEN · Seen Sep 2024
  • Starting Value with the Longest Collatz ChainPHONE SCREEN · Seen Apr 2022
  • Classify an Alien Dictionary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
  • Multiset Intersection of Three ListsPHONE SCREEN · Seen Feb 2022
  • Find the Smallest Magic IndexPHONE SCREEN · Seen Dec 2021
  • Website Pair with the Most Common VisitorsPHONE SCREEN · Seen Nov 2021
  • Missing Ranges within Inclusive BoundsPHONE SCREEN · Seen Feb 2021
  • Fibonacci Number with Constant Extra SpacePHONE SCREEN · Seen Mar 2017

Similar questions at other companies

  • Grid Infection with Recovery After D DaysOpenAI · PHONE SCREENOpenAI interview questions
  • Days Until Poisoned Plants StabilizeApple · PHONE SCREENApple interview questions
  • Apply a 2048 Board MoveGlean · PHONE SCREENGlean interview questions
  • Dense Matrix MultiplicationAmazon · PHONE SCREEN
  • File-Backed Dense Game of LifeApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Tilting Maze BallHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Spiral Order with ObstaclesTemu · PHONE SCREENTemu interview questions
  • Logistic Regression DiagnosticsLinkedIn · PHONE SCREENLinkedIn interview questions
  • Spiral Matrix TraversalByteDance · PHONE SCREENByteDance interview questions
  • S-Shaped Matrix TraversalFox Corporation · PHONE SCREEN

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int[][] centerOutwardSpiral(int n) {
        // Write your solution here.
    }
}
Checking account…