Morgan Stanley Interview Question for Software Engineer / Developers






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

calling recursion on a very huge set may result int stack overflow...but in the above case this situation should not arise...

- beginner August 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

To answer second part...if you use recursion, the performance will suffer drastically. Because of so many function calls, stack will be filled fast and even if stack is not overflowed, program will take too much time than iterative method.

- Sumit August 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

arungupta1.blogspot.in/2012/09/print-nn-matrix-in-spiral-order.html

- Arun Kumar Gupta September 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

arungupta1.blogspot.in/2012/09/print-nn-matrix-in-spiral-order.html

- Arun Kumar Gupta September 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>

using namespace std;

int main()
{
    int n=5;
   int matrix[5][5]={{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}};
   for(int i=0;i<5;i++)
   {
      for(int j=0;j<5;j++)
      {
          cout<<matrix[i][j]<<" ";
      }
      cout<<endl;
   }
      
   for(int layer=0;layer<=2;layer++)
   {
       cout<<endl<<"Layer:"<<layer+1<<endl;
       for(int c=layer;c<n-layer;c++)
        cout<<matrix[layer][c]<<" ";
       for(int c=layer+1;c<n-layer;c++)
        cout<<matrix[c][n-layer-1]<<" ";
       for(int c=n-layer-2;c>=layer;c--)
        cout<<matrix[n-layer-1][c]<<" ";
       for(int c=n-layer-2;c>layer;c--)
        cout<<matrix[c][layer]<<" ";
       
   }
   
   return 0;
}

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

#include <iostream>

using namespace std;

#define n 4

int main()
{
   int matrix[n][n]={{1,2,3,4},{6,7,8,9},{11,12,13,14},{16,17,18,19}};
   
    
   for(int layer=0;layer<=int(n/2);layer++)
   {
      cout<<endl<<"Layer:"<<layer+1<<endl;
       for(int c=layer;c<n-layer;c++)
        cout<<matrix[layer][c]<<" ";
       for(int c=layer+1;c<n-layer;c++)
        cout<<matrix[c][n-layer-1]<<" ";
       for(int c=n-layer-2;c>=layer;c--)
        cout<<matrix[n-layer-1][c]<<" ";
       for(int c=n-layer-2;c>layer;c--)
        cout<<matrix[c][layer]<<" ";
       
   }
   
   return 0;
}

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

#include <stdio.h>
#define R 3
#define C 6
 
void spiralPrint(int m, int n, int a[R][C])
{
    int i, k = 0, l = 0;
 
    /*  k - starting row index
        m - ending row index
        l - starting column index
        n - ending column index
        i - iterator
    */
 
    while (k < m && l < n)
    {
        /* Print the first row from the remaining rows */
        for (i = l; i < n; ++i)
        {
            printf("%d ", a[k][i]);
        }
        k++;
 
        /* Print the last column from the remaining columns */
        for (i = k; i < m; ++i)
        {
            printf("%d ", a[i][n-1]);
        }
        n--;
 
        /* Print the last row from the remaining rows */
        if ( k < m)
        {
            for (i = n-1; i >= l; --i)
            {
                printf("%d ", a[m-1][i]);
            }
            m--;
        }
 
        /* Print the first column from the remaining columns */
        if (l < n)
        {
            for (i = m-1; i >= k; --i)
            {
                printf("%d ", a[i][l]);
            }
            l++;    
        }        
    }
}

- Nit January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<iostream>
#include<stdio.h>
using namespace std;

void print(int size,int r,int c)
{
if(r==0)
printf("%2d ",(size*size)-1-c);
else if(c==size-1)
printf("%2d ",size*(size-1)-r);
else
print(size-1,(size-1-r),(size-2-c));

}
int main()
{
int n;
while(cin>>n)
{
for(int r=0;r<n;r++,cout<<endl)
{
for(int c=0;c<n;c++)
{
print(n,r,c);
}
}
}
return 0;
}

- Anonymous October 06, 2011 | 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