MathWorks Online Assessment
- Posted
- 5 Nov 2026
Summary
I took the MathWorks online assessment, which consisted of three algorithmic problems ranging from medium to hard difficulty.
How it went
I recently appeared for the MathWorks Online Assessment (OA). From what I observed, participants received different sets of questions, and the difficulty level varied considerably across candidates.
I found the first two problems to be in the Medium range (considering LeetCode difficulty levels), whereas the third problem was considerably more challenging. Interestingly, I later found that the third problem, or a very similar variant, had appeared in previous online assessments, interviews, and competitive programming contests, particularly on Codeforces.
Here is a brief description of the three problems I encountered:
1. Minimum Cost to Traverse a Ring
We are given an array cost, where cost[i] represents the cost of moving from element i to either of its adjacent elements (clockwise or anticlockwise).
The elements are arranged in a circular manner, meaning the first and last elements are also adjacent.
We are also given an array of requests specifying the elements we need to visit. Initially, we are positioned at element 1, and we can move either clockwise or anticlockwise.
The objective is to determine the minimum total cost required to fulfil all the requests in the given order.
Constraints:
- Number of elements: approximately 2000.
- Number of requests: up to 10^5.
2. Minimum Time to Schedule a Meeting
We are given an array of strings representing people's schedules. Each string follows a format similar to:
"Alex work 01:00 13:30"
This indicates that Alex is busy with work from 01:00 to 13:30 (both endpoints inclusive).
There can be multiple entries for the same person, representing different busy intervals. There can also be entries corresponding to other people.
We are additionally given an integer k, representing the required duration of the meeting.
The objective is to find the earliest possible starting time at which the meeting can be scheduled such that:
- Everyone is available throughout the meeting.
- The meeting duration is exactly k.
- The meeting must start and finish on the same day.
If no valid time slot exists, return -1.
Constraints:
- Number of schedule entries: up to 10^5.
3. Minimum Diameter of a Tree After Removing Exactly K Nodes
We are given a tree with n nodes, numbered from 0 to n-1, an integer k, and an array of edges representing the tree.
We need to minimize the diameter of the resulting tree by removing exactly k leaf nodes.
An important detail is that after removing a leaf node, its parent may become a leaf itself and can subsequently be removed. Thus, the removal process can continue iteratively.
The objective is to determine the minimum possible diameter after exactly k such removals.
Constraints:
- number of nodes: up to 2000. (1e5 is really tough, you can check this post: https://codeforces.com/blog/entry/143297)
Questions asked (3)
- 01
Minimum Cost to Traverse a Ring
Data Structures & Algorithms · Medium
Given an array
costwherecost[i]is the cost to move from elementito either adjacent element (clockwise or anticlockwise) in a circular arrangement. You are also given an array of requests specifying the elements to visit in order. Starting at element1, you may move clockwise or anticlockwise. Find the minimum total cost required to fulfill all requests in the given order.Constraints:
- Number of elements: up to ~2000.
- Number of requests: up to 10^5. - 02
Minimum Time to Schedule a Meeting
Data Structures & Algorithms · Medium
Given an array of strings representing people's busy intervals in the format "Name activity startTime endTime" (e.g., "Alex work 01:00 13:30"), and an integer
krepresenting the required meeting duration, determine the earliest possible start time for a meeting of exactlykminutes such that all participants are free, the meeting starts and ends on the same day, and if no slot exists return-1.Constraints:
- Number of schedule entries: up to 10^5. - 03
Minimum Diameter of a Tree After Removing Exactly K Nodes
Data Structures & Algorithms · Hard
Given a tree with
nnodes (0-indexed), an integerk, and the list of edges, remove exactlykleaf nodes (removing a leaf may turn its parent into a leaf, which can then be removed) to minimize the diameter of the remaining tree. Return the minimum possible diameter after the removals.Constraints:
- Number of nodes: up to 2000.