
Morgan Stanley


10+ Morgan Stanley Software Developer Intern Interview Questions and Answers
Q1. Longest Substring with At Most K Distinct Characters
Given a string S
of length N
and an integer K
, find the length of the longest substring that contains at most K
distinct characters.
Input:
The first line co...read more
Find the length of the longest substring with at most K distinct characters in a given string.
Use a sliding window approach to keep track of the characters and their counts within the window.
Maintain a hashmap to store the characters and their frequencies.
Update the window size and characters count as you iterate through the string.
Return the maximum window size encountered for each test case.
Q2. Split the String Problem Statement
You are given a string str
consisting of N
lowercase alphabets. Your task is to determine if it is possible to divide the string into three non-empty substrings such that one ...read more
Given a string, determine if it can be split into three non-empty substrings where one is a substring of the other two.
Check if any substring of the string is a substring of the other two substrings.
Iterate through all possible splits of the string and check for the condition.
Use two pointers to find all possible substrings efficiently.
Q3. Sorted Linked List to Balanced BST Problem Statement
Given a singly linked list where nodes contain values in increasing order, your task is to convert it into a Balanced Binary Search Tree (BST) using the same...read more
Convert a sorted singly linked list into a Balanced Binary Search Tree (BST) using the same data values.
Create a function to convert the linked list to a BST by finding the middle element as the root and recursively building the left and right subtrees.
Maintain a pointer to the head of the linked list and update it as nodes are processed.
Use level order traversal to output the values of the BST nodes, representing NULL nodes with -1.
Ensure the height difference of the subtree...read more
Q4. Ways To Make Coin Change
Given an infinite supply of coins of varying denominations, determine the total number of ways to make change for a specified value using these coins. If it's not possible to make the c...read more
Implement a function to determine the total number of ways to make change for a specified value using given denominations.
Use dynamic programming to keep track of the number of ways to make change for each value up to the target value.
Iterate through each denomination and update the number of ways to make change for each value based on the current denomination.
Return the total number of ways to make change for the target value.
Example: For N=3, D=[1, 2, 3], V=4, the output sh...read more
Q5. Cycle Detection in a Singly Linked List
Determine if a given singly linked list of integers forms a cycle or not.
A cycle in a linked list occurs when a node's next
points back to a previous node in the list. T...read more
Detect if a singly linked list forms a cycle by checking if a node's next pointer points back to a previous node.
Use Floyd's Cycle Detection Algorithm to determine if there is a cycle in the linked list.
Maintain two pointers, one moving at twice the speed of the other.
If the two pointers meet at any point, there is a cycle in the linked list.
Q6. Pair Sum Problem Statement
You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to find and return a list of all pairs of elements where each sum of a pair equals 'S'.
Note:
Each pa...read more
Find pairs of elements in an array that sum up to a given value, sorted in a specific order.
Iterate through the array and for each element, check if the complement (S - current element) exists in a hash set.
If the complement exists, add the pair to the result list.
Sort the result list based on the criteria mentioned in the problem statement.
Q7. Validate BST Problem Statement
Given a binary tree with N
nodes, determine whether the tree is a Binary Search Tree (BST). If it is a BST, return true
; otherwise, return false
.
A binary search tree (BST) is a b...read more
Validate if a binary tree is a Binary Search Tree (BST) or not.
Check if the left subtree of a node contains only nodes with data less than the node's data.
Check if the right subtree of a node contains only nodes with data greater than the node's data.
Ensure both the left and right subtrees are also binary search trees.
Traverse the tree in an inorder manner and check if the elements are in sorted order.
Recursively validate each node's value against its parent's value range.
Q8. Ninja and Binary String Problem Statement
Ninja has a binary string S
of size N
given by his friend. The task is to determine if it's possible to sort the binary string S
in decreasing order by removing any num...read more
Determine if a binary string can be sorted in decreasing order by removing non-adjacent characters.
Iterate through the binary string and check if it can be sorted in decreasing order by removing non-adjacent characters.
Keep track of the count of '1's and '0's in the string to determine if it can be sorted in decreasing order.
If the count of '1's is greater than the count of '0's, the string can be sorted in decreasing order.
Q9. Find the Duplicate Number Problem Statement
Given an integer array 'ARR' of size 'N' containing numbers from 0 to (N - 2). Each number appears at least once, and there is one number that appears twice. Your tas...read more
Find the duplicate number in an integer array containing numbers from 0 to (N - 2).
Iterate through the array and keep track of the frequency of each number using a hashmap.
Return the number that appears twice in the array.
The duplicate number is always present in the given array.
Designing a system like Facebook involves creating user profiles, news feeds, friend connections, messaging features, and more.
Create user profiles with personal information, photos, and posts
Implement a news feed algorithm to display relevant content to users
Allow users to connect with friends and follow other users
Include messaging features for private communication between users
Implement notifications for likes, comments, and friend requests
Utilize a database to store user...read more
Interview Process at Morgan Stanley Software Developer Intern

Top Software Developer Intern Interview Questions from Similar Companies








Reviews
Interviews
Salaries
Users/Month

