## xyz Interview Question for abcs

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
0
of 0 vote

Depending on meaning, either:

``````def count_different(input):
return len(set(input))``````

or

``````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
this_length += 1
front += 1
return max(this_length, max_length)``````

Both are O(n)

Comment hidden because of low score. Click to expand.
0
of 0 vote

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
this_length += 1
front += 1
return max(this_length, max_length)``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

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;``````

}

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````private static void usingString(int[] array) {
String str = "";
for (int i = 0; i < array.length; i++) {
String temp = String.valueOf(array[i]);
if (!str.contains(temp)) {
str = str + temp;
}
}
System.out.println(str.length());
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````private static void usingString(int[] array) {
String str = "";
for (int i = 0; i < array.length; i++) {
String temp = String.valueOf(array[i]);
if (!str.contains(temp)) {
str = str + temp;
}
}
System.out.println(str.length());
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public static int distinctArray(int arr[]){
HashSet<Integer> set=new HashSet<>();
for(int x:arr){
}
set.size();
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````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);
}

}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````def countUnique(arr):
n=len(arr)
d={}
for i in range(len(arr)):
if arr[i] not in d:
d[arr[i]]=1
else:
d[arr[i]]+=1
count=0
for x in d:
if d[x]==1:
count+=1
return count``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.