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

Apply commands to transform a matrix

Last updated: Apr 25, 2026

Quick Overview

This question evaluates array and matrix manipulation skills, specifically in-place row reversal, row swapping, and 90-degree rotation, and falls under the Coding & Algorithms domain with emphasis on practical implementation.

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

Apply commands to transform a matrix

Company: Capital One

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given an integer matrix `A` of size `n × m` and a list of string commands to apply in order. Implement the commands and return the final matrix. ## Commands Each command is one of: 1. `"reverseRow r"` - `r` is a 0-based row index. - Reverse the elements in row `r` in-place. 2. `"swap r1 r2"` - `r1` and `r2` are 0-based row indices. - Swap the two rows. 3. `"rotate"` - Rotate the entire matrix 90 degrees clockwise. - Note that after rotation, the matrix dimensions become `m × n`. ## Input/Output - Input: `A` and `commands`. - Output: the matrix after applying all commands in order. ## Assumptions / Constraints - `0 ≤ r, r1, r2 < current_number_of_rows` at the time the command is executed. - Matrix elements fit in 32-bit signed integers. - `n, m ≥ 1`. ## Example If `A = [[1,2,3],[4,5,6]]` and `commands = ["reverseRow 0", "rotate"]`, then: - After `reverseRow 0`: `[[3,2,1],[4,5,6]]` - After `rotate`: `[[4,3],[5,2],[6,1]]` Return `[[4,3],[5,2],[6,1]]`.

Quick Answer: This question evaluates array and matrix manipulation skills, specifically in-place row reversal, row swapping, and 90-degree rotation, and falls under the Coding & Algorithms domain with emphasis on practical implementation.

Related Interview Questions

  • Solve Four Coding Assessment Tasks - Capital One (medium)
  • Write SQL using joins and window functions - Capital One (medium)
  • Review Preprocessing Code and Tests - Capital One (easy)
  • Remove nodes with a given value - Capital One (medium)
  • Solve multiple algorithmic interview questions - Capital One (hard)
Capital One logo
Capital One
Sep 19, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
9
0

You are given an integer matrix A of size n × m and a list of string commands to apply in order. Implement the commands and return the final matrix.

Commands

Each command is one of:

  1. "reverseRow r"
    • r is a 0-based row index.
    • Reverse the elements in row r in-place.
  2. "swap r1 r2"
    • r1 and r2 are 0-based row indices.
    • Swap the two rows.
  3. "rotate"
    • Rotate the entire matrix 90 degrees clockwise.
    • Note that after rotation, the matrix dimensions become m × n .

Input/Output

  • Input: A and commands .
  • Output: the matrix after applying all commands in order.

Assumptions / Constraints

  • 0 ≤ r, r1, r2 < current_number_of_rows at the time the command is executed.
  • Matrix elements fit in 32-bit signed integers.
  • n, m ≥ 1 .

Example

If A = [[1,2,3],[4,5,6]] and commands = ["reverseRow 0", "rotate"], then:

  • After reverseRow 0 : [[3,2,1],[4,5,6]]
  • After rotate : [[4,3],[5,2],[6,1]] Return [[4,3],[5,2],[6,1]] .

Submit Your Answer

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
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.