Morgan Stanley Interview Question


Country: India




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

You just can't.
An array is a contiguous memory segment. So you can't guarantee that a new allocation will return a subsequent memory address.

- Felipe December 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

You can have custom linked list with each element of the link list would be array of specific size . Once the number of elements reached to the size of array, it would add another link list element containing another array.

It will require little complex algorithm to locate the linked list element based on [array_size]%index = linked list element
remainder of above would then be the indexed element inside the array of the linked list element.

It is somewhat similar to tiling in parallel programming.

- viralz December 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Looks good to me! Basically, a page-based memory where memory is allocated in blocks with some blocks pre-allocated to avoid requesting for memory again and again.

In C++, like std::deque.

- nilukush April 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can use standard C library function realloc()

- fReaK December 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote

If realloc was able to make the old block of memory bigger, it returns the same pointer , you Anon.

- fReaK December 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Write code to overload the [] operator and you can literally rewrite the non-older-deletion version of vector in C++.

- gameboy1024 December 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you please elaborate?

- jais.ashish December 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

dynamic array is the solution ...
it allocates all memory contigously in memory keeps count of the current number of elements,if thee space reserved for the dynamic array is exceeded ,it is reallocted and possibly all the before values are copied..but it is an expensive thing

- script7vineel December 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define SIZE 10
struct node
{
 int a[SIZE];
 struct node * next;
};
typedef struct node Node;
class safearay
{
   private:
      Node *list;
   public:
      safearay() 
      {
         list = new Node;
		 list->next = NULL;
      }
      int &operator[](int i)
      {
		if(i == 0)
			return start->a[0];
			
          int temp = i / Size;
		  Node* start = list;
		  while(temp && start != NULL)
		  {
			start = start->next; 
			temp--;
		  }
		  if(temp == 0)
			return start->a[i%SIZE];
		  else
		  {
		    while(temp)
			{
				Node *tempNode = new Node;
				tempNode->next = NULL;
				start->next = tempNode;
				start = tempNode;
				temp--;
			}
			return start->a[i%SIZE];
		  }
      }
};

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

public class ArrayResize {
	
	public static void main(String []args) {
		Object[] originalArray = new Object[5];  
		originalArray[0] = 10;
		originalArray[1] = 20;
		originalArray[2] = 30;
		
		Object[] largerArray = Arrays.copyOf(originalArray, 10);
		largerArray[3] = 10;
		for (int i = 0; i < largerArray.length; i++) {
			System.out.println(largerArray[i]);
		}
	}
}

- Anonymous March 30, 2019 | 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