Question:-

Find the longest

sub array which consists of numbers that can be arranged in a continuous sequence.

For ex- {4,5,1,5,7,6,8,4,1}

output-{5,7,6,8,4}.

The main problem here is that array contains duplicates also, i know the solution of doing the same problem in case of distinct elements only, Please help me if anybody knows

for distinct below code will work no problem,but what about in case of duplicates?

```
for(int i=0;i<n;i++) {
hash[a[i]]=true;
for(int j=i+1;j<n;j++) {
if(hash[a[j]]) break;
hash[a[j]] = true;
if(max_val[i][j] - min_val[i][j] = abs(i-j)) {
if(abs(i-j) < best)
best = abs(i-j);
}
}
memset(hash,0,sizeof(hash));
}
```