Problem database last updated: June 20, 2025

MMathWorks logo

MathWorks Coding Interview Questions

28 problems · 5 Easy, 12 Medium, 11 Hard · Ranked #72 of 458

Difficulty breakdown

5 Easy

18% · avg 23%

12 Medium

43% · avg 59%

11 Hard

39% · avg 18%

Top topics

array
53.6%
string
35.7%
dynamic-programming
35.7%1.8x
greedy
25%3x
math
21.4%1.7x
binary-search
17.9%2x

Interview profile

Based on 28 reported problems, MathWorks interviews are significantly harder than average - 39% Hard vs 18% across all companies.

Compared to the industry average, MathWorks puts unusual emphasis on bitmask (7.1% of problems, 13.2x the industry average), greedy (25% of problems, 3x the industry average), simulation (10.7% of problems, 2.5x the industry average). If you're short on time, these are the categories to double down on.

The most common topics are array (53.6%), string (35.7%), dynamic-programming (35.7%), greedy (25%). Problems below are sorted by frequency, the ones at the top are asked most often.

All 28 problems

Count Subarrays With Fixed Bounds

Solve

You are given an integer array nums and two integers minK and maxK.

HardVery Likely
arrayqueuesliding-window

Maximum Number of Alloys

Solve

You are the owner of a company that creates alloys using various types of metals. There are n different types of metals available, and you have access to k mach...

MediumVery Likely
arraybinary-search

Sell Diminishing-Valued Colored Balls

Solve

You have an inventory of different colored balls, and there is a customer that wants orders balls of any color.

MediumVery Likely
arraymathbinary-search

Total Cost to Hire K Workers

Solve

You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker.

MediumVery Likely
arraytwo-pointersheap-priority-queue

Reshape the Matrix

Solve

In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data.

EasyVery Likely
arraymatrixsimulation

Keyboard Row

Solve

Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.

EasyVery Likely
arrayhash-tablestring

Earliest Second to Mark Indices II

Solve

You are given two 1-indexed integer arrays, nums and, changeIndices, having lengths n and m, respectively.

HardVery Likely
arraybinary-searchgreedy

Count Anagrams

Solve

You are given a string s containing one or more words. Every consecutive pair of words is separated by a single space ' '.

HardVery Likely
hash-tablemathstring

Minimum Cost Tree From Leaf Values

Solve

Given an array arr of positive integers, consider all binary trees such that:

MediumVery Likely
arraydynamic-programmingstack

Shopping Offers

Solve

In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more differe...

MediumVery Likely
arraydynamic-programmingbacktracking

Binary Tree Cameras

Solve

You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate chil...

HardVery Likely
dynamic-programmingtreedepth-first-search

Last Substring in Lexicographical Order

Solve

Given a string s, return the last substring of s in lexicographical order.

HardVery Likely
two-pointersstring

Maximum Palindromes After Operations

Solve

You are given a 0-indexed string array words having length n and containing 0-indexed strings.

MediumVery Likely
arrayhash-tablestring

Remove Colored Pieces if Both Neighbors are the Same Color

Solve

There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color...

MediumVery Likely
mathstringgreedy

Earliest Second to Mark Indices I

Solve

You are given two 1-indexed integer arrays, nums and, changeIndices, having lengths n and m, respectively.

MediumVery Likely
arraybinary-search

Pass the Pillow

Solve

There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pill...

EasyVery Likely
mathsimulation

String Transformation

Solve

You are given two strings s and t of equal length n. You can perform the following operation on the string s:

HardVery Likely
mathstringdynamic-programming

Minimum Edge Reversals So Every Node Is Reachable

Solve

There is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional.

HardLikely
dynamic-programmingdepth-first-searchbreadth-first-search

Longest String Chain

Solve

You are given an array of words where each word consists of lowercase English letters.

MediumLikely
arrayhash-tabletwo-pointers

Split Array Largest Sum

Solve

Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized.

HardLikely
arraybinary-searchdynamic-programming

Sum of Distances in Tree

Solve

There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.

HardLikely
dynamic-programmingtreedepth-first-search

Convert Binary Number in a Linked List to Integer

Solve

Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary repre...

EasyLikely
linked-listmath

Longest Repeating Character Replacement

Solve

You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform th...

MediumLikely
hash-tablestringsliding-window

Maximum Difference Between Increasing Elements

Solve

Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and...

EasyLikely
array

Beautiful Arrangement

Solve

Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i...

MediumLikely
arraydynamic-programmingbacktracking

Distinct Subsequences

Solve

Given two strings s and t, return the number of distinct subsequences of s which equals t.

HardLikely
stringdynamic-programming

Break a Palindrome

Solve

Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string...

MediumLikely
stringgreedy

Reverse Nodes in k-Group

Solve

Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.

HardLikely
linked-listrecursion

How often are these problems asked?

Frequency scores are based on crowdsourced interview reports. A higher score means the problem has been reported more often in recent MathWorks interviews.

Very Likely

75-100%

Likely

50-74%

Sometimes

25-49%

Rare

0-24%

Preparing for your MathWorks coding interview

MathWorks interviews focus heavily on array, string, dynamic-programming problems. If you're short on time, these are the categories to prioritize. The problems on this page are sorted by frequency, so start from the top and work your way down.

Beyond solving problems, practice explaining your approach. MathWorks interviewers care about your thought process - how you break down a problem, consider edge cases, and evaluate tradeoffs between solutions. A clean O(n) solution you can explain clearly beats an O(log n) solution you can't articulate.

Looking for more companies? Browse all 458 companies in our directory, or sharpen your fundamentals with our free data structure visualizers and AI-powered DSA tutor.

Frequently Asked Questions

What coding problems does MathWorks ask in interviews?add

MathWorks has been reported to ask 28 distinct coding problems. The most common topics are array, string, dynamic-programming. 5 are Easy difficulty, 12 are Medium, and 11 are Hard. Problems are sorted by frequency - the ones at the top are asked most often.

How hard are MathWorks coding interviews?add

Based on 28 reported problems, MathWorks interviews are significantly harder than average - 39% Hard vs 18% across all companies. 43% of questions are Medium difficulty. Focus on the high-frequency Medium problems first, then work through the Hard ones.

How should I prepare for a MathWorks coding interview?add

Start with the highest-frequency problems listed on this page. Focus on the core topics: array, string, dynamic-programming. Practice solving them under time pressure and explaining your approach out loud. Mock interviews with AI can simulate the real experience.

Other companies to explore

Ready to ace your MathWorks interview?

Simulate a real MathWorks coding interview with an AI interviewer. Get a scorecard with specific feedback on your problem-solving, code quality, and communication.

Simulate a MathWorks interview with AIarrow_forward