PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Statistics & Math/MathWorks

Deduce position from logic clues

Last updated: Mar 29, 2026

Quick Overview

This question evaluates the ability to model and reason about constraint-satisfaction on a 2D grid, including logical inference with directional and adjacency relations, combinatorial placement constraints, and determination of uniqueness.

  • hard
  • MathWorks
  • Statistics & Math
  • Software Engineer

Deduce position from logic clues

Company: MathWorks

Role: Software Engineer

Category: Statistics & Math

Difficulty: hard

Interview Round: Take-home Project

You are given a set of locations L laid out on a 2D grid (rows and columns) and a list of relational clues of the forms: ( 1) X is north/south/east/west of Y; ( 2) X is adjacent/not-adjacent to Y; ( 3) X cannot be in row r or column c; ( 4) Exactly one of {A, B, C} is adjacent to D. Assume the clues are consistent and determine the unique location (row, column) of a target person P or report that no unique solution exists. Design an algorithm to solve this constraint-satisfaction problem, describe the data structures you will use, analyze time/space complexity, and provide pseudocode.

Quick Answer: This question evaluates the ability to model and reason about constraint-satisfaction on a 2D grid, including logical inference with directional and adjacency relations, combinatorial placement constraints, and determination of uniqueness.

Related Interview Questions

  • Compute probability of drawing reds - MathWorks (easy)
  • Compute urn-draw probabilities and expectations - MathWorks (easy)
  • Deduce row order from logic clues - MathWorks (easy)
  • Calculate tiered cost and break-even - MathWorks (medium)
MathWorks logo
MathWorks
Sep 6, 2025, 12:00 AM
Software Engineer
Take-home Project
Statistics & Math
3
0

Constraint-Satisfaction on a 2D Grid with Relational Clues

Context

You are given a rectangular grid with R rows and C columns. A set of named entities (people) must each occupy exactly one distinct grid cell. A set of relational clues constrain where entities may be placed. Your goal is to determine whether the location (row, column) of a particular target person P is uniquely determined by the clues. If so, return that unique location; otherwise report that no unique solution exists.

Assumptions and definitions:

  • Rows are indexed 1..R (1 is the northernmost/top row) and columns 1..C (1 is the westernmost/left column).
  • A cell is identified by (r, c).
  • Adjacency means 4-neighborhood: two cells are adjacent if their Manhattan distance is 1 (i.e., share a side).
  • Directional relation "X is north of Y" means same column and row(X) < row(Y); similarly for south (>), east (same row, col(X) > col(Y)), west (<).
  • All entities occupy distinct cells unless otherwise stated.

Clue Types

You may receive any combination of the following clues:

  1. Directional: X is north/south/east/west of Y
  2. Adjacency: X is adjacent/not-adjacent to Y
  3. Unary bans: X cannot be in row r or column c
  4. Exactly-one adjacency: Exactly one of {A, B, C} is adjacent to D

Clues are guaranteed to be mutually consistent (at least one full placement exists), but may or may not uniquely determine P's location.

Task

Design an algorithm to:

  • Determine the unique location (row, column) of target P if implied by the clues; otherwise report that no unique solution exists.
  • Describe data structures you will use.
  • Analyze time and space complexity.
  • Provide clear pseudocode.

Input (conceptual): R, C; set of entities E; target P ∈ E; list of clues of the types above.

Output: Either the unique (row, column) for P, or a statement that P is not uniquely determined.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Statistics & Math•More MathWorks•More Software Engineer•MathWorks Software Engineer•MathWorks Statistics & Math•Software Engineer Statistics & Math
PracHub

Master your tech interviews with 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.