## Google Interview Question for Backend Developers

Country: United States

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

``````//assuming overlapping Strings are allowed and are case sensitive

public Set<String> duplicateStrings(String str, int k){
Set<String> results = new HashSet();
Set<String> dupSet = new HashSet();

if(str.length() < k || k < 1){
return results;
}

for(int i=0; i<str.length()-k; i++){
String substring = str.substring(i, i+k);
if(dupSet.contains(substring)){
}

}

return results;
}``````

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

import java.util.Scanner;
public class Findduplicates {
public static boolean checkRepeat(int array[][], int length, int index, int j, int k){
int i;
for(i=0;i<index;i++){
int x = array[i][j];
if(x>=k)
return true;
}
return false;
}
public static int finddup(String str, int k){
int count=0,c=0;
int length = str.length()+1;
int array[][] = new int[length][length];
int i,j;

for(i=1;i<=length-(2*k)+1;i++){
for(j=i+k;j<length;j++){
char a = str.charAt(i-1);
char b = str.charAt(j-1);
if(a==b){
array[i][j] = array[i-1][j-1]+1;
if(array[i][j] >= k){
if(checkRepeat(array, length, i, j, k)==false)
count ++;
}
}
}
}

return count;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("\n ENter the String: ");
Scanner in = new Scanner(System.in);
String str = in.nextLine();
System.out.println("Enter pattern length: ");
int k = in.nextInt();
System.out.println("String given: "+str+" pattern length: "+k);
int count;
count = finddup(str, k);
System.out.println("count: "+count);
}

}

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

``````/*
Time Complexity: O(String size x k size)
Space Complexity: O(String size x k size)
*/
static void printDuplicateStrings(String str, int k) {
if (str == null || str.length() == 0 || k <= 0) {
return;
}

HashMap<String, Integer> substrings = new HashMap<>();

for (int i = 0; i < str.length(); i++) {
StringBuilder aux = new StringBuilder();
if (i <= str.length() - k) {
for (int j = i; j < i + k; j++) {
aux.append(str.toLowerCase().charAt(j));
}
if (!substrings.containsKey(aux.toString())) {
substrings.put(aux.toString(), 1);
} else {
substrings.put(aux.toString(), substrings.get(aux.toString()) + 1);
}
}
}
for (String s : substrings.keySet()) {
if (substrings.get(s) > 1) {
System.out.println(s + " " + substrings.get(s));
}
}``````

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

If bbb occurs and k is = 2, does that mean bb and bb are two substrings or no?

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

public class Ksubstring {
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Enter the string : ");
String str = in.nextLine();
// in.nextLine();
System.out.println("Enter the value of k : ");
int k = in.nextInt();

if(k>=str.length()) {
System.out.println("Incorrect input!");
return;
}

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

for(int i =0 ;i<=str.length()-k;i++) {
String newString = str.substring(i, i+k);
int count = duplicates.containsKey(newString)? duplicates.get(newString) : 0;
duplicates.put(newString, count+1);
// System.out.println(str.substring(i, i+k));
}

for(Map.Entry<String,Integer> me : duplicates.entrySet()) {
if(me.getValue()>1) {
System.out.println(me.getKey());
}
}
}

}

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

``````public class Ksubstring {
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Enter the string : ");
String str = in.nextLine();
//		in.nextLine();
System.out.println("Enter the value of k : ");
int k = in.nextInt();

if(k>=str.length()) {
System.out.println("Incorrect input!");
return;
}

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

for(int i =0 ;i<=str.length()-k;i++) {
String newString = str.substring(i, i+k);
int count = duplicates.containsKey(newString)? duplicates.get(newString) : 0;
duplicates.put(newString, count+1);
//			System.out.println(str.substring(i, i+k));
}

for(Map.Entry<String,Integer> me : duplicates.entrySet()) {
if(me.getValue()>1) {
System.out.println(me.getKey());
}
}
}

}``````

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.

### 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.

### 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.