## Fuze Interview Question for Senior Software Development Engineers

Country: United States

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

Was there a time complexity requirement or something? Seems like with those limitations doing just a brute force solution seems enough, which I believe is O(n^3)

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

For first example answer should be "noing" not "nothing" as per my understanding. Please correct me if I am wrong.

Second example, there is no match for pre_score and post score, so it is a tie. And multiple substrings of text holding the same score zero. So it should go for first string come lexicographically, so answer should be "a"

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

EXACTLY... this is what I was confused about. When I ran the test through hacker rank for sample case #1 it came back as failed until I hard coded "nothing".

Also agreed with your analysis of the second example. The answer should be a not b.

I think the engineers at Fuze that setup this test made some mistakes.
In the end I got screwed.

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

Case #1: "nothing" is the correct answer because "noing" is not a substring of text "nothing";

Case #2:
Substrings of text are:
ab (preScore = 0, postScore = 0)
a (preScore = 0, postScore = 1)
b (preScore = 1, postScore = 0)

a & b ties, choose b (preScore is higher)

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

As per my understanding here we go for O(n logn) solution in C++

``````#include<iostream>
#include<string>
#include<vector>
#include<regex>

void  tokenize(std::string & text, std::vector<std::string>& text_prefix_tokens, std::vector<std::string>& text_suffix_tokens )
{
std::string text_copy(text);
int length =  text_copy.length();

int i = 1;
while( i <= length )
{
text_prefix_tokens.push_back(text_copy.substr(0, i));
++i;
}

while( length-- )
{
text_suffix_tokens.push_back(text_copy.substr(length));
}
}

std::string findHighestPattern(std::string & pre_text, std::string & post_text, std::string & text)
{
std::vector<std::string> text_prefix_tokens;
std::vector<std::string> text_suffix_tokens;
tokenize(text, text_prefix_tokens, text_suffix_tokens);

std::smatch matches;
int post_text_score = 0;

std::string post_result;
for( auto &x : text_suffix_tokens)
{
std::regex pattern (x+"(.*)");
std::regex_match(post_text,matches,pattern);

if(matches.size() > 0)
{
int post_length = x.length();
if(post_length > post_text_score)
{
post_text_score = post_length;
post_result = x;
}
}
}
int pre_text_score = 0;

std::string pre_result;
for( auto &x : text_prefix_tokens)
{
std::regex pattern ("(.*)"+x);
std::regex_match(pre_text, matches, pattern);

if(matches.size() > 0)
{
int pre_length = x.length();
if(pre_length > pre_text_score)
{
pre_text_score = x.length();
pre_result = x;
}
}
}
std::string result = pre_result + post_result;
if(result.length() == 0)
{
text_suffix_tokens.insert(std::end(text_suffix_tokens), std::begin(text_prefix_tokens), std::end(text_prefix_tokens));
std::sort(std::begin(text_suffix_tokens),std::end(text_suffix_tokens));

result = text_suffix_tokens.at(0);
}
return result;
}

int main()
{
std::string pre_text ("bruno");
std::string text("nothing");
std::string post_text("ingenious");

//std::string pre_text ("b");
//std::string text("ab");
//std::string post_text("a");

std::cout<< findHighestPattern(pre_text,post_text,text) <<"\n";``````

}

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

public class StringManupulation {

public static void main(String []args) throws IOException
{
System.out.println("Text:");

System.out.println("Prefix:");
System.out.println("Suffix:");

String output = "";
int max_prefix_count = 0, prefix_count = 0,
max_suffix_count = 0, suffix_count = 0,
sstr_start = 0, sstr_end = 0,
i=0,j=0;

while(i<text.length())
{
int k=i,start=-1,end=-1;
j=0;prefix_count = 0;

while((k<text.length() && j<prefix.length())
&& (text.charAt(k) != prefix.charAt(j)))
j++;

while((k<text.length() && j<prefix.length())
&& (text.charAt(k) == prefix.charAt(j)))
{
if(start == -1)
start = k;

prefix_count++;
k++; j++;
}

//update prefix index as we get the new string.
if(prefix_count > max_prefix_count)
{
max_prefix_count = prefix_count;
sstr_start = start;
}

k=i;j=0;
suffix_count = 0;

while((k<text.length() && j<suffix.length())
&& (text.charAt(k) != suffix.charAt(j)))
j++;

while((k<text.length() && j<suffix.length())
&& (text.charAt(k) == suffix.charAt(j)))
{
suffix_count++;
k++; j++;
}

end = k;

//update prefix index as we get the new string.
if(suffix_count > max_suffix_count)
{
max_suffix_count = suffix_count;
sstr_end = end;
}
i++;
}
if(sstr_end>sstr_start)
System.out.println("output:"+text.substring(sstr_start, sstr_end));
else
System.out.println("output:"+text.substring(sstr_start));
}
}

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

///public class StringManupulation {

public static void main(String []args) throws IOException
{
System.out.println("Text:");

System.out.println("Prefix:");
System.out.println("Suffix:");

String output = "";
int max_prefix_count = 0, prefix_count = 0,
max_suffix_count = 0, suffix_count = 0,
sstr_start = 0, sstr_end = 0,
i=0,j=0;

while(i<text.length())
{
int k=i,start=-1,end=-1;
j=0;prefix_count = 0;

while((k<text.length() && j<prefix.length())
&& (text.charAt(k) != prefix.charAt(j)))
j++;

while((k<text.length() && j<prefix.length())
&& (text.charAt(k) == prefix.charAt(j)))
{
if(start == -1)
start = k;

prefix_count++;
k++; j++;
}

//update prefix index as we get the new string.
if(prefix_count > max_prefix_count)
{
max_prefix_count = prefix_count;
sstr_start = start;
}

k=i;j=0;
suffix_count = 0;

while((k<text.length() && j<suffix.length())
&& (text.charAt(k) != suffix.charAt(j)))
j++;

while((k<text.length() && j<suffix.length())
&& (text.charAt(k) == suffix.charAt(j)))
{
suffix_count++;
k++; j++;
}

end = k;

//update prefix index as we get the new string.
if(suffix_count > max_suffix_count)
{
max_suffix_count = suffix_count;
sstr_end = end;
}
i++;
}
if(sstr_end>sstr_start)
System.out.println("output:"+text.substring(sstr_start, sstr_end));
else
System.out.println("output:"+text.substring(sstr_start));
}
}\\\

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

``````public class StringManupulation {

public static void main(String []args) throws IOException
{
System.out.println("Text:");

System.out.println("Prefix:");
System.out.println("Suffix:");

String output = "";
int max_prefix_count = 0, prefix_count = 0,
max_suffix_count = 0, suffix_count = 0,
sstr_start = 0, sstr_end = 0,
i=0,j=0;

while(i<text.length())
{
int k=i,start=-1,end=-1;
j=0;prefix_count = 0;

while((k<text.length() && j<prefix.length())
&& (text.charAt(k) != prefix.charAt(j)))
j++;

while((k<text.length() && j<prefix.length())
&& (text.charAt(k) == prefix.charAt(j)))
{
if(start == -1)
start = k;

prefix_count++;
k++; j++;
}

//update prefix index as we get the new string.
if(prefix_count > max_prefix_count)
{
max_prefix_count = prefix_count;
sstr_start = start;
}

k=i;j=0;
suffix_count = 0;

while((k<text.length() && j<suffix.length())
&& (text.charAt(k) != suffix.charAt(j)))
j++;

while((k<text.length() && j<suffix.length())
&& (text.charAt(k) == suffix.charAt(j)))
{
suffix_count++;
k++; j++;
}

end = k;

//update prefix index as we get the new string.
if(suffix_count > max_suffix_count)
{
max_suffix_count = suffix_count;
sstr_end = end;
}
i++;
}
if(sstr_end>sstr_start)
System.out.println("output:"+text.substring(sstr_start, sstr_end));
else
System.out.println("output:"+text.substring(sstr_start));
}``````

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

``````BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Text:");

System.out.println("Prefix:");
System.out.println("Suffix:");

String output = "";
int max_prefix_count = 0, prefix_count = 0,
max_suffix_count = 0, suffix_count = 0,
sstr_start = 0, sstr_end = 0,
i=0,j=0;

while(i<text.length())
{
int k=i,start=-1,end=-1;
j=0;prefix_count = 0;

while((k<text.length() && j<prefix.length())
&& (text.charAt(k) != prefix.charAt(j)))
j++;

while((k<text.length() && j<prefix.length())
&& (text.charAt(k) == prefix.charAt(j)))
{
if(start == -1)
start = k;

prefix_count++;
k++; j++;
}

//update prefix index as we get the new string.
if(prefix_count > max_prefix_count)
{
max_prefix_count = prefix_count;
sstr_start = start;
}

k=i;j=0;
suffix_count = 0;

while((k<text.length() && j<suffix.length())
&& (text.charAt(k) != suffix.charAt(j)))
j++;

while((k<text.length() && j<suffix.length())
&& (text.charAt(k) == suffix.charAt(j)))
{
suffix_count++;
k++; j++;
}

end = k;

//update prefix index as we get the new string.
if(suffix_count > max_suffix_count)
{
max_suffix_count = suffix_count;
sstr_end = end;
}
i++;
}
if(sstr_end>sstr_start)
System.out.println("output:"+text.substring(sstr_start, sstr_end));
else
System.out.println("output:"+text.substring(sstr_start));``````

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

``````static String calculateScore(String text, String prefix, String suffix) {

int n = text.length();
int sl = suffix.length();
int pl = prefix.length();

Map<String, Integer> map = new HashMap<>();

for(int i =0; i<n; i++) {
for(int j = i+1; j<=n; j++) {

String sub = text.substring(i,j);

int ps = 0, ss = 0, subL = sub.length();

for(int k =0; k < subL; k++) {
if(subL - k <= sl) {
if(sub.substring(k).equals(suffix.substring(0,subL-k))) {
ps = Math.max(subL-k, ps);
}
}
}

for(int k =0; k < subL; k++) {
if(k < pl) {
if(sub.substring(0,k+1).equals(prefix.substring(pl-k-1, pl))) {
ss = Math.max(k+1,ss);
}
}
}

if(map.get(sub)==null) {
map.put(sub, ps+ss);
} else {
map.put(sub, Math.max(map.get(sub), ps+ss));
}
}
}
int m = -1;
Set<String> keys = map.keySet();

String[] arr = keys.toArray(new String[keys.size()]);

Arrays.sort(arr);
String ans = null;
for(int i = 0; i<arr.length; i++) {
if(m < map.get(arr[i])) {
ans = arr[i];
m = map.get(arr[i]);
}
}

return ans;
}``````

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

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.