Samsung Interview Question for Network Engineers


Country: India
Interview Type: In-Person




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

I think you should build trie from these strings, so when you go from root to nodes, all strings that would be under current node - will be answers. For better performance you can store all references on all strings each node belongs to. so complexity wiil be O(n), where n - is lenght of input.

- glebstepanov1992 December 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I would go for a map with key={string} value={set}
I am choosing this case assuming i have small number of keys so the map cost will be small for lookup.
also, in any DS like LL, Tr(i)e etc, the cost of storing a pointer is high when data is small.
Trie might end up optimizing this as well, but given there are too many children per node, the ptr cost i think might become high.

- Abhinav May 10, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You should make use of n-ary tree. store characters of the string as node of the n-ary tree. Now make use of DFS as :
say the input is aa -- now to give the suggestions take 2nd 'a' as main node and apply the DFS on it. Print the result of the DFS .

- Zombie December 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please apply Weighted Quick Union Find Algorithm. It will help to distribute the character on the wight. We can decide the way of representation of the string representation and can take the sub tree for the node for which the string matches.

- Somashis Nath January 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*This code Needs some modification anybody who got the logic can try it.. and it does work for "a" and "aa", but doesn't work for input "ac" */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StringChallenge {
    public static void main(String[] args) {
	// TODO Auto-generated method stub

	String[] input = { "aabb", "aafd", "acff", "aacg", "acfg" };
	List<String> lst = new ArrayList<String>();

	for (String str : input) {
	    lst.add(str);
	}

	System.out.println("enter your option: ");
	Scanner in = new Scanner(System.in);
	String expt = in.nextLine();
	char[] inp = expt.toCharArray();
	
	for (int i = 0; i < inp.length; i++) {
	    while (lst.get(i).contains(expt)) {
		System.out.println(lst.get(i) + " ");
		lst.remove(i);
		continue;
	    }
	}
    }
}

- Sudheer Telugu April 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is my code and i'm new to java but not to logics :P .. please check and reply..

- sudheerjay April 10, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;

public class CheckSubString {

public static void main(String[] args) {

String[] str={"aabd","adbd","bfdbd","abcd","absbd"};
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();

for(int i=0;i<str.length;i++){
System.out.println(str[i].substring(0,input.length()));
if(str[i].substring(0,input.length()).equals(input))
System.out.println(str[i]);
else
continue;
}

}

}

- Atul Rai November 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

import java.util.Scanner;

public class CheckSubString {

public static void main(String[] args) {

String[] str={"aabd","adbd","bfdbd","abcd","absbd"};
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();

for(int i=0;i<str.length;i++){
if(str[i].substring(0,input.length()).equals(input))
System.out.println(str[i]);
else
continue;
}

}

}

- Atul rai November 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

just removed the sysOut after the for loop

- Anonymous November 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

package com.example.itext;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;




/**
* Hello world!
*
*/
public class App implements IExample
{
public static void main( String[] args )
{
String[] strArr = {"aBB","aaCC","aBc","aaaVBF","bbaa","bAAA","aaaHHHH","d"};
List<String> strArrayList = new ArrayList<String>();
for(String str:strArr){
strArrayList.add(str);
}
Collections.sort(strArrayList);
String inputString = "d";
StringBuilder strb = new StringBuilder("");
for(String listElm: strArrayList){
if(inputString.charAt(0)== listElm.charAt(0)){
if(listElm.startsWith(inputString))
strb.append(listElm).append(" ");
}else{
continue;
}

}

System.out.println("strb: " + strb);

}

}

- cCAACc December 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi man,

iam getting outpou as d .
\
please check the program

- sandy December 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

public static void findStrings(String[] sa, String str)
	{
		if(sa==null)
			return;
		else
		{
			for(int i=0;i<sa.length;i++)
			{
				if(sa[i].startsWith(str))
					System.out.println(sa[i]);
			}
		}

}

- GReeky March 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

/*here is the code in C*/

#include<stdio.h>
#include<string.h>
int main()
{
int i;
char strin[][10] = {"abc","aab","aacf","gffg","saas","dddd","lkll","dfgfd","dfgdete","aafgdgr"};
char str[5];
printf("Enter the string to be searched\n");
scanf("%s",str);
for(i = 0;i<10;i++){
if(strncmp(strin[i],str,strlen(str)) == 0)
printf("%s\n",strin[i]);
}
return 0;
}

- Mayank Sonakiya December 10, 2013 | 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