PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of grid and string manipulation, coordinate transformations, spatial reasoning, and character validation in constrained inputs.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Rotate a 3×3 digit grid by 180°

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem You are given a **3×3** grid of digits (characters `'0'`–`'9'`), represented as an array of 3 strings of length 3. When the entire grid is rotated by **180 degrees**: 1. Each cell `(r, c)` moves to `(2 - r, 2 - c)`. 2. Each digit must also be replaced by what it looks like after a **180-degree rotation**. Assume only the following digits remain valid under 180° rotation: - `0 → 0` - `1 → 1` - `8 → 8` - `6 → 9` - `9 → 6` All other digits (`2,3,4,5,7`) become invalid. ### Task Return the rotated 3×3 grid (same format) if every cell can be rotated successfully; otherwise return the string `"INVALID"`. ### Input/Output - **Input:** `grid`: array of 3 strings, each of length 3, containing digits. - **Output:** array of 3 strings (rotated grid) or `"INVALID"`. ### Examples - Input: - `["169", "808", "001"]` - Output: - `["100", "808", "691"]` - Input: `["123","456","789"]` → `"INVALID"` (contains digits not rotatable)

Quick Answer: This question evaluates understanding of grid and string manipulation, coordinate transformations, spatial reasoning, and character validation in constrained inputs.

Rotate a 3x3 digit grid and transform each digit under 180-degree rotation, or return INVALID.

Constraints

  • grid has three strings of length three

Examples

Input: (['169', '808', '001'],)

Expected Output: ['100', '808', '691']

Explanation: Prompt example.

Input: (['123', '456', '789'],)

Expected Output: 'INVALID'

Explanation: Invalid digits.

Input: (['000', '111', '888'],)

Expected Output: ['888', '111', '000']

Explanation: Self-rotating digits.

Hints

  1. Read destination cells from the opposite source cell and map each digit.
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
  • 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

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)