## CapitalIQ Interview Question for Consultants

• 0

Country: India
Interview Type: Phone Interview

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

Since a hashset maintains uniqueness of elements, why not just add the elements from the array to a hashset, iterate over the hashset and print them? Time complexity: O(n).

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

It was a correct note to use set instead of a map, since we only need to keep track of existing (encountered) values, but not a key-value pair.

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

Just sort the array and then start traversing the array and keep the traversed element in another array..if during traversing you get a condition where arr[i]==arr[i+1] then ignore this value otherwise keep copying the elements.It will time for sorting the array and then traversing which will take O(nlogn).

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

1. consider given array(arr ), other array (Oarr), and a hash Map (HMap<int,int>);
2. key of HMap is element of arr,
3. if ith element of arr has count>0 in HMap, ignore it otherwise store in Oarr.

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

O(n) time complexity.

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

Your steps would miss repeated elements and the in the new array you will have only the unique elements. The purpose is not met.

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

``````map mymap;
int givenarr[n];
int otherarr[n];
j = 0
for i = 0 to n - 1
if not mymap.containskey(givenarr[i])
otherarr[j++] = givenarr[i]
mymap[givenarr[i]] = something
while j < n
otherarr[j++] = Nothing``````

O(nlogn)

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

@coding.arya
Complexities should be as follows
Space: O(m), where m is the number of unique elements from the given input of n
Time: O(n)

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

1. sort the array in ascending order( O(log n) )
2. and simply copy element from given array to another array and keep record of last copied in element in variable. continue this process till the end of array. (O(n))
so total time complexity O(n).

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

@Ganesh
Sorting takes O(n log n).

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.

### 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.