Morgan Stanley Interview Question for Software Developers


Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

A simple recursive task.
1. If string is single - return its chars as an array
2. if we have N strings - get chars of the first string, for each char of the string combine it with solution of the rest of strings.

Javascript solution:

function solution(strings){
    if (0==strings.length)
        return [];
    var chars = strings[0].split('');
    if (1==strings.length)
        return chars;
    var result = [];
    var rest = strings.slice(1);
    for (var i in chars){
        var sol = solution(rest);
        for (let j in sol)
            result.push(chars[i]+sol[j]);
    }
    return result;
}

- md.xytop May 05, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static ArrayList<String> find(List<String> input, int aI){
ArrayList<String> result = new ArrayList<>();

if(aI == input.size()) return result;

char[] charStr = input.get(aI).toCharArray();

if(aI == input.size()-1){
for(int i=0;i<charStr.length; i++){
result.add(""+charStr[i]);
}
return result;
}

for(int i=0;i<charStr.length; i++){
ArrayList<String> rest = find(input, aI+1);
for(String s : rest){
result.add(charStr[i] + s);
}
}

return result;
}

- Anonymous July 26, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static ArrayList<String> find(List<String> input, int aI){
		ArrayList<String> result = new ArrayList<>();
		
		if(aI == input.size()) return result;
		
		char[] charStr = input.get(aI).toCharArray();
		
		if(aI == input.size()-1){
		    for(int i=0;i<charStr.length; i++){
		        result.add(""+charStr[i]);
		    }
		    return result;
		}
		
		for(int i=0;i<charStr.length; i++){
		    ArrayList<String> rest = find(input, aI+1);
		    for(String s : rest){
		        result.add(charStr[i] + s);
		    }
		}
		
		return result;
	}

- @smurfette July 26, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void func(vector<string> &v,string &temp,int index,vector<string> &res,int n)
{
if(temp.length() == n)
{
res.push_back(temp);
return;
}

for(int i=0;i<n;++i)
{
string str = v[index];
temp.push_back(v[index][i]);
func(v,temp,index+1,res,n);
temp.pop_back();
}
}

int main() {
int n;
cin>>n;
vector<string> v;
for(int i=0;i<n;++i)
{
string temp;
cin>>temp;
v.push_back(temp);
}
string temp;
vector<string> res;
func(v,temp,0,res,n);

for(auto it : res)
cout<<it<<" ";
return 0;
}

- c++ code July 28, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void func(vector<string> &v,string &temp,int index,vector<string> &res,int n)
{
if(temp.length() == n)
{
res.push_back(temp);
return;
}

for(int i=0;i<n;++i)
{
string str = v[index];
temp.push_back(v[index][i]);
func(v,temp,index+1,res,n);
temp.pop_back();
}
}

int main() {
int n;
cin>>n;
vector<string> v;
for(int i=0;i<n;++i)
{
string temp;
cin>>temp;
v.push_back(temp);
}
string temp;
vector<string> res;
func(v,temp,0,res,n);

for(auto it : res)
cout<<it<<" ";
return 0;
}

- c++ code July 28, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void func(vector<string> &v,string &temp,int index,vector<string> &res,int n){
if(temp.length() == n){
res.push_back(temp);
return;
}

for(int i=0;i<n;++i){
string str = v[index];
temp.push_back(v[index][i]);
func(v,temp,index+1,res,n);
temp.pop_back();
}
}

int main() {
int n;
cin>>n;
vector<string> v;
for(int i=0;i<n;++i){
string temp;
cin>>temp;
v.push_back(temp);
}
string temp;
vector<string> res;
func(v,temp,0,res,n);

for(auto it : res)
cout<<it<<" ";
return 0;
}

- c++ code July 28, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void print(vector<string>& s, int i, string str){
        if (str.size() == s.size()){
            cout << str << "\n";
            return;
        }
        for (int j =0; j < s[i].size(); j++){
            str += s[i][j];
            print(s, i+1, str);
            str.pop_back();
        }
    }

- Ajith August 12, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{public class MultipleStringPermutation {

public static void main(String[] args) {
String str[] = {"abc","def","ghi"};
String s = "";
int i = 0, j= 0;
while(j < str[i].length() && j < str.length){
s += str[i].charAt(j);
i++;
if (i == str.length){
j++;
i=0;
//System.out.println(s);
permute(s, 0, s.length()-1);
s = "";
}

}
}
private static void permute(String str, int l, int r)
{
if (l == r)
System.out.println(str);
else
{
for (int i = l; i <= r; i++)
{
str = swap(str,l,i);
permute(str, l+1, r);
str = swap(str,l,i);
}
}
}
public static String swap(String a, int i, int j)
{
char temp;
char[] charArray = a.toCharArray();
temp = charArray[i] ;
charArray[i] = charArray[j];
charArray[j] = temp;
return String.valueOf(charArray);
}
}}

- Anonymous April 25, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class MultipleStirngPermutation {

public static void main(String[] args) {
String str[] = {"abc","def","ghi"};
String s = "";
int i = 0, j= 0;
while(j < str[i].length() && j < str.length){
s += str[i].charAt(j);
i++;
if (i == str.length){
j++;
i=0;
//System.out.println(s);
permute(s, 0, s.length()-1);
s = "";
}
}
}
private static void permute(String str, int l, int r)
{
if (l == r)
System.out.println(str);
else
{
for (int i = l; i <= r; i++)
{
str = swap(str,l,i);
permute(str, l+1, r);
str = swap(str,l,i);
}
}
}
public static String swap(String a, int i, int j)
{
char temp;
char[] charArray = a.toCharArray();
temp = charArray[i] ;
charArray[i] = charArray[j];
charArray[j] = temp;
return String.valueOf(charArray);
}
}

- sTrack April 25, 2020 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More