# Tree Node — SQL interview question

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3957/tree-node
Source observed: 2026-11-04T21:34:38.072Z
Last checked: 2026-11-04T21:34:38.072+00:00
Indexed: 2026-11-05T01:45:45.549+00:00

---

# Tree Node

**Difficulty:** Easy  
**Category:** Coding; SQL  
**Roles:** [Software Engineer (9)](https://www.aced.io/questions?role=swe), [Machine Learning Engineer](https://www.aced.io/questions?role=ml-engineer)  
**Companies represented:** [Amazon (2)](https://www.aced.io/questions?company=amazon), [Google (2)](https://www.aced.io/questions?company=google), [Microsoft](https://www.aced.io/questions?company=microsoft), [Samsung](https://www.aced.io/questions?company=samsung), [Palantir](https://www.aced.io/questions?company=palantir), [Barclays](https://www.aced.io/questions?company=barclays), [Meta](https://www.aced.io/questions?company=meta-facebook), and [Infosys](https://www.aced.io/questions?company=infosys).

## Question

Given a binary tree, identify which nodes are leaf nodes, root nodes, or inner nodes.

- **Leaf nodes:** A node with no children
- **Root nodes:** A node with no parent
- **Inner nodes:** A node with both children and parent nodes

The input table is `tree_node_table`:

| Column | Type |
|---|---|
| `id` | integer |
| `p_id` | integer |

`p_id` is the ID of the parent node. Return these columns:

- `id`
- `node_types`, with one of `Root`, `Inner`, or `Leaf`

The solution editor supports SQLite. The solution and mock-interview tabs are locked, and the page includes an option to sign up to run code: [Sign up to run code](https://www.aced.io/signup?src=lesson).

## Interview experiences

The page records **10 shared interview experiences** and shows “11 interviews,” with the last reported occurrence listed as 6 months ago. The experiences are user-submitted examples associated with the following roles and companies:

1. **Amazon — Software Engineer, Intern — 6 months ago**: “It went well and answered all questions. and did both leetcode questions asked one in each interview.” [Read the experience](https://www.aced.io/experiences/amazon-software-engineer-intern-interview-19b58a)
2. **Google — Software Engineer, Entry Level / L3 — 7 months ago**: “Pretty easy, just very long. For technical just need to do leetcode, no system design. Interviewers help you if you are stuck.” [Read the experience](https://www.aced.io/experiences/google-software-engineer-interview-0af9e4)
3. **Microsoft — Machine Learning Engineer, Entry Level / L3 — 7 months ago**: The contributor described smooth live-coding and system-architecture rounds, discussing API design, database strategy, and high availability for microservices. The behavioral portion felt rushed, and interviewers challenged assumptions with “what if” scenarios. [Read the experience](https://www.aced.io/experiences/microsoft-machine-learning-engineer-interview-f29ce8)
4. **Samsung — Software Engineer, Intern — 8 months ago**: “Smooth overall”; the recruiter communicated clearly, allowed enough time to schedule coding, and the coding interviewer set expectations well. [Read the experience](https://www.aced.io/experiences/samsung-software-engineer-intern-interview-62cb56)
5. **Google — Software Engineer, Mid Level / L4 — a year ago**: The contributor described an organized process and relevant, challenging technical interviews, while noting that time between stages made the process longer. [Read the experience](https://www.aced.io/experiences/google-software-engineer-interview-c471d4)
6. **Palantir — Software Engineer, Intern — a year ago**: The contributor described a more difficult-than-expected process involving LeetCode, a mini data project, and a sliding-window question. [Read the experience](https://www.aced.io/experiences/palantir-software-engineer-intern-interview-332d60)
7. **Amazon — Software Engineer, Intern — 2 years ago**: The contributor described a recruiter screen, online assessment, hiring-manager interview, and team interview, with technical LeetCode questions. [Read the experience](https://www.aced.io/experiences/amazon-software-engineer-intern-interview-bccbb0)
8. **Barclays — Software Engineer, Entry Level / L3 — 2 years ago**: The contributor described coding rounds with LC medium questions and system design, smoother behavioral rounds, and rapid increases in difficulty that made time management important. [Read the experience](https://www.aced.io/experiences/barclays-software-engineer-interview-31230a)
9. **Meta — Software Engineer, Intern — 2 years ago**: The contributor described a CodeSignal GCF assessment with four increasingly difficult sections, followed by two LeetCode-style medium questions in a 45-minute technical interview. [Read the experience](https://www.aced.io/experiences/meta-facebook-software-engineer-intern-interview-71076f)
10. **Infosys — Software Engineer, Entry Level / L3 — 2 years ago**: The contributor described a phone round followed by a technical interview, received an offer, and did not accept it. [Read the experience](https://www.aced.io/experiences/infosys-software-engineer-interview-9b8572)

## Related courses

### [Machine Learning Engineer Interview Prep](https://www.aced.io/courses/ml-engineer)

![Machine Learning Engineer Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/6UfkHxUyLQVfDHSfLNQtWa/1be1539a65b4f6f15201f5b573c0a578/ML_Engineer_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

We cover mock interviews, frameworks, and advice from senior candidates for machine-learning roles at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other companies. Topics include ML system design, core concepts, coding, and behavioral interviews.

### [Software Engineering Interview Prep](https://www.aced.io/courses/software-engineering)

![Software Engineering Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/4VkuYewBHUFIVUS5oJDW5h/02e833439b1289f25f38f13f81cbdca3/adobe_stock_optimized.jpeg?w=800&h=800&fm=webp&q=75)

We cover mock interviews, frameworks, and advice from senior candidates for software-engineering roles at Google, Amazon, Microsoft, Meta, Apple, and other companies. Topics include data structures, algorithms, system design, people management, and behavioral interviews.

## Related Aced resources

- [All questions](https://www.aced.io/questions)
- [Coding questions](https://www.aced.io/questions?type=algorithms&filterBy=codeEditor&src=nav)
- [SQL questions](https://www.aced.io/questions?type=sql&filterBy=codeEditor&src=nav)
- [Practice](https://www.aced.io/practice?src=nav)
- [Mock interviews and coaching](https://www.aced.io/coaching?category=mock_interviews&src=nav)
- [Pricing](https://www.aced.io/upgrade?src=nav)

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3957%2Ftree-node&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3957%2Ftree-node). Opening a form does not execute a tool.