Asana logo

Asana

San Francisco, CASoftware

Interview Questions

2048 Game Implementation

Asked at Asana
technical
game design
implementation

Design and implement the 2048 game.

Core Components:

interface Position {
  x: number;
  y: number;
}

class Game2048 {
  private board: number[][];
  
  constructor(size: number = 4);
  move(direction: Direction): boolean;
  addNewTile(): void;
  isGameOver(): boolean;
  getScore(): number;
}

enum Direction {
  UP,
  DOWN,
  LEFT,
  RIGHT
}

Requirements:
1. Game Logic
- Tile merging rules
- Movement mechanics
- Score tracking
- Game over detection

2. Board Management
- Initialize board
- Add random tiles
- Handle merges
- Update state

Example:

Initial: [2][0][2][0] [0][2][0][0] [0][0][2][0] [0][0][0][2]

After LEFT: [4][0][0][0] [2][0][0][0] [2][0][0][0] [2][0][0][0]

Jigsaw Puzzle Design

Asked at Asana
technical
object oriented
algorithms

Design classes and relationships for jigsaw puzzle solver.

Core Classes:

enum SideType {
  IN,    // Tab
  OUT,   // Blank
  FLAT   // Edge
}

class Side {
  type: SideType;
  pattern: number;  // Unique pattern ID
  
  matches(other: Side): boolean {
    return this.pattern === other.pattern &&
           this.type !== other.type;
  }
}

class Piece {
  id: number;
  sides: Side[];
  position?: Position;
  
  canConnect(other: Piece, side: number): boolean;
  rotate(times: number): void;
}

class Puzzle {
  pieces: Piece[];
  width: number;
  height: number;
  
  solve(): boolean;
  private findEdgePieces(): Piece[];
  private tryPlace(piece: Piece, pos: Position): boolean;
}

Solution Strategy:
1. Find corner pieces
2. Build edges
3. Fill interior
4. Validate connections

LRU Cache Implementation

Asked at Asana
technical
data structures
design

Implement LRU Cache (LeetCode 146).

class LRUCache {
  constructor(capacity: number);
  get(key: number): number;
  put(key: number, value: number): void;
}

Requirements:
- O(1) operations
- Fixed capacity
- LRU eviction policy

See: https://leetcode.com/problems/lru-cache/

Product of Array Except Self

Asked at Asana
technical
arrays
algorithms

Calculate array product excluding self (LeetCode 238).

function productExceptSelf(nums: number[]): number[]

Requirements:
- O(n) time complexity
- No division operator
- O(1) extra space

See: https://leetcode.com/problems/product-of-array-except-self/

Validate Binary Search Tree

Asked at Asana
technical
trees
recursion

Validate if binary tree is BST (LeetCode 98).

function isValidBST(root: TreeNode): boolean

Requirements:
- Check BST properties
- Handle duplicates
- Consider node ranges

See: https://leetcode.com/problems/validate-binary-search-tree/

K Closest Points to Origin

Asked at Asana
technical
heap
sorting

Find k closest points to origin (LeetCode 973).

function kClosest(points: number[][], k: number): number[][]

Requirements:
- Use Euclidean distance
- Return k closest points
- Optimize for large inputs

See: https://leetcode.com/problems/k-closest-points-to-origin/

Maximum Subarray

Asked at Asana
technical
arrays
dynamic programming

Find contiguous subarray with largest sum (LeetCode 53).

function maxSubArray(nums: number[]): number

Requirements:
- Handle negative numbers
- O(n) time complexity
- Track subarray bounds

See: https://leetcode.com/problems/maximum-subarray/

Count of Matches in Tournament

Asked at Asana
technical
math
simulation

Calculate tournament matches (LeetCode 1688).

function numberOfMatches(n: number): number

Requirements:
- Tournament pairing rules
- Count total matches
- Handle odd numbers

See: https://leetcode.com/problems/count-of-matches-in-tournament/

Share Your Experience at Asana