Google Interview Question for Software Engineers

Country: United States
Interview Type: In-Person

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

from z3 import *


M =  'x........x'
M += ''
M += ''
M += '.xxx..x..x'
M += ''
M += '.x...xx...'
M += '...xxxxx..'
M += '.xx.x.xx..'
M += '.xx.x...x.'
M += 'xxxx.....x'

cells = [Int('cell_%d' % i) for i in range(N)]

def overlaps(i,j):
  return M[i*N + j] == 'x'

s = Optimize()

for i in range(N):
  s.add(cells[i] >= 0)
  s.add(cells[i] <= 1)
  for j in range(i+1, N):
    s.add(Or(overlaps(i,j) == False, cells[i] + cells[j] <= 1))


if s.check() == sat:
  res = [x for x in cells if s.model()[x] == 1]
  print (len(res))
  print (res)


[cell_0, cell_3, cell_5, cell_7, cell_8]

- Anonymous September 07, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

If you need to compute a maximal subset where adding a new tower forces the subset to have an overlap with it then this is a Maximal Independent Set (MIS) problem. If on the other hand you need to compute a largest such subset then this is a Maximum Independent Subset problem (MaxIS).

- adr September 07, 2019 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


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


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