## VMWare Inc Interview Question for Member Technical Staffs

• 1
of 1 vote

Country: India
Interview Type: In-Person

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

Use dictionary where key will be an array item and value would be count and increase count every time you find duplicate. Time complexity would be O(n). I am assuming array is not sorted

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

#include<stdio.h>
#include<conio.h>

int FindDuplicate(int a[],int n)
{
int temp=a;
for(int i=1;i<n;i++)
{
temp=temp^a[i];
}
return temp;

}
void main()
{

int i, n;
int a;
printf("Enter the Number of Elements u want to Enter");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",a[i]);
i=FindDuplicate(a,n);

}

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

What is the space complexity ?
If we know the max number in the array, then we can create an alternate array and use the number as index and keep track of the number of times each number has come.

For example:

``````int main()
{
int arr = { 1, 2, 1,3};
int brr = { 0, 0, 0, 0};
for ( int i = 0 ; i < 4 ; ++i) {
brr[arr[i]]++;
}

for ( int i = 0 ; i <4 ; ++i) {
if ( brr[i] == 2) {
cout << "Duplicate with k entries: " << i << endl;
}
}
return 0;
}``````

Now, Here with value of k = 2, we get the duplicate number as 1.

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

The space complexity asked in question was O(1). Unable to edit the question now

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

if original array contains large numbers with sparse entries then size of new array will be very large, which will be very inefficient and wastage of memory.
e.g. arr = {-12, 100, 3, 9834}
in this case you need an array of size 9834. Moreover one entry is -ve also. so brr[arr[i]] will result in coredump!! or segmentation fault.
A better solution is to use hashing.

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

if original array contains large numbers with sparse entries then size of new array will be very large, which will be very inefficient and wastage of memory.
e.g. arr = {-12, 100, 3, 9834}
in this case you need an array of size 9834. Moreover one entry is -ve also. so brr[arr[i]] will result in coredump!! or segmentation fault.
A better solution is to use hashing.

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

if original array contains large numbers with sparse entries then size of new array will be very large, which will be very inefficient and wastage of memory.
e.g. arr = {-12, 100, 3, 9834}
in this case you need an array of size 9834. Moreover one entry is -ve also. so brr[arr[i]] will result in coredump!! or segmentation fault.
A better solution is to use hashing.

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

//#include<stdio.h>
#include<iostream>
#include <iterator>
#include <map>

using namespace std;

int main()
{
int arr={2,10,11,9,2,4,3,9,12,2};

map<int,int> um;

int count;

map<int,int> :: iterator it;

for (int i = 0 ; i<=9 ; i++)
{
count = 0;
it = um.find(arr[i]);
if(it!=um.end())
{
(*it).second = ((*it).second) + 1;
}
else
um.insert(make_pair(arr[i],++count));

}

map<int,int> :: const_iterator it1;

for(it1 = um.begin();it1!= um.end();it1++)
{
cout<<(*it1).first <<" "<<(*it1).second<<endl;
}

return 0;

}

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

``````#include<iostream>
#include <iterator>
#include <map>

using namespace std;

int main()
{
int arr={2,10,11,9,2,4,3,9,12,2};

map<int,int> um;

int count;

map<int,int> :: iterator it;

for (int i = 0 ; i<=9 ; i++)
{
count = 0;
it = um.find(arr[i]);
if(it!=um.end())
{
(*it).second = ((*it).second) + 1;
}
else
um.insert(make_pair(arr[i],++count));

}

map<int,int> :: const_iterator it1;

for(it1 = um.begin();it1!= um.end();it1++)
{
cout<<(*it1).first <<" "<<(*it1).second<<endl;
}

return 0;

}``````

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

``````private static void dups(int A[]) {

for (int i = 0; i < A.length; i++) {
if (A[i] < 0)
continue;
if (A[Math.abs(A[i])] >= 0) {
A[Math.abs(A[i])] = -A[Math.abs(A[i])];

} else {
System.out.println("Duplicate Number" + Math.abs(A[i]));
}
}

}``````

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

``````private static void dups(int A[]) {

for (int i = 0; i < A.length; i++) {
if (A[i] < 0)
continue;
if (A[Math.abs(A[i])] >= 0) {
A[Math.abs(A[i])] = -A[Math.abs(A[i])];

} else {
System.out.println("Duplicate Number" + Math.abs(A[i]));
}
}``````

}

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

``````private static void dups(int A[]) {

for (int i = 0; i < A.length; i++) {
if (A[i] < 0)
continue;
if (A[Math.abs(A[i])] >= 0) {
A[Math.abs(A[i])] = -A[Math.abs(A[i])];

} else {
System.out.println("Duplicate Number" + Math.abs(A[i]));
}
}

}``````

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

I guess this should solve the problem

``````def deleteDuplicate(text):
delDuplicate = ''
for char in text:
if(char not in delDuplicate):
delDuplicate+= char
print(delDuplicate)

deleteDuplicate('hhha')``````

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

def duplicates(string):
d={}
for i in string:
d[i]=d.get(i,0)+1
for k,v in d.items():
if v>1:
print(k,v)

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.