an array t[100] which contains numbers between 1..99. Return the duplicated value. Try both O(n) and O(n-square).
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 |
What are dynamic data structures?
Is array part of collection framework?
Two linked lists are given, find out the sum of them without altering the linked list?
Can we create a null as a key for a map collection?
Which is better merge or quick sort?
What are the advantage of linked list over array?
How do you make a bubble chart with 3 variables?
What is the time complexity of arraylist and linked list?
What is sequential search? What is the average number of comparisons in a sequential search?
What is the use of threaded binary tree?
Which data structure is used in arraylist?
Explain the term recursive case?