← Applovin Interview Insights

Applovin·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Applovin SWE interview with a twist on a classic BST problem. Instead of just validating the tree, they wanted a count of violating nodes, which sounds like a small change but actually requires you to think more carefully about what you're tracking.

Questions Asked (1)

Q1

Given the root of a binary tree, instead of checking whether it's a valid BST, return the count of nodes that violate the BST property (where a node violates if its value falls outside the valid range implied by all its ancestors, counting each violating node only once).

Algorithms & Data Structures
Author's notes

My first instinct was to just return a boolean and I had to stop myself.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a top-down DFS that passes down the valid (min, max) range for each node, counting a node as violating if its value is outside that range and then stopping recursion into its children to avoid double-counting. For non-violating nodes, update the range for left and right subtrees accordingly.

Pro tip: Clarify that once a node violates the BST property, its entire subtree is considered invalid, so you should not recurse further into it—this avoids counting descendants as separate violations and matches the 'counting each violating node only once' requirement.

1. Clarify the definition of violation

Confirm that a node violates if its value is outside the range implied by all ancestors, and that once a node violates, its descendants are not counted separately. This sets the recursion base case.

2. Define the recursive helper

Write a function that takes a node, a lower bound, and an upper bound, and returns the count of violating nodes in the subtree. Use -infinity and +infinity for the root.

3. Check violation and recurse

If the node is null, return 0. If node.val is outside [low, high], return 1 (and do not recurse). Otherwise, recurse left with (low, node.val) and right with (node.val, high), and return the sum.

4. Analyze complexity

Explain that each node is visited at most once, so time complexity is O(n) and space complexity is O(h) for the recursion stack, where h is the tree height.

5. Test with edge cases

Walk through examples: a valid BST (returns 0), a tree where the root violates (returns 1), and a tree with multiple violations at different levels to ensure no double-counting.

Key Points to Mention

  • Use of range propagation (min/max bounds) instead of just comparing with immediate parent.
  • Early termination when a violation is found to avoid counting descendants.
  • Handling of integer overflow by using long or null for bounds, or using -inf/+inf.
  • Time and space complexity analysis.
  • Comparison with the standard 'validate BST' problem and how this differs.
  • Edge cases: empty tree, single node, skewed tree, duplicate values (if allowed).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.