Samsung Interview Question for Senior Software Development Engineers


Country: United States
Interview Type: In-Person




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

Can be done in 2 ways:
1) Brute Force using 2 loops.
O(N^2) Runtime.
2) Using HashMap to remember the char already present.
O(N) Runtime with Constant Space

char * removeDuplicateChars( char *str ){
 
	char *itr, *src;	 
	itr = str;
	src = str;
	 
	int hashMap[MAX_CHARS];
	for(int i = 0; i < MAX_CHARS; i++) 
		hashMap[i] = 0;
	 
	while( *itr != '\0' ){
		if( hashMap[*itr] == 0 ){
			hashMap[*itr]++;
			*src = *itr;
			src++;
			itr++;
		}	
		else{
			itr++;
		}
	}
	
	if( NULL != src )
		*src = '\0';
		
	return str;
}

- R@M3$H.N September 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the space isnt constant, its O(n) in both cases

- Anonymous September 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its just a sorting of array...simple..O(nlongn)

- mBk November 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Program
{
static void Main(string[] args)
{
char[] ch = Console.ReadLine().ToCharArray();
for(int i=0;i<ch.Length;i++)
{
if(ch[i]=='~')
{
continue;
}
for(int j=i+1;j<ch.Length;j++)
{
if(ch[i]==ch[j])
{
ch[j] = '~'; // Ssave any special char
}
}
}
for(int j=0;j<ch.Length;j++)
{
if(ch[j]=='~')
{
continue;
}
Console.Write(ch[j]);
}
}
}

- Mrityunjay June 24, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void removeDuplicates(String[] arr){

Set<String> hs = new HashSet<String>();

for(int i=0;i<arr.length;i++){
hs.add(arr[i]);
}
int i = 0;
for(string s : hs){
arr[i] = s;
i++;
}

for(int j = i; j<arr.length; j++){
arr[i] = null;
}

}

- shubhankar singh August 02, 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