Ericsson Interview Question for Software Engineer / Developers






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

if the element is only a character from ascii, you can use bitset with size of 255 to remember if it is repeated.

- Anonymous September 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Fairly straightforward O(n) solution:

public String removeDupes(int[] input){
    if(input.length == 0 || input.length == 1) return input;
    int prev = input[0];
    String output = "" + prev;

    for(int i=1; i<input.length; i++){
        int cur = input[i];
        if(prev != cur){
            output += ", " + cur;
            prev = cur;
        }
    }
    return output;
}

- Kyle Kamperschroer September 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Kyle.
The approach will only work if the duplicate elements are always together as mentioned in the example. However it is not explicitly mentioned in the question. So if the sequence can be 111122223333311111 then you will op 1 multiple times. In that case, bitmap/hash can be used.

- ardent.1981 September 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

maybe sorting firstly.

- xiaoc10 September 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hash the Key values to the global array. However we don't need to distinctly has each value here. So overriding the same value wont be an issue.
function (int a[])
{
for (int i=0;i<a.length();i++)
{
int key = a[i]/255; // Assuming the maximum difference in given value to be fully represented by the Ascii table..
global_array[key]=a[i];
}
// Now you can read the global array to get the value distinctly.
}

- Prem September 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void PrintDistinct(int A[], int n )
{
	int i=1, temp = A[0] ;
	printf("\n %d", temp );

	for(; i< n ; i++ )
	{
		if( temp != A[i] )
		{
			temp = A[i] ;
			printf("\n %d",temp );
		}
	}
}

- siva.sai.2020 September 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

one more way is building a max heap or min heap will fix the problem. while inserting we can find out the element is inserted or not, if the value is already present print the value and move to next value.

- DNS September 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes it will work but the complexity will be O(nlogn)

- CareerCup September 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

But the space complexity will be less. correct me if i am wrong.

- Yogendra Singh September 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<stdio.h>
#include<conio.h>

using namespace std;

void main(){
int arr[10],temp[10],i,j,k,n,flag;
cout<<"enter the number of elements: ";
cin>>n;
cout<<"enter the number: ";
for(i=0;i<n;i++)
cin>>arr[i];
temp[0]=arr[0];
k=1;
for(i=1;i<n;i++){
flag=0;
for(j=0;j<k;j++){
if(arr[i]==temp[j]){
flag=1;
break;
}
}
if(flag==0){
temp[k]=arr[i];
k++;
}
}
cout<<"the resultant array is: ";
for(i=0;i<k;i++)
cout<<" "<<temp[i];
_getch();
}

- narender singh September 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If array is sorted... then can be solved in Time Complexity - O(log n) and Space Complexity O(1). Otherwise, use hash maps... Time Complexity O(n) and Space Complexity O(n)...

I am giving solution for the sorted array scenario:-

#include<iostream>
using namespace std;

int rightBinarySearch(int *arr, int start, int end, int prev_mid,int key)
{
	if ( start > end )
		return prev_mid;

	int mid = (end-start)/2 + start;

	if ( arr[mid] == key )
		return rightBinarySearch(arr,mid+1,end,mid,key);
	else if (arr[mid] > key)
		return rightBinarySearch(arr,start,mid-1,prev_mid,key);
	else
		return rightBinarySearch(arr,mid+1,end,prev_mid,key);
}

void Compressor(int* arr, int *len)
{
	if ( !arr || *len < 2 )
		return;
	int i = 0, start = 0, end = *len;
	while( start < end )
	{
		arr[i++] = arr[start];
		start = rightBinarySearch(arr,start,end,start,arr[start]) + 1;
	}
	*len = i;
}

int main()
{
	int arr[] = { 10,11,11,11,11 };
	int len = 5;

	Compressor(arr, &len);

	for ( int i = 0; i<len; i++ )
		cout << arr[i]<<" ";
	return 0;

}

- Sunny_Boy February 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void remove_double (const char *src, char *dst)
{
    const char *tmp_src = src;
    while (*src) {
        if (*src == *++tmp_src)
           src++;
        else {
         *dst++ = *src;
         *dst++ = ',';
         src++;
        }
    }
    *--dst = '\0';
}

int main()
{
    char src[] = "11222222222222222222222222222222222222222222222222222222222222222222222222567888888888888888888888888";
    char dst[128] = {0};

    remove_double(src, dst);
    printf("Data:%s\n", dst);

    return 0;
}

- Hello World November 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can't we do just unique_sort ? or I understood something wrong

- David February 09, 2015 | 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