PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • Medium
  • Instacart
  • Coding & Algorithms
  • Software Engineer

Implement matrix-indexing and expression resolver

Company: Instacart

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

##### 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".

Quick Answer: 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.

You are given a target variable name (e.g., "T3") and a list of assignment strings of the form "Ti=expr". Each variable name is "T" followed by one or more digits. Each expr is one of: (1) an integer (optionally with a leading minus), (2) a single variable name, or (3) a sum/difference of exactly two terms: term "+" term or term "-" term. A term is either an integer (optionally with a leading minus) or a variable name. Whitespace may appear anywhere. Evaluate the numeric value of the target by resolving dependencies. If the dependency graph contains a cycle, return "IMPOSSIBLE". All referenced variables appear on the left-hand side of some assignment and appear at most once on the left-hand side.

Constraints

  • 1 <= len(assignments) <= 10000
  • Variable names match regex ^T\d+$
  • Each variable appears at most once on the left-hand side
  • Right-hand side expression has at most one binary operator (+ or -)
  • Terms are either integers (optionally with a leading minus) or variables
  • All referenced variables are defined in assignments
  • If a cycle exists, return "IMPOSSIBLE"

Hints

  1. Model dependencies as a directed graph and evaluate using DFS with memoization.
  2. Track node states: unvisited, visiting, and visited to detect cycles.
  3. To parse an expression, strip spaces and split on the first '+' or '-' that is not a leading sign.
Last updated: Mar 29, 2026

Loading coding console...

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
  • AI Coding 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.

Related Coding Questions

  • Fix the Broken Search Filter in a Book Catalog API - Instacart (medium)
  • Find Largest Adjacent Stock Price Change - Instacart (medium)
  • Implement an In-Memory File Storage System - Instacart (medium)
  • Decode an encoded string - Instacart (medium)
  • Evaluate an arithmetic expression - Instacart (medium)