Sandvine

  www.sandvine.com
Work in HR? Unlock Free Profile

Sandvine Quality Assurance Engineer Interview Question (student candidate)

I interviewed in Toronto, ON (Canada) and was asked:
"Write code to find duplicates in a sorted array and delete them."
Add Tags [?]
Answer

Part of a Quality Assurance Engineer Interview Review - one of 25 Sandvine Interview Reviews

Answers & Comments

0
of 0
votes
// Function to remove the duplicates
int removeDuplicates(int a[], int array_size)
{
  int i, j;

  j = 0;

  // Print old array...
  printf("\n\nOLD : ");
  for(i = 0; i < array_size; i++)
  {
     printf("[%d] ", a[i]);
  }

  // Remove the duplicates ...
  for (i = 1; i < array_size; i++)
  {
    if (a[i] != a[j])
    {
      j++;
      a[j] = a[i]; // Move it to the front
    }
  }

  // The new array size..
  array_size = (j + 1);

  // Print new array...
  printf("\n\nNEW : ");
  for(i = 0; i< array_size; i++)
  {
     printf("[%d] ", a[i]);
  }
  printf("\n\n");

  // Return the new size...
  return(j + 1);
}
- Dominator on Sep 2, 2013

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.