Google Interview Question for Software Engineer in Tests


Country: United States
Interview Type: In-Person




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

It is so annoying when we end up wasting time trying to figure out what the question is. Despite posting questions is useful to us, such vague questions is actually counter productive.

- Dilbert Einstein September 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

This problem seems to ask, given a list of intervals and a particular interval, delete the particular interval and output the remaining intervals. However, it is unclear whether the list of intervals are sorted to begin with and also what to do when the particular interval to delete falls on two or more intervals.

- bk September 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

I see this as a double linked list.

Every interval can be stored as a node in a double linked list.
When a node gets deleted , inaddition to modifying the pointers, modify the values too.

typedef struct node_t {
struct node_t prev;
int prev_data;
struct node_t next;
int next_data;
}node;

12 <==> 24 <==> 45.
[illustration only, not this problem]
lets imagine we need to insert 23,
we need to insert a node called 23
with node->next_data = 3;
and node->prev_data = 2;

traverse the node and find a node with next_data = 2.
let it be p;
newnode->next_data = 3;
newnode->prev_data = 2;
newnode->next = p->next;
newnode->prev = p;
p->next = newnode;
p->next_data = newnode->prev_data; //3;
newnode->prev_data = newnode->next_data;
newnode->next_data = newnode->next->prev_data; // newnode becomes 34

so totally the nodes will now become

12 <==> 23 <===>34 <==> 45.

now to delete 23, which is our node, we refer it by 'del'
let del point to  23.

12 <==> 23 <===>34 <==> 45.
//del->prev_data = 2;
//del->next_data = 3;
//del->prev = 12;
//del->next = 34;
void delete (node *del)
{
    node *after;
    node *before;
    before = del->prev;
    after = del->next; //34
    after->prev_data = del->prev_data; // 34 becomes 24;
    before->next = after;
    after->prev = before;
    free(del);
}

12 <=====> 24 <========> 45

Corrections are appreciated :)
--
“A mistake is a crash-course in learning.”
--

- code_monkey September 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

can you explain your question ??

- cobra August 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Input 1: a list of elements and each elements contains two numbers
Input 2: an element which contains two numbers.
output: remove the input2 from input1 then print input1.

- Vincent August 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Shouldn't the output be [1,2] [3,4] according to your explanation?

- Anshu Kumar August 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Question is not clear...need more examples

- Victor August 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

1. Declare a function which generate a good hash combining both the numbers
2. Add all the input1 list to another list
3. remove the input2 from input1 list and print it

- Amith August 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void removeInterval(int []interval, int[]input){
		ArrayList<Integer> result = new ArrayList<Integer>();
		for(int i=0;i<interval.length;i=i+2){
			if(interval[i] <input[0]){
				result.add(interval[i]);
				result.add(interval[i+1]);
			}
			else if(interval[i] >=input[1]){
				result.add(interval[i]);
				result.add(interval[i+1]);
			}
			
		}
		
		System.out.println(result.toString());

}

- jerry July 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As someone else pointed out this could be implemented with a linked list, removing nodes within specified range, or we could do something like the following python code:

def rem_intervals(intervals, start, end):
    i = 0
    while i < len(intervals)-1:
        print "Current index is: ", i, intervals[i]
        if intervals[i][0] >= start and intervals[i][1] <= end:
            print "Removing interval: ", intervals[i]
            intervals.pop(i)
        elif intervals[i][0] == end:
            intervals[i][0] = start
            i = i + 1
        else:
            i = i + 1
    return intervals


intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]
start = 2
end = 5
print rem_intervals(intervals, start, end)

- Badr September 03, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def rem_intervals(intervals, start, end):
    i = 0
    while i < len(intervals)-1:
        print "Current index is: ", i, intervals[i]
        if intervals[i][0] >= start and intervals[i][1] <= end:
            print "Removing interval: ", intervals[i]
            intervals.pop(i)
        elif intervals[i][0] == end:
            intervals[i][0] = start
            i = i + 1
        else:
            i = i + 1
    return intervals

- Badr September 03, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

The question looks like, given a list of intervals and some numbers, insert the numbers into the intervals such that those neighboring intervals can be merged together. And output the merged intervals

- jj August 11, 2012 | 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