## Cisco Systems Interview Question for Software Engineers

Country: India
Interview Type: Written Test

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

``````for( int i = a.length-1, j = b.length-1; i >= 0 && j >= 0 && a[i] == b[j]; i--;j--);

if ( i < a.length-1 ) return a.substring(++i);
return "";``````

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

``````- O(n^2)
- Given s1 and s2
- For each substring(i, s2.length) check if substring is in s1
- if so print substring

- O(n) #on average
- Given s1 and s2
- Create suffix hash of s1
- Ex: s1 = 'abc'
- suffix hash = { 'a': 'a', 'abc' : 'abc': 'b': 'b', 'bc': 'bc': 'c': 'c' }
- For each suffix in s2, check hash if exist print``````

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

``````s1.reverse();
s2.reverse();
for (int i = 0; i < s1.length()&&s2.length(); i++) {
if (s1[i] == s2[i]) {
System.out.println(s1[i]);
}
else {
break;
}
}``````

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

An update to the above code ::

``````s1.reverse();
s2.reverse();
string s;
for (int i = 0; i < s1.length()&&s2.length(); i++) {
if (s1[i] == s2[i]) {
s+=s1[i];
}
else {
break;
}
}
s.reverse();
cout<<s;``````

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

``````//C++ Code
for( int i = a.length()-1, j = b.length()-1; i >= 0 && j >= 0 && a[i] == b[j]; i--;j--);
if ( i < a.length()-1 ) return a.substr(i);
else
return "";``````

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

``````std::string findCommonSuffix(std::string s1, std::string s2)
{
int i, j;
for(i = s1.size()-1, j = s2.size()-1 ; i >= 0 && j >= 0; --i, --j)
{
if(s1[i] != s2[j]) break;
if(i == 0 || j == 0) break;
}
std::string result;
if(i == 0)
result = s1;
else if(j == 0)
result = s2;
else
result = s1.substr(i+1, s1.size() - i);
return result;
}``````

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

String s1 = "cornfiled";
String s2 = "Exfiled";
String suffix;

if ( s1.length() > s2.length()){
suffix = searchSuffix(s1, s2);
}else{
suffix = searchSuffix(s2, s1);
}

System.out.println("Matching suffix is :" + suffix);
}

static String searchSuffix(String searchString, String searchInString){

String sbSearch = null;
for (int i=0; i<searchString.length(); i++){
sbSearch = searchString.substring(i);
System.out.println("sbSearch :" + sbSearch);
if(searchInString.contains(sbSearch)){
return sbSearch;
}
}

return null;
}

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

public static void main(String[] args){

String s1 = "cornfiled";
String s2 = "Exfiled";
String suffix;

if ( s1.length() > s2.length()){
suffix = searchSuffix(s1, s2);
}else{
suffix = searchSuffix(s2, s1);
}

System.out.println("Matching suffix is :" + suffix);
}

static String searchSuffix(String searchString, String searchInString){

String sbSearch = null;
for (int i=0; i<searchString.length(); i++){
sbSearch = searchString.substring(i);
System.out.println("sbSearch :" + sbSearch);
if(searchInString.contains(sbSearch)){
return sbSearch;
}
}

return null;
}

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

``````String[] words = {"cornfiled", "Exfiled", "eled"};
Stream.of(words)
.sorted(Comparator.reverseOrder())
.reduce((r, l) ->
{
String suff = "";
for (int i = r.length() - 2; i >= 0; i--) {
String temp = r.substring(i);
if (!l.endsWith(temp)) {
break;
}
suff = temp;
}
return suff;

}).ifPresent(System.out::println);``````

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

``````String[] words = {"cornfiled", "Exfiled", "eled"};
Stream.of(words)
.sorted(Comparator.reverseOrder())
.reduce((r, l) ->
{
String suff = "";
for (int i = r.length() - 2; i >= 0; i--) {
String temp = r.substring(i);
if (!l.endsWith(temp)) {
break;
}
suff = temp;
}
return suff;

}).ifPresent(System.out::println);``````

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

``````public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int temp;
try{
System.out.println("enter string 1:");
String str1=sc.nextLine();
System.out.println("enter string 2:");
String str2=sc.nextLine();
if(str1.length()>str2.length())
{
if(str1.contains(str2)){
temp=str1.indexOf(str2);
System.out.print(str1.substring(temp));
}
}
else
{
if(str2.contains(str1)){
temp=str2.indexOf(str1);
System.out.print(str2.substring(temp));
}
}
}
catch(Exception e){
System.err.print(e);
}

}``````

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

``````def commonSufix(str1, str2):

i1 = len(str1)-1
i2 = len(str2)-1

while i1 >= 0 and i2 >= 0 and str1[i1] == str2[i2]:
i1 -= 1
i2 -= 1
return str1[i1+1:]``````

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

``````def longest_common_suffix(arr)
suffix = arr[0]
i = 0

while i < arr.length
temp = 0
until suffix.nil? || arr[i].end_with?(suffix)
temp += 1
suffix = suffix[temp, suffix.length]
end

i += 1
end

suffix
end

input = ['bakersfield', 'intensefield', 'vfield']
puts longest_common_suffix(input)``````

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.