Implement core puzzle/array/grid routines
AsanaSoftware Engineer · OnsiteLast 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):
- Jigsaw assembly (small backtracking)
- You are given
Nsquare 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
RandCsuch thatR*C == N, determine whether the tiles can be arranged into anR x Cgrid so that all internal adjacent edges match. (Optionally: also return one valid arrangement of tile IDs and rotations.) - Assume
Nis small enough for backtracking (e.g.,N <= 12).
- ASCII canvas printer
- Implement an ASCII drawing engine with a blank canvas of size
H x Winitialized with spaces. - You will receive a list of drawing commands such as:
RECT x y width height ch(fill the rectangle with characterch)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
Hlines ofWcharacters.
- Product of array except self
- Given an integer array
numsof lengthn, return an arrayoutwhereout[i]equals the product of allnums[j]forj != i. - Do not use division.
- Target
O(n)time; extra space should beO(1)besides the output array.
- 2048 move simulation
- Given a
4 x 4grid 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 0moving left becomes4 2 0 0, not8 0 0 0). - Return the updated grid (optionally also return the score gained from merges).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.