Google Interview Question for SDE1s

Country: United States

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

# how to keep track of the sum in a sliding window for
# the data that are on disk
# rather than memory
# may 11 2017

from itertools import islice

def window(seq, n=2):
    it = iter(seq)
    result = tuple(islice(it,n))
    if len(result) == n:
        yield result
        sum_windows = sum(result)
        for elem in it:
            result = result[1:] + (elem,)
            # i believe this is what google is looking for
            sum_windows += elem
            print('The sum of the window is ', sum_windows)
            yield result

for x in window(range(10),4):

- an idea but its a bit slow May 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

When it means data is on disk, it means that size of the data is not known and is probably very large. Like a 1GB file. In such case we can used a circular buffer (circular linked list say size N) to read a chunk of data in the buffer and slide the window of size k to get the sum. As we reach the end of buffer, we can read N-K chunk of data in the buffer and keep adding the data in head to the sliding window.

- Anonymous March 15, 2018 | 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