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.

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

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.

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 .

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.

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) {
}

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

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

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

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) {

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

}

}

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

import java.util.Scanner;

public class CheckSubString {

public static void main(String[] args) {

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

}

}

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

just removed the sysOut after the for loop

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

}

}

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

Hi man,

iam getting outpou as d .
\

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

}

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

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.