Interview Question for Financial Software Developers






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

Use BitSet to solve this issue. Read the given numbers one by one and set the corresponding bit into the BitSet. Before setting this, just check whether bit is already set or not. If yes, print the number.

- Anonymous December 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

do you want to have million bits representing each number?

- compmanic January 21, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

He means that have a single million bit BitSet... and set bits wherever the number fits in the set.... this would work well if the numbers were the first million numbers... 0-1M .... since this is not the case... wed require a mapping function to the BitSet....

- Noob June 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

this will be cool

- aaron liang September 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

I guess using HashSet will do the work for us. Iterate once over provided array to add elements to HashSet and check the return value on every addition. If return value is false, it is duplicate and print it.

This holds good if restriction is not there on space.

- Amit Gupta March 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the range of the numbers in the array is given then following algorithm works

i=1
Repeat while i=n
{

if(a(abs(a[i])>0)
then
a(abs(a[i])=-a(abs(a[i])
else
print a(abs(a[i])
endif
i=i+1
end while


Time Complexity O(n) and Space Complexity O(1)

- Yashwanth October 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I could not understand this program, what is abs(a[i]>0) will do.
Could you please elaborate... !!!

- Piyush Beli October 27, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what do u mean by abs ???? can somebody explain?

- aaron liang September 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Piyush: It is not abs(a[i]>0), it is abs(a[i])>0). abs(a[i]) returns the absolute value of a[i], i.e., if a[i] is 5, it returns 5, if a[i] is -5, it still returns 5.

- Ayushi August 18, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is not abs(a[i]>0) , it is abs(a[i])>0. abs(a[i]) means it gives / returns the absolute value of a[i]. Eg: if a[i] is 5, it returns 5, if a[i] is -5, it returns still 5.

- Ayushi August 18, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Instead of using a HashMap , we can rather use a HashSet. Add the element in HashSet from given array. If add(Object o) method returns false (means element is already there in Set) then print that no.
But the problem with this approach is it's using extra memory.

- Piyush Beli October 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Building of Hashset depends on the efficiency of our hashCode. If a unique hash code is guaranteed for all ur numbers then the complexity of soultion is O(n) which means you have to traverse all the collection before making a Hashset. What if the hash code results in unique hashcode for all elements. Then it will be really worse.

A simple approach can be

prepare a BST with the million integers. while preparing just check if the element exists in BST. this will have a complexity of O(logn). just print the duplicates.

- Rustum November 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

@Rustum:

I agree that BST would be a good choice. But I hope you did not forget that You would traverse your BST for each number... running time O(10^6logn).. or O(nlogn) if I may.

Getting the same hashCode is very rare... and a risk that can be taken with a million numbers. If you know the range of the numbers, and its small, hashTable is a very good way.

However, it is best to ask the interviewer to elaborate on the question. For example, how much extra memory do I have? Do we know the range ? and other such restrictions.

- MS February 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can't we just sort the array, e.g., merge sort? and then scan the array in linear time and find the duplicates?

- AM2501 November 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, I was also thinking same but i don't see ppl going for sorting..Not sure why everybody is talking of hashset and hashmap..I think sorting will be best if in-place solution is being looked for.

- OTR March 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

My answer would be:
add each number from array to the HashSet. If accepted then continue else add it to another HashSet for uniqueness.

- Karthik December 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

First you have to ask the interviewer abt the range of possible values the one million number can have...If he says its ages of ppl...then u can use hash map to count the number of occurrences of 1-100 and then just print them...

- notytony February 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess using HashSet will do the work for us. Iterate once over provided array to add elements to HashSet and check the return value on every addition. If return value is false, it is duplicate and print it.

This holds good if restriction is not there on space.

- Amit Gupta March 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is abs?

- Prabhat November 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

mzlcmldmc,xz

- sahil garg June 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

dgfrghfrh

- Abc August 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Or you could you use a HashTable, if you don't know the bounds.

- Anonymous October 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

millions of numbers? how many memory do you have? even if you use hash set , it should be more simple. when it returns false, that means the number is duplicate.

- aaron liang September 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

i suggested using a hashmap for maintaining a count of the numbers appearing in the array and printing out all the numbers with a count > 1.
but they were looking for sorting the array.

- jango October 26, 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