Katkat

Implement core puzzle/array/grid routines

AsanaSoftware Engineer · Onsite

Last updated

This question set evaluates algorithmic problem-solving competencies including backtracking and constraint satisfaction for jigsaw assembly, simulation and state manipulation for ASCII canvas and 2048 move logic, and linear-time in-place array transformation for the product-of-array problem.

You may be asked to solve one or more of the following coding exercises (write clean, testable code; discuss time/space complexity):

  1. Jigsaw assembly (small backtracking)
  • You are given N square tiles. Each tile has 4 edge labels: top, right, bottom, left (strings). Two adjacent tiles are compatible if the touching edges have the same label.
  • A tile may be rotated (0/90/180/270 degrees), which permutes its edge labels.
  • Given integers R and C such that R*C == N, determine whether the tiles can be arranged into an R x C grid so that all internal adjacent edges match. (Optionally: also return one valid arrangement of tile IDs and rotations.)
  • Assume N is small enough for backtracking (e.g., N <= 12).
  1. ASCII canvas printer
  • Implement an ASCII drawing engine with a blank canvas of size H x W initialized with spaces.
  • You will receive a list of drawing commands such as:
  • RECT x y width height ch (fill the rectangle with character ch)
  • HLINE x1 x2 y ch (draw a horizontal line)
  • VLINE x y1 y2 ch (draw a vertical line)
  • Later commands overwrite earlier ones.
  • Output the final canvas as H lines of W characters.
  1. Product of array except self
  • Given an integer array nums of length n, return an array out where out[i] equals the product of all nums[j] for j != i.
  • Do not use division.
  • Target O(n) time; extra space should be O(1) besides the output array.
  1. 2048 move simulation
  • Given a 4 x 4 grid of non-negative integers (powers of two or zero) and a direction in {left, right, up, down}:
  • Slide all tiles as far as possible in that direction.
  • Merge equal adjacent tiles once per move (e.g., 2 2 2 0 moving left becomes 4 2 0 0, not 8 0 0 0).
  • Return the updated grid (optionally also return the score gained from merges).