MathWorks
JTPL Interview Questions and Answers
Q1. Car Pooling Capacity Problem
You are a cab driver with a car that initially has 'C' empty seats. The car moves in a straight line towards the forward direction only. Your job is to determine if it is possible t...read more
Determine if it is possible to handle all passenger trips within the car capacity without exceeding it at any point.
Iterate through each trip and keep track of the total number of passengers in the car at each point.
Check if the total number of passengers exceeds the car capacity at any point, return 'False'. Otherwise, return 'True'.
Q2. Convert BST to Greater Sum Tree
Given a Binary Search Tree (BST) of integers, your task is to convert it into a greater sum tree. In the greater sum tree, each node's value should be replaced with the sum of al...read more
Convert a Binary Search Tree into a Greater Sum Tree by replacing each node's value with the sum of all nodes' values greater than the current node's value.
Traverse the BST in reverse inorder (right-root-left) to visit nodes in descending order.
Keep track of the running sum of visited nodes and update each node's value with this sum.
Recursively apply the above steps to all nodes in the BST.
Example: For the input BST [4, 1, 6, 0, 2, 5, 7], the output Greater Sum Tree will be [...read more
Q3. Distance To Nearest 1 in a Binary Matrix Problem
Given a binary matrix MAT
containing only 0s and 1s of size N x M, find the distance of the nearest cell containing 1 for each cell in the matrix.
The distance i...read more
Given a binary matrix, find the distance of the nearest cell containing 1 for each cell in the matrix.
Iterate through the matrix and for each cell, find the nearest cell containing 1 using BFS or DFS.
Calculate the distance using the formula |i1 – i2| + |j1 – j2|.
Update the matrix with the distances to the nearest cell with 1.
Handle edge cases like cells already containing 1 or cells with no 1s nearby.
Ensure movements are only allowed in four directions: Up, Down, Left, and Ri...read more
Q4. K-th Ugly Ninja Problem Statement
Ninja is looking to hire 'ugly ninjas' whose numbers have all prime factors from a given list. Your task is to help him find the K-th ugly ninja.
You will be given an array PRI...read more
Find the K-th ugly ninja number using prime factors from a given list.
Generate ugly numbers using prime factors from PRIME_ARR
Keep track of the K-th ugly number
Return the K-th ugly number
Q5. Optimal Strategy for a Coin Game
You and your friend Ninjax are engaged in a strategic game involving coins. Ninjax arranges 'N' coins in a linear sequence.
The rules of the game are as follows:
1. Each coin ha...read more
Determine the maximum amount you can win in a coin game by selecting coins strategically.
Start by understanding the rules of the game and the goal of maximizing winnings.
Consider the fact that you can choose either the first or last coin in each turn.
Think about how to ensure you make the best choice at each turn to guarantee the maximum win.
Examples: For the input 4 9 5 21 7, selecting coins in the order of 9 and 21 results in a maximum win of 30.
Q6. Count Pairs Divisible by K
You are given an array ARR
and a positive integer K
. Your task is to count the total number of pairs within the array whose sum is divisible by K
.
Example:
Input:
ARR = [4, 3, 5, 1, 4...read more
Count pairs in an array whose sum is divisible by a given integer K.
Iterate through the array and calculate the remainder of each element when divided by K.
Store the remainders in a hashmap along with their frequencies.
For each remainder R, check if K - R is present in the hashmap and add the product of their frequencies to the count.
Return the total count of pairs whose sum is divisible by K.
Q7. Interest in Matlab
I have a strong interest in Matlab due to its powerful data analysis and visualization capabilities.
I have experience using Matlab for data analysis and visualization in my academic projects.
I find Matlab's syntax to be intuitive and easy to learn.
I appreciate Matlab's extensive library of functions for various mathematical and engineering tasks.
Interview Process at JTPL
Top Software Developer Intern Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month