an array t[100] which contains numbers between 1..99. Return the duplicated value. Try both O(n) and O(n-square).



an array t[100] which contains numbers between 1..99. Return the duplicated value. Try both O(n) and..

Answer / Om Hari

In O(n), you can use a hash table or an array to keep track of encountered elements:

```c
#define MAX 100
int arr[MAX]; // array to store the frequencies
int t[100]; // input array

void findDuplicates(int n) {
for (int i = 0; i < n; i++) {
if (arr[t[i]] == 1) {
printf("%d is a duplicate.n", t[i]);
}
arr[t[i]]++; // increment the frequency counter
}
}
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

What are dynamic data structures?

3 Answers  


Is array part of collection framework?

1 Answers  


Two linked lists are given, find out the sum of them without altering the linked list?

1 Answers   Expedia,


Can we create a null as a key for a map collection?

1 Answers  


Which is better merge or quick sort?

1 Answers  


What are the advantage of linked list over array?

1 Answers  


How do you make a bubble chart with 3 variables?

1 Answers  


What is the time complexity of arraylist and linked list?

1 Answers  


What is sequential search? What is the average number of comparisons in a sequential search?

1 Answers  


What is the use of threaded binary tree?

1 Answers  


Which data structure is used in arraylist?

1 Answers  


Explain the term recursive case?

1 Answers  


Categories