PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

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.

Apply reverseRow, swap, and rotate commands to a matrix and return the final matrix.

Constraints

  • Command row indices are valid at execution time

Examples

Input: ([[1, 2, 3], [4, 5, 6]], ['reverseRow 0', 'rotate'])

Expected Output: [[4, 3], [5, 2], [6, 1]]

Explanation: Prompt example.

Input: ([[1, 2], [3, 4]], ['swap 0 1'])

Expected Output: [[3, 4], [1, 2]]

Explanation: Swap rows.

Input: ([[1]], ['rotate', 'reverseRow 0'])

Expected Output: [[1]]

Explanation: Single cell.

Hints

  1. A clockwise rotation is the transpose of the reversed row order.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • 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.

Related Coding 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)