PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Capital One

Sort Every Concentric Matrix Border Clockwise

Last updated: Jul 22, 2026

Quick Overview

Sort the values on each concentric border of a rectangular matrix, then write them back clockwise from the layer's top-left cell. The exercise tests precise coordinate traversal and edge cases where an inner layer collapses to a row, column, or single cell.

  • medium
  • Capital One
  • Coding & Algorithms
  • Software Engineer

Sort Every Concentric Matrix Border Clockwise

Company: Capital One

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

# Sort Every Concentric Matrix Border Clockwise Given a nonempty rectangular integer matrix, process each concentric layer independently. For a layer, list its coordinates clockwise starting at that layer's top-left cell. Sort the values from that border in ascending order, then write them back along the same clockwise coordinate order. Return the transformed matrix. The innermost layer may be a single row, a single column, or one cell. Every matrix cell belongs to exactly one layer. ## Function Signature ```python def sort_matrix_borders(matrix: list[list[int]]) -> list[list[int]]: ... ``` ## Constraints - `1 <= len(matrix) <= 200` - `1 <= len(matrix[0]) <= 200` - Every row has the same length. - `-1_000_000_000 <= matrix[r][c] <= 1_000_000_000` ## Example ```text Input: [[9, 8, 7], [6, 5, 4], [3, 2, 1]] Output: [[1, 2, 3], [9, 5, 4], [8, 7, 6]] ``` The outer values are written in ascending order along the clockwise path from the top-left cell; the center cell forms its own layer.

Quick Answer: Sort the values on each concentric border of a rectangular matrix, then write them back clockwise from the layer's top-left cell. The exercise tests precise coordinate traversal and edge cases where an inner layer collapses to a row, column, or single cell.

Related Interview Questions

  • Reorder a String by Alternating Its Left and Right Ends - Capital One (medium)
  • Arrange Match Results in Repeating Win-Draw-Loss Order - Capital One (medium)
  • Count Pairs of Cyclically Equivalent Integers - Capital One (medium)
  • Sort Matrix Diagonals By Their Values - Capital One (medium)
|Home/Coding & Algorithms/Capital One

Sort Every Concentric Matrix Border Clockwise

Capital One logo
Capital One
Jul 21, 2026, 12:00 AM
mediumSoftware EngineerTake-home ProjectCoding & Algorithms
0
0

Sort Every Concentric Matrix Border Clockwise

Given a nonempty rectangular integer matrix, process each concentric layer independently.

For a layer, list its coordinates clockwise starting at that layer's top-left cell. Sort the values from that border in ascending order, then write them back along the same clockwise coordinate order. Return the transformed matrix.

The innermost layer may be a single row, a single column, or one cell. Every matrix cell belongs to exactly one layer.

Function Signature

def sort_matrix_borders(matrix: list[list[int]]) -> list[list[int]]:
    ...

Constraints

  • 1 <= len(matrix) <= 200
  • 1 <= len(matrix[0]) <= 200
  • Every row has the same length.
  • -1_000_000_000 <= matrix[r][c] <= 1_000_000_000

Example

Input:
[[9, 8, 7],
 [6, 5, 4],
 [3, 2, 1]]

Output:
[[1, 2, 3],
 [9, 5, 4],
 [8, 7, 6]]

The outer values are written in ascending order along the clockwise path from the top-left cell; the center cell forms its own layer.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Capital One•More Software Engineer•Capital One Software Engineer•Capital One Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.