Google Interview Question for Software Engineers


Country: United States




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

Looking for help on interview preparation?
Visit AONECODE.COM for ONE-TO-ONE private lessons by FB, Google and Uber engineers!

Customized course covers
System Design (for candidates of FB, LinkedIn, AMZ, Google and Uber etc)
Algorithms (DP, Greedy, Graph etc. every aspect you need in a coding interview and Clean Coding)
Interview questions sorted by companies
Mock Interviews

Our members got into G, U, FB, Amazon, LinkedIn, MS and other top-tier companies after weeks of training.

Feel free to email us aonecoding@gmail.com with any questions. Thanks!

boolean hasFactorKSubArray(int[] arr, int k) {
        for(int i = 1; i < arr.length; i++) {
            arr[i] += arr[i - 1]; //becomes a prefix sum array of arr (can be recovered if necessary)
        }
        for(int hi = arr.length - 1; hi >= 1; hi-- ) {
            for(int lo = 0; lo <= hi - 1; lo++) {
                if((arr[hi] - lo == 0 ? 0: arr[lo - 1]) % k == 0) {
                    return true;
                }
            }
        }
        return false;
    }

- aonecoding January 13, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package findSubArray;
import java.util.*;

public class findSubArray {

public static int findsubArray(int arr[], int k) {
int n = arr.length, i, j;
int array[][] = new int[n][n];
for(i=0;i<n;i++) {
array[0][i] = arr[i];
}
for(i=0;i<n;i++) {
array[i][0] = arr[0];
}
for(i=1; i<n; i++) {
for(j=i;j<n;j++) {
array[i][j] = arr[j] * array[i-1][j-1];
System.out.println("i: "+i+" j: "+j+" arr[i-1][j-1]: "+array[i-1][j-1]+" arr[i][j]: "+array[i][j]);
if(array[i][j] % k ==0) {
if(i != 0) {
System.out.println("End of subarray is: "+arr[j]);
return i+1;
}
}
}
}
return 0;

}
public static void main(String[] args) {
// TODO Auto-generated method stub
int array[] = {1, 9, 16, 5, 4, 3, 2};
int k = 720;
int answer = findsubArray(array, k);
System.out.println("Minimum lenth of subarray is: "+answer);
}

}

- Varsha Jayaraman January 13, 2018 | 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