PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Google

Find mode in a trinary search tree

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's understanding of tree data structures and frequency analysis, focusing on handling a trinary search tree variant and determining mode values across possibly large datasets.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Find mode in a trinary search tree

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given the root of a **trinary search tree** where each node has up to three children: ```text class Node { int val; Node left; // all values < val Node middle; // all values = val Node right; // all values > val } ``` Assume the tree is intended to satisfy the ordering rules above. ## Task Return the **mode(s)** of the tree: the value(s) that occur most frequently among all nodes. - If there is one mode, return a single-element list. - If multiple values tie for highest frequency, return **all** such values (in any order). ## Constraints (typical) - Number of nodes `n` can be large (e.g., up to `10^5`). - Values can be any 32-bit signed integers. ## Follow-up How would your approach change if the tree is **broken** (i.e., it may not respect the `<`, `=`, `>` constraints), but you still must return the correct mode(s)?

Quick Answer: This question evaluates a candidate's understanding of tree data structures and frequency analysis, focusing on handling a trinary search tree variant and determining mode values across possibly large datasets.

Related Interview Questions

  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Solve Shortest Paths and Rental Allocation - Google (medium)
  • Solve Two Array Optimization Problems - Google (medium)
Google logo
Google
Nov 16, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0

You are given the root of a trinary search tree where each node has up to three children:

class Node {
  int val;
  Node left;    // all values < val
  Node middle;  // all values = val
  Node right;   // all values > val
}

Assume the tree is intended to satisfy the ordering rules above.

Task

Return the mode(s) of the tree: the value(s) that occur most frequently among all nodes.

  • If there is one mode, return a single-element list.
  • If multiple values tie for highest frequency, return all such values (in any order).

Constraints (typical)

  • Number of nodes n can be large (e.g., up to 10^5 ).
  • Values can be any 32-bit signed integers.

Follow-up

How would your approach change if the tree is broken (i.e., it may not respect the <, =, > constraints), but you still must return the correct mode(s)?

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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