PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Microsoft

Solve binary-tree reverse printing and LPS

Last updated: May 10, 2026

Quick Overview

This question evaluates proficiency with tree data structures and level-order traversal semantics for reverse level printing, as well as string algorithmic reasoning and dynamic programming concepts for computing the longest palindromic subsequence, categorized under Coding & Algorithms.

  • easy
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Solve binary-tree reverse printing and LPS

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given a binary tree node definition: - `TreeNode { int val; TreeNode left; TreeNode right; }` Answer the following two algorithmic questions. ## 1) Reverse-print a binary tree Implement a function that returns the values of the tree **level by level from bottom to top**. - **Input:** `root` (possibly `null`) - **Output:** a list of levels, where each level is a list of node values - **Order requirement:** within each level, nodes are listed **from left to right**, but the **levels** are returned in **reverse** (deepest level first). **Example** Tree: - `1` - left: `2` (children: `4`, `5`) - right: `3` (right child: `6`) Output: `[[4,5,6],[2,3],[1]]` ## 2) Longest palindromic subsequence (LPS) Given a string `s`, return the **length** of the longest subsequence of `s` that is a palindrome. - A subsequence keeps relative order but may delete characters. - **Input:** string `s` - **Output:** integer length **Example** - Input: `"bbbab"` - Output: `4` (one LPS is `"bbbb"`) ### Constraints (assume typical interview constraints) - `0 <= number_of_nodes <= 10^5` for the tree - `1 <= |s| <= 2000` for LPS

Quick Answer: This question evaluates proficiency with tree data structures and level-order traversal semantics for reverse level printing, as well as string algorithmic reasoning and dynamic programming concepts for computing the longest palindromic subsequence, categorized under Coding & Algorithms.

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
Dec 24, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0

You are given a binary tree node definition:

  • TreeNode { int val; TreeNode left; TreeNode right; }

Answer the following two algorithmic questions.

1) Reverse-print a binary tree

Implement a function that returns the values of the tree level by level from bottom to top.

  • Input: root (possibly null )
  • Output: a list of levels, where each level is a list of node values
  • Order requirement: within each level, nodes are listed from left to right , but the levels are returned in reverse (deepest level first).

Example

Tree:

  • 1
    • left: 2 (children: 4 , 5 )
    • right: 3 (right child: 6 )

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

2) Longest palindromic subsequence (LPS)

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

  • A subsequence keeps relative order but may delete characters.
  • Input: string s
  • Output: integer length

Example

  • Input: "bbbab"
  • Output: 4 (one LPS is "bbbb" )

Constraints (assume typical interview constraints)

  • 0 <= number_of_nodes <= 10^5 for the tree
  • 1 <= |s| <= 2000 for LPS

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.