Add office photos
Morgan Stanley logo
Employer?
Claim Account for FREE

Morgan Stanley

3.7
based on 1.5k Reviews
Video summary
Filter interviews by
Software Developer Intern
Fresher
Clear (1)

10+ Morgan Stanley Software Developer Intern Interview Questions and Answers

Updated 5 Feb 2024

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
Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow
Morgan Stanley Software Developer Intern Interview Questions and Answers for Freshers
illustration image

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

Ans.

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

Add your answer
right arrow

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

Ans.

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

Add your answer
right arrow
Discover Morgan Stanley interview dos and don'ts from real experiences

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow
Q10. How would you design a system like Facebook?
Ans.

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

Add your answer
right arrow
Contribute & help others!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos

Interview Process at Morgan Stanley Software Developer Intern

based on 1 interviews
Interview experience
4.0
Good
View more
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Software Developer Intern Interview Questions from Similar Companies

View all
Recently Viewed
SALARIES
FIS
LIST OF COMPANIES
Discover companies
Find best workplace
INTERVIEWS
Paytm
10 top interview questions
INTERVIEWS
Flipkart
10 top interview questions
INTERVIEWS
Zepto
10 top interview questions
INTERVIEWS
Oracle
No Interviews
INTERVIEWS
StreamSets
No Interviews
SALARIES
Swan Defence and Heavy Industries
SALARIES
Godrej & Boyce Manufacturing
INTERVIEWS
StreamSets
No Interviews
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
75 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter