PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Microsoft

Rotate a 3×3 digit grid by 180°

Last updated: Mar 29, 2026

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.

Related Interview Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)
Microsoft logo
Microsoft
Jan 6, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
7
0
Loading...

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)

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Software Engineer•Microsoft Software Engineer•Microsoft Coding & Algorithms•Software Engineer Coding & Algorithms
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.