## xyz Interview Question

abcs**Country:**United States

**Interview Type:**In-Person

O(n):

```
def count_different(input):
if not input:
return 0
front = back = max_length = this_length = 0
running_set = set()
while front < len(input):
if input[front] in running_set:
while True:
back += 1
max_length = max(max_length, this_length)
running_set.remove(input[back - 1])
this_length -= 1
if input[back - 1] == input[front]:
break
running_set.add(input[front])
this_length += 1
front += 1
return max(this_length, max_length)
```

C++ solution..

```
int main(){
int a[]={1,2,2,3,4,5,6,2,3};
int n=sizeof(a)/sizeof(a[0]);
int p=a[0];
for (int i = 0; i < n; ++i)
{ if(a[i]>p)
p=a[i];
}
int d[p];
memset(d,0,p*sizeof(int));
for (int i = 0; i < n; ++i)
{
d[a[i]-1]+=1;
}
int t=0;
for (int i = 0; i < p; ++i)
{
if(d[i]==1)
t++;
}
cout<<t;
```

}

```
import java.util.HashSet;
public class NonRepeatedNum {
public static void main(String args[])
{
HashSet<Integer> realSet = new HashSet<>();
HashSet<Integer> DupeSet = new HashSet<>();
int [] arr = {1, 2, 2, 3, 4, 5, 6, 2, 3};
int [] arrDupe = new int[arr.length-1];
int count = 0;
for(int i =0;i<arr.length;i++)
{
arrDupe[arr[i]]++;
}
for(int i = 0;i< arrDupe.length;i++)
{
if(arrDupe[i] == 1)
{
count++;
}
}
System.out.println(count);
}
}
```

Depending on meaning, either:

or

Both are O(n)

- pasio April 28, 2018