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
        running_set.add(input[front])
        this_length += 1
        front += 1
    return max(this_length, max_length)

Both are O(n)

- pasio April 28, 2018 | Flag Reply
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
        running_set.add(input[front])
        this_length += 1
        front += 1
    return max(this_length, max_length)

- noammohr April 28, 2018 | Flag Reply
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;

}

- bipinkumar April 29, 2018 | Flag Reply
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());
	}

- Anonymous May 08, 2018 | Flag Reply
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());
	}

- Sujay May 08, 2018 | Flag Reply
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.add(x);
	}
	set.size();
}

- Code September 13, 2018 | Flag Reply
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);
	}

}

- TonyStark September 23, 2018 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More