Deshaw Inc Interview Question for Software Engineer / Developers






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

----------------------------Start of Pseudocode---------------------------------------------------
b=string of bits
u=integer
D=suitable data structure (hashtable will be a good idea)
where element=(key,value)
value=(occurance counter- OC of key, pairing counter PC of key)

for each number b in file
{
u=binary string to int(b)
if( compliment(u) exits in D AND OC(u) >0 )
{
OC(compliment(u))=OC(compliment(u))-1
PC(compliment(u))=PC(compliment(u))+1
}
else
{
if (u exists in D)
{
OC(u)=OC(u)+1
}
else
{
D.add(u,1,0) // 1=OC 0=PC
}
}

}

//Scan through the Data Structure D to generate pairing information
----------------------------End of Pseudocode---------------------------------------------------
Runtime = O(nk) where n=number of binary numbers, k=number of bits in each number.

- kg January 15, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Instead of storing the counters for each pair, you can save precious memory by writing out the pair of complements to a file as you encounter it. Why keep a count for pairs?

If repetitions of pairs are to be avoided, we don't even need the occurrence counters, instead just use 2 bit to store whether u has occurred or not, and has been used in a pair, and output the pair if u occurs, and hasnt been used in a pair yet

- Matchless February 21, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The above solution works fine, when size of numbers is small and all numbers can be loaded into RAM in one go. The data structure will be in the RAM and it requires to hold all the numbers.
The term “millions of 30 bit binary numbers” gives a notion that all the numbers can’t be accommodated in RAM in one go and hence we need a better solution for this. B-tree data structures are used for secondary storage but not sure if they will be useful in this case.

- kg February 16, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Given that it is millions of data, let's assume that all data is in disk.

Sort the numbers in this fashion, (Assume memory available is M) -
1. Create M sorted sublists by bringing M chunk of data, sorting them in memory and writing them back to disk.
2. Merge sorted sublists by populating M memory buffers by the first element of each sublist in disk. Finding the smallest number of all and write it back to disk. Re-populate a memory buffer from its list if it get empty.

Once we have it all sorted, then the problem remains trivial.

1. Start a pointer from head and another from tail.
2. Repeatedly run the head pointer downwards and tail upwards looking for complements.
3. When head & tail meets, finish the program.

- Anonymous February 01, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What is significance of 30 bits here ? Why not normally available e.g. 16 / 32 bit ? I am just trying to find out if it ( 30 bit ) causes any issue ...
Any comment on the complexity of the file ?

- Time Pass ! February 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I mean complexity of whole algorithm ...

- Time Pass ! February 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

cant we use tries to store all different binary numbers. Tries will take less memory to store all numbers and meanwhile searching for a numbers complement can be done in o(30) constant time.

- Rohit July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sounds like a good idea.

For every new element check the number and its compliment in trie. Great idea.

- tihor January 26, 2015 | Flag


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