Tools
Back to Juspay Hiring Challenge
🔥 Only 15-20% Pass This Round

The Infamous
"Tree of Space" Problem

Master the signature Juspay problem that filters 80-85% of candidates in Hackathon Part A. Complete O(log n) solution guide with parent pointers, descendant count tracking, and targeted practice.

✅ REGISTRATIONS OPEN

Juspay is accepting applications NOW on a rolling basis. Don't wait — apply today for ₹30K-40K/month internship!

What is the Juspay Tree of Space Problem?

The Tree of Space is the signature problem used in Juspay Hiring Challenge 2026 Hackathon Part A. It tests your ability to implement efficient lock/unlock operations on an M-ary tree (a tree where each node can have 0 to M children) with strict concurrency constraints and time complexity requirements.

This problem is infamous because it combines multiple advanced concepts: tree traversal, ancestor-descendant relationships, state management, and time complexity optimization. Only 15-20% of candidates pass this round — making it the single biggest filter in Juspay's hiring process.

📊 By the Numbers

  • Duration: 4-5 hours for Hackathon Part A
  • Passing Rate: 15-20% (80-85% elimination rate)
  • Required Complexity: O(log n) or O(h) for all operations
  • Test Cases: Must pass 80%+ including edge cases

The Infamous "Tree of Space" Problem

This is THE problem that 1,350+ students searching "Juspay Hiring Challenge 2026" are desperately hunting for. If you don't master this, you won't get past Hackathon Part A. Here's the exact breakdown experienced candidates use.

Juspay Hiring Challenge: Round-by-Round Mechanics

extreme4-5 hours

The infamous problem: Implement lock/unlock operations on an M-Ary tree with concurrency constraints. This is THE differentiator — only 15-20% get past this.

Key Skills Tested

Tree Traversal (DFS/BFS)Ancestor & Descendant ChecksState ManagementParent-Child RelationshipsTime Complexity Optimization

Passing Criteria: Must pass 80%+ test cases. Edge cases and time limits are strict.

Common Pitfalls (Why Most Students Fail)

  • Not storing parent pointers — makes ancestor checks slow
  • Inefficient ancestor/descendant lookup (O(n) per query)
  • Forgetting the unlock constraint: "can only unlock if all descendants are unlocked"
  • Memory limit exceeded from storing too much redundant state

Tree of Space: Lock/Unlock an M-Ary Tree

You are given an M-ary tree (each node can have 0 to M children). Implement `lock(node)`, `unlock(node)`, and `upgradeLock(node)` operations with the following constraints:

Constraints (The Hard Part):

1

A node can be locked only if none of its ancestors or descendants are currently locked.

2

A node can be unlocked only if it is currently locked.

3

upgradeLock(node) locks a node and unlocks all its locked descendants, but only if no ancestor is locked.

4

All operations must run in O(log n) or O(h) time where h is tree height.

Real-World Mapping

This models permission systems (e.g., filesystem locks, database row locks, access control trees). Juspay tests if you can build efficient, concurrent-safe tree structures.

How to Solve Tree of Space (O(log n) Approach)

1. Store Parent Pointers

class TreeNode {
  int id;
  TreeNode parent;
  List<TreeNode> children;
  boolean isLocked;
  int lockedBy; // user ID who locked this node
}

Why this works: Store parent pointers to quickly traverse upward for ancestor checks.

2. Efficient Ancestor Check (O(h))

boolean hasLockedAncestor(TreeNode node) {
  TreeNode curr = node.parent;
  while (curr != null) {
    if (curr.isLocked) return true;
    curr = curr.parent;
  }
  return false;
}

Why this works: Walk up the tree to root — O(h) complexity. Store parent pointers for fast traversal.

3. Efficient Descendant Check (Track Count)

// Maintain a count of locked descendants for each node
Map<TreeNode, Integer> lockedDescendantCount;

boolean hasLockedDescendant(TreeNode node) {
  return lockedDescendantCount.get(node) > 0;
}

Why this works: Maintain a count of locked descendants for each node. Update counts during lock/unlock operations. Avoid O(n) DFS on every query.

4. Lock Operation (O(h))

boolean lock(TreeNode node, int userId) {
  if (node.isLocked) return false;
  if (hasLockedAncestor(node)) return false;
  if (hasLockedDescendant(node)) return false;
  
  node.isLocked = true;
  node.lockedBy = userId;
  updateAncestorCounts(node, +1); // increment locked count in ancestors
  return true;
}

Why this works: Check ancestors and descendants. If clear, lock the node and update ancestor counts.

Key Insight (This is What Gets You Selected)

The O(log n) constraint forces you to avoid DFS on every query. Use parent pointers + descendant count tracking instead of naive tree traversals.

Targeted Practice Problems (Sorted by Juspay Round)

1Tree Fundamentals

  • LeetCode 1214: Two Sum BSTs
  • LeetCode 236: Lowest Common Ancestor
  • LeetCode 1650: Lowest Common Ancestor III (parent pointers)

2State Management in Trees

  • LeetCode 1443: Minimum Time to Collect Apples
  • LeetCode 1600: Throne Inheritance (genealogy tree)

3Concurrency Basics

  • LeetCode 1114: Print in Order
  • LeetCode 1115: Print FooBar Alternately
  • LeetCode 1116: Print Zero Even Odd

Ready to Crack Juspay?

Don't waste time on generic DSA prep. Master the Tree of Space, learn the concurrency patterns, and practice the exact problem types Juspay tests.

Related Juspay Resources

Ready to Crack Juspay?

Don't let the Tree of Space eliminate you. Master the O(log n) solution, practice the targeted LeetCode problems, and avoid the common pitfalls that trip up 80% of candidates.

Apply to Juspay Hiring Challenge 2026