Microsoft Interview Question
1,272 Interview Reviews |
Back to all Microsoft Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Development Engineer In Test (SDET) at Microsoft:
find duplicated item from an array, output the duplicated item with their times
See more for this Microsoft Software Development Engineer In Test (SDET) Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (4)
void find_duplicates(char *string)
{
char *duplicate = strdup(string);
int length = strlen(duplicate);
quicksort(duplicate, 0, length - 1);
for (int i = 0; i < length;)
{
int count = 1;
for (i = i + 1; i < length && duplicate[i] == duplicate[i - 1]; i++)
{
count++;
}
if (count > 1)
{
printf("%c: %d\n", duplicate[i - 1], count);
}
}
}
Helpful Answer?
Yes |
No
Inappropriate?
Helpful Answer?
Yes |
No
Inappropriate?
{
int[] ip = { 1, 2, 2, 4, 5, 5, 5, 8, 9, 10, 11,11,11, 11, 12 };
int[] op = new int[ip.Length - 1]; int j = 1, i = 0, k=0;
for (i = 0; i < ip.Length - 1; i++)
{
if (ip[i] == ip[i + 1])
{
j++;
}
else if(j>1)
{
op[k] = ip[i];
op[k+1] = j;
j=1;k=k+2;
}
}
}
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



0 of 0 people found this helpful
by Tim:
void find_duplicates(unsigned short *items, int length)
{
int counts[USHRT_MAX + 1];
memset(counts, 0, sizeof(counts));
for (int i = 0; i < length; i++)
{
counts[items[i]]++;
}
for (unsigned i = 0; i <= USHRT_MAX; i++)
{
if (counts[i] > 1)
{
printf ("%d: %d\n", i, counts[i]);
}
}
}