Google Interview Question for Data Engineers


Country: United States




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

public static long numWays(int n){
	    long dp[] = new long[n];
	    dp[0] = 1;
	    dp[1] = 2;
	    for(int i = 2; i < n; i++){
	        dp[i] = dp[i-1] + dp[i-2];
	    }
	    return dp[n-1];
	}

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

public static long numWays(int n){
	    long dp[] = new long[n];
	    dp[0] = 1;
	    dp[1] = 2;
	    for(int i = 2; i < n; i++){
	        dp[i] = dp[i-1] + dp[i-2];
	    }
	    return dp[n-1];
	}

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

Simple DP solution
public static long numWays(int n){
long dp[] = new long[n];
dp[0] = 1;
dp[1] = 2;
for(int i = 2; i < n; i++){
dp[i] = dp[i-1] + dp[i-2];
}
return dp[n-1];
}

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

public static long numWays(int n){
	    long dp[] = new long[n];
	    dp[0] = 1;
	    dp[1] = 2;
	    for(int i = 2; i < n; i++){
	        dp[i] = dp[i-1] + dp[i-2];
	    }
	    return dp[n-1];
	}

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

public static long numWays(int n){
	    long dp[] = new long[n];
	    dp[0] = 1;
	    dp[1] = 2;
	    for(int i = 2; i < n; i++){
	        dp[i] = dp[i-1] + dp[i-2];
	    }
	    return dp[n-1];
	}

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

public static long numWays(int n){
long dp[] = new long[n];
dp[0] = 1;
dp[1] = 2;
for(int i = 2; i < n; i++){
dp[i] = dp[i-1] + dp[i-2];
}
return dp[n-1];
}

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

# n: number of columns to complete
    # bo: boolean, whether the bottom square at the current col is open
    # to: boolean, whether the top square at the current col is open
    # memo: cached results
    def rec(n, bo, to,memo)
      # return the cached result if we have one
      if memo.include?([n,bo,to])
        return memo[[n,bo,to]]
      end

      r = if bo && to # if both squares are open
        rec(n-1, true, true,memo) + # use a vertical piece
        rec(n-2, true, true,memo) + # use two horizontal pieces
        rec(n-1, false, true,memo) + # use an L piece, leaving top open
        rec(n-1, true, false,memo)   # use an L piece, leaving bottom open
      elsif bo  # if only the bottom is open
        rec(n-1, false, true,memo) + # use a horizontal piece, leave the top open
        rec(n-2, true, true,memo) # use an L shape to cover the bottom hole
      else # if only the top is open
        rec(n-1, true, false,memo) + # use a horizontal piece, leave the bottom open
        rec(n-2, true, true,memo) # use an L shape to cover the top hole
      end
      memo[[n,bo,to]] = r
      r
    end
    def solution(n)
      memo = {
      [1, true, true] => 1,
      [1, false, true] => 0,
      [1, true, false] => 0,
      [2, true, true] => 2,
      [2, true, false] => 1,
      [2, false, true] => 1}
      rec(n, true, true, memo)
    end

- randy January 26, 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