FastPrepFind a Template Across Binary-Tree Leaves
Problems/Find a Template Across Binary-Tree Leaves

Find a Template Across Binary-Tree Leaves

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamples

Problem statement

Source note: The report gives the goal of searching the leaves of a tree and asks about complexity. It does not give a function signature, examples, or input limits. Our version is about 96% the same as the reported question.

The text represented by a binary tree is formed by concatenating the values of its leaves from left to right. A leaf value may be a string, a single character, or a space.

In this practice interface, leafValues lists the leaf values in that same left-to-right order. Given leafValues and a string templateText, return true if templateText occurs as a contiguous substring of the tree's text. Otherwise, return false.

Characters, including spaces, must match exactly. A match may begin in one leaf value and continue into another.

Function

containsLeafTemplate(leafValues: String[], templateText: String) → boolean

Examples

Example 1

leafValues = ["ab","c"," de"]templateText = "c d"return = true

The leaves form abc de. The template c d appears across the boundary between the second and third leaf values.

Example 2

leafValues = ["hello"," ","world"]templateText = "lo wo"return = true

The leaves form hello world, which contains lo wo.

Example 3

leafValues = ["binary"," ","tree"]templateText = "template"return = false

The leaves form binary tree, which does not contain template.

More Google Onsite Interview questions

  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Shortest Uncommon SubstringAirbnb · ONSITE INTERVIEWAirbnb interview questions
  • Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • Longest Substring Without Repeating CharactersOracle · ONSITE INTERVIEWOracle interview questions
  • Longest Substring Without Repeating CharactersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Classify Password StrengthHackerRank · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
  • Sliding Items on a Circular RingIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
  • Longest Substring Without Repeating CharactersMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions

Interview reports that mention this question

  • Google L4 PhD New Grad Europe Onsite: 1 Experience

Google interview experiences

  • Google L5 Security Engineer Domain Knowledge Round: 1 Experience
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public boolean containsLeafTemplate(String[] leafValues, String templateText) {
        // Write your code here.
    }
}
Checking account…