← Applovin Interview Insights

Applovin·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Got a coding question at Applovin that was basically a twist on a classic BST validation problem. Not the hardest thing in the world but the modification tripped me up a bit.

Questions Asked (1)

Q1

Given a binary tree, instead of just checking whether it's a valid BST, return the count of nodes that violate the BST property based on their valid range in an in-order traversal.

Algorithms & Data Structures
Author's notes

My first instinct was to just do the standard recursive validation with a low/high range per node, which is right, but I kept wanting to return a boolean and had to mentally reset.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a recursive in-order traversal that passes down the valid (min, max) range for each node. At each node, check if its value falls within the range; if not, increment a counter. Then recurse left with updated max and right with updated min, ensuring the range constraints are enforced.

Pro tip: Clarify whether the BST property allows duplicates and how to handle them (e.g., strict inequality). Also, mention that you can combine the validation and counting in one pass to achieve O(n) time and O(h) space.

1. Clarify requirements and edge cases

Ask about duplicate values, null nodes, and whether the tree is guaranteed to be binary. Confirm that 'violate' means the node's value is outside its valid range.

2. Define the recursive function

Design a helper function that takes a node, a lower bound, and an upper bound, and returns the count of violations in the subtree. Use a nonlocal counter or return the count.

3. Implement range checking and recursion

At each node, if its value is not within (lower, upper), increment the violation count. Then recursively process left child with upper bound = node.val and right child with lower bound = node.val.

4. Handle base case and return result

If the node is null, return 0 (or the current count). After traversing, return the total count of violations.

5. Analyze complexity and test

State that time complexity is O(n) and space is O(h) due to recursion stack. Walk through a small example to verify correctness.

Key Points to Mention

  • In-order traversal property of BST: nodes should be visited in strictly increasing order.
  • Using range constraints (min, max) to validate each node instead of just comparing with parent.
  • Handling duplicates: decide whether to allow equal values and adjust bounds accordingly.
  • Single-pass solution that counts violations without extra space beyond recursion stack.
  • Edge cases: empty tree, single node, skewed tree, and nodes with extreme values.
  • Time and space complexity: O(n) time, O(h) space where h is tree height.

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