PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Microsoft

Solve four classic algorithm problems

Last updated: Mar 29, 2026

Quick Overview

This set evaluates proficiency in core algorithms and data structures: tree traversal and order manipulation (zigzag level-order), dynamic programming and subsequence reasoning (longest palindromic subsequence), numeric algorithms and search/approximation (integer square root), and positional numeral systems/base conversion (spreadsheet column to number). These problems are commonly asked to assess algorithmic thinking, complexity analysis, and handling of edge cases in the Coding & Algorithms domain, testing both conceptual understanding of underlying principles and practical application of implementation techniques.

  • easy
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Solve four classic algorithm problems

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given four independent coding tasks. For each task, implement the required function. --- ## Problem 1: Zigzag level-order traversal of a binary tree Given the root of a binary tree, return the node values level by level, but **alternate the traversal direction** each level: - Level 0 (root level): left → right - Level 1: right → left - Level 2: left → right - … and so on. **Input:** `root` (binary tree node) **Output:** A list of lists, where each inner list contains the values for one level in the required order. **Example:** - Tree: `1,2,3,4,5,null,6` - Output: `[[1],[3,2],[4,5,6]]` **Constraints:** number of nodes up to ~10^4. --- ## Problem 2: Longest palindromic subsequence length Given a string `s`, return the **length** of the longest subsequence of `s` that is a palindrome. - A **subsequence** can delete characters without changing the relative order of the remaining characters. **Input:** string `s` **Output:** integer length **Example:** - Input: `s = "bbbab"` - Output: `4` (one answer is subsequence `"bbbb"`) **Constraints:** `1 <= len(s) <= 1000`. --- ## Problem 3: Integer square root (floor) Given a non-negative integer `x`, compute and return `⌊sqrt(x)⌋` (the integer part of the square root). **Input:** integer `x >= 0` **Output:** integer `r` such that `r*r <= x < (r+1)*(r+1)` **Example:** - Input: `x = 8` - Output: `2` **Constraints:** `0 <= x <= 2^31 - 1`. --- ## Problem 4: Spreadsheet column label to number In a spreadsheet, columns are labeled `A, B, ..., Z, AA, AB, ..., AZ, BA, ...`. Given a column label string `col` consisting of uppercase English letters, return its **1-indexed** column number. **Input:** string `col` **Output:** integer **Examples:** - `"A" -> 1` - `"Z" -> 26` - `"AA" -> 27` - `"ZY" -> 701` **Constraints:** `1 <= len(col) <= 7` (or any length that fits within 32-bit/64-bit integer, depending on language).

Quick Answer: This set evaluates proficiency in core algorithms and data structures: tree traversal and order manipulation (zigzag level-order), dynamic programming and subsequence reasoning (longest palindromic subsequence), numeric algorithms and search/approximation (integer square root), and positional numeral systems/base conversion (spreadsheet column to number). These problems are commonly asked to assess algorithmic thinking, complexity analysis, and handling of edge cases in the Coding & Algorithms domain, testing both conceptual understanding of underlying principles and practical application of implementation techniques.

Related Interview Questions

  • Sort Three Categories In Place - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Implement SFT Sample Packing - Microsoft (medium)
  • Implement SQL Table and DNA Ordering - Microsoft (medium)
  • Solve power jumps and graph tour - Microsoft (hard)
Microsoft logo
Microsoft
Nov 30, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0

You are given four independent coding tasks. For each task, implement the required function.

Problem 1: Zigzag level-order traversal of a binary tree

Given the root of a binary tree, return the node values level by level, but alternate the traversal direction each level:

  • Level 0 (root level): left → right
  • Level 1: right → left
  • Level 2: left → right
  • … and so on.

Input: root (binary tree node)

Output: A list of lists, where each inner list contains the values for one level in the required order.

Example:

  • Tree: 1,2,3,4,5,null,6
  • Output: [[1],[3,2],[4,5,6]]

Constraints: number of nodes up to ~10^4.

Problem 2: Longest palindromic subsequence length

Given a string s, return the length of the longest subsequence of s that is a palindrome.

  • A subsequence can delete characters without changing the relative order of the remaining characters.

Input: string s

Output: integer length

Example:

  • Input: s = "bbbab"
  • Output: 4 (one answer is subsequence "bbbb" )

Constraints: 1 <= len(s) <= 1000.

Problem 3: Integer square root (floor)

Given a non-negative integer x, compute and return ⌊sqrt(x)⌋ (the integer part of the square root).

Input: integer x >= 0

Output: integer r such that r*r <= x < (r+1)*(r+1)

Example:

  • Input: x = 8
  • Output: 2

Constraints: 0 <= x <= 2^31 - 1.

Problem 4: Spreadsheet column label to number

In a spreadsheet, columns are labeled A, B, ..., Z, AA, AB, ..., AZ, BA, ....

Given a column label string col consisting of uppercase English letters, return its 1-indexed column number.

Input: string col

Output: integer

Examples:

  • "A" -> 1
  • "Z" -> 26
  • "AA" -> 27
  • "ZY" -> 701

Constraints: 1 <= len(col) <= 7 (or any length that fits within 32-bit/64-bit integer, depending on language).

Comments (0)

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 7,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.