PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Atlassian

Implement snake game and find org LCA

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in designing efficient data structures and APIs for real-time simulation (grid-based snake game) and in tree algorithms for computing lowest common ancestors, including handling edge cases, correctness, and formal time/space complexity analysis.

  • Medium
  • Atlassian
  • Coding & Algorithms
  • Software Engineer

Implement snake game and find org LCA

Company: Atlassian

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Part A — Snake Game Engine: Implement a grid-based snake game. The board has height H and width W (0-indexed, row-major). The snake starts at (0, 0) moving right and initially occupies one cell. You are given a list of food positions as (row, col) that must be consumed in order. Expose an API: class Snake(int H, int W, List<(int,int)> food); int step(char dir) where dir ∈ {'U','D','L','R'}. On each step, the snake advances one cell; if the new head lands on the next food, increase score by 1 and grow (do not remove tail this turn); otherwise move the tail forward (no growth). Return the current score after a valid move, or -1 if the snake collides with walls or its own body (moving into the cell just vacated by the tail in the same step is allowed). Design data structures to support O( 1) time per step and implement the API. Describe time/space complexity. Part B — Lowest Common Manager: Given an organization chart as a rooted n-ary tree with unique employee IDs and only child adjacency lists (no parent pointers), implement a function lowestCommonManager(root, a, b) that returns the lowest common manager of employees a and b. Handle cases where one or both employees may be absent. Discuss an approach optimized for a single query and an approach that supports many queries efficiently (e.g., preprocessing). Provide time/space complexity for both.

Quick Answer: This question evaluates proficiency in designing efficient data structures and APIs for real-time simulation (grid-based snake game) and in tree algorithms for computing lowest common ancestors, including handling edge cases, correctness, and formal time/space complexity analysis.

Related Interview Questions

  • Find a secret word using match feedback - Atlassian (hard)
  • Compute a moving average on a stream - Atlassian (hard)
  • Implement sequential and parallel URL requests - Atlassian (medium)
  • Implement sliding-window rate limiter function - Atlassian (medium)
  • Merge intervals and design rating APIs - Atlassian (medium)
Atlassian logo
Atlassian
Sep 6, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
4
0

Part A — Snake Game Engine: Implement a grid-based snake game. The board has height H and width W (0-indexed, row-major). The snake starts at (0, 0) moving right and initially occupies one cell. You are given a list of food positions as (row, col) that must be consumed in order. Expose an API: class Snake(int H, int W, List<(int,int)> food); int step(char dir) where dir ∈ {'U','D','L','R'}. On each step, the snake advances one cell; if the new head lands on the next food, increase score by 1 and grow (do not remove tail this turn); otherwise move the tail forward (no growth). Return the current score after a valid move, or -1 if the snake collides with walls or its own body (moving into the cell just vacated by the tail in the same step is allowed). Design data structures to support O(

  1. time per step and implement the API. Describe time/space complexity.

Part B — Lowest Common Manager: Given an organization chart as a rooted n-ary tree with unique employee IDs and only child adjacency lists (no parent pointers), implement a function lowestCommonManager(root, a, b) that returns the lowest common manager of employees a and b. Handle cases where one or both employees may be absent. Discuss an approach optimized for a single query and an approach that supports many queries efficiently (e.g., preprocessing). Provide time/space complexity for both.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Atlassian•More Software Engineer•Atlassian Software Engineer•Atlassian Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.