Bloomberg LP Interview Question for Software Engineer / Developers






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

use a link list with each node having an array of type int of some predefined size SIZE. create more and more nodes in link list as the data is read from the file. the last node can have the array partially filled so you will have to count either the total elements read from the file or total valid elements in the array contained in last node.

something like:

#define SIZE 1<<4
typedef struct node_ { 
    struct node* next;
    int elements[SIZE];
   }node;

class DataContainer {   //LinkList
    node * m_pHead;
    int m_nTotalElementsContained;
public:
    void InsertElement(int nValue);
    void getValueAtIndex(int nIndex);
};

Here we have used m_nTotalElementsContained which tells total number of elements. We could also have used m_nTotalElementsContainedInLastArray, which will hold the number of elements in the last node's Array. The total elements in that case could have been calculated by

SIZE*(number of nodes -1) + m_nTotalElementsContainedInLastArray

both having their advantages. Compared to a link list node having a single value rather than array, it saves (TotalElements - (TotalElements / SIZE))*sizeof(int*) number of bytes of memory.

Let us say TotalElements = 1000, SIZE=10, thus it becomes (1000 - 1000/10) * (4) for 32 bit OS
900*4=3600. Thus 3600 bytes are saved for 1000 elements compared to a linklist having 1 value rather than array.

- abhityagi85 October 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Proof that interviewers can be morons too.

- Anonymous May 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1st pass count number of lines
create fixed array
2nd pass fill the array with data

- Anonymous May 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Maybe He was giving you a hint that vectors use the structure of arrays?

- chenming831@gmail.com May 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

using 'shrink to fit' vector<int>(ivec).swap(ivec)

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

may be first calculate size of file; initialize vector size according to file size and assuming some format of numerical data; this will optimize vector size to some extent

- david June 05, 2010 | 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