Implement matrix-indexing and expression resolver
InstacartSoftware Engineer · OnsiteLast updated
This question evaluates a candidate's ability to parse structured text files, perform matrix indexing with a nonstandard origin convention, reconstruct data across multiple blocks, and resolve symbolic variable expressions and dependencies for arithmetic evaluation in the Coding & Algorithms domain.
Question
Given a text file path whose contents include a single block starting with a line like "[2,4]" followed by rows of equal-length characters (e.g., "S3KDA4" … "RTRYYU"), write code to return the character(s) at each coordinate pair, where [0,0] is the bottom-left character of the block. Follow-up 1 (multiple blocks): each block starts with an integer giving the character’s index in a password, then the "[row,col]" header and the character matrix. Return the reconstructed password across all blocks (e.g., blocks for indices 1 and 0 should output "XK"). Follow-up 2 (multiple passwords): continue reading blocks until an index value repeats; the repeat marks the start of a new password. Return the first complete password only. Expression evaluation: Given a target variable computeExp (e.g., T 3) and a list of assignments such as T1=1, T2=2, T3=T4, T4=T5, T5=T2, compute the numeric value of computeExp by resolving dependencies. Follow-up 1: An assignment may contain exactly one + or – (e.g., T3=T4+T 5). Handle integer arithmetic with one operator. Follow-up 2: If the dependency graph contains a cycle (e.g., T4 depends on T5 and T5 depends on T 4), return "IMPOSSIBLE".
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.