PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/MathWorks

Decide transform via one-to-one mapping

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of character-to-character mappings in strings, modeling those mappings as directed graphs, detection and handling of cycles, and the ability to construct a sequence of replacements.

  • Medium
  • MathWorks
  • Coding & Algorithms
  • Software Engineer

Decide transform via one-to-one mapping

Company: MathWorks

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

You are given two strings s and t of equal length over the lowercase English alphabet. In one step, you may pick any character x and replace all its occurrences in s with a single character y (the mapping x→y must be applied consistently across the entire string and persists for subsequent steps). Determine whether s can be transformed into t in finitely many steps. If cycles occur in the mapping, you may only break them if there exists at least one spare character not present in t to use as a temporary buffer. Design an algorithm to decide transformability and, if possible, output one valid sequence of replacements.

Quick Answer: This question evaluates understanding of character-to-character mappings in strings, modeling those mappings as directed graphs, detection and handling of cycles, and the ability to construct a sequence of replacements.

Related Interview Questions

  • Minimize shortest path by adding weight-1 edges - MathWorks (easy)
  • Maximize minimum after K decrements - MathWorks (easy)
  • How to maximize rewards with exactly k tasks - MathWorks (easy)
  • Maximize minimum value after k decrements - MathWorks (medium)
  • Determine Whether P's Position Is Unique - MathWorks (medium)
MathWorks logo
MathWorks
Sep 6, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
4
0

You are given two strings s and t of equal length over the lowercase English alphabet. In one step, you may pick any character x and replace all its occurrences in s with a single character y (the mapping x→y must be applied consistently across the entire string and persists for subsequent steps). Determine whether s can be transformed into t in finitely many steps. If cycles occur in the mapping, you may only break them if there exists at least one spare character not present in t to use as a temporary buffer. Design an algorithm to decide transformability and, if possible, output one valid sequence of replacements.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More MathWorks•More Software Engineer•MathWorks Software Engineer•MathWorks Coding & Algorithms•Software Engineer Coding & Algorithms
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.