Mathworks EDG

Posted
4 Oct 2025
367 reads

Summary

I encountered a dynamic programming problem involving XOR subsequences during my Mathworks EDG interview, and this post details the problem and my C++ solution.

How it went

During my interview for the Engineering Development Group (EDG) at Mathworks, I was presented with a challenging coding problem. The core of the problem required me to identify the longest subsequence from a given array where, for any two consecutive elements a and b in the subsequence, their bitwise XOR operation (a ^ b) resulted in a specific target value k. My approach involved recognizing the pattern implied by the XOR condition and applying dynamic programming. I realized that if a ^ b = k, then a ^ k = b. This insight allowed me to efficiently determine the required preceding element for any number in the subsequence. I used a hash map to store the maximum length of subsequences ending at each number, allowing for quick lookups when extending subsequences.

Questions asked (1)

  1. 01

    Longest XOR Subsequence with Target K

    Data Structures & Algorithms · Medium

    Given an array of integers arr and a target integer k, find the length of the longest subsequence such that for any two consecutive elements a and b in the subsequence, a ^ b = k.

    Observation from the problem: "From the question we can observe that.. So, the subsequence is nothing but alternate values.. So, we need to find the pairs of them.. So, Suppose we are at a value x, then ending at x, max length of subsequence can be defined as 1 + dp[x ^ target] ;"

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Mathworks recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

Be the first to share your thoughts and start the discussion!