VMWare Inc Interview Question for Member Technical Staffs


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

- Amit August 02, 2015 | Flag Reply
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[0];
for(int i=1;i<n;i++)
{
temp=temp^a[i];
}
return temp;

}
void main()
{

int i, n;
int a[20];
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);

}

- Anonymous August 03, 2015 | Flag Reply
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[4] = { 1, 2, 1,3};
    int brr[4] = { 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.

- deepak.mehta.nitk August 03, 2015 | Flag Reply
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

- saurav.kr.paul August 03, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- TrickyCoder October 11, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- TrickyCoder October 11, 2015 | Flag
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.

- trickyCoder October 11, 2015 | Flag Reply
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[10]={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;

}

- Sumit November 20, 2015 | Flag Reply
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[10]={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;	
	
}

- Sumit November 20, 2015 | Flag Reply
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]));
			}
		}

	}

- sandeep March 17, 2016 | Flag Reply
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]));
			}
		}

}

- sandeep March 17, 2016 | Flag Reply
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]));
			}
		}

	}

- sandy March 17, 2016 | Flag Reply
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')

- bayyah June 23, 2016 | Flag Reply
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)

- Tharakanadha Reddy May 14, 2020 | 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