Google Interview Question for Developer Program Engineers


Country: United States
Interview Type: In-Person




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

select p.id, c.id from Parents p inner join Children c on p.id = c.parent_id where p.id = (select parent_id from children where age in (select max(age), min(age) from children group by parent_id));

- Sourabh Das June 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

create table #Parent (Id INT, Age int, Child_Id int)
create table #Child (Id INT, Age int, Parent_Id int)

INSERT INTO #Parent VALUES (1, 55, 1)
INSERT INTO #Parent VALUES (1, 55, 2)
INSERT INTO #Parent VALUES (1, 55, 3)
INSERT INTO #Child VALUES(1, 30, 1)
INSERT INTO #Child VALUES(2, 28, 1)
INSERT INTO #Child VALUES(3, 25, 1)

INSERT INTO #Parent VALUES (2, 45, 4)
INSERT INTO #Parent VALUES (2, 45, 5)
INSERT INTO #Parent VALUES (2, 45, 6)
INSERT INTO #Child VALUES(4, 20, 2)
INSERT INTO #Child VALUES(5, 18, 2)
INSERT INTO #Child VALUES(6, 15, 2)

;WITH T AS
(SELECT p.Id
	,FIRST_VALUE(c.Id) OVER(PARTITION BY p.Id ORDER BY c.Age asc) YoungestChild
	,FIRST_VALUE(c.Id) OVER(PARTITION BY p.Id ORDER BY c.Age desc) EldestChild
	,ROW_NUMBER() OVER(PARTITION BY p.Id ORDER BY c.Age desc) r
FROM #Parent p
	INNER JOIN #Child c
		ON p.Child_Id = c.Id)
SELECT Id, YoungestChild, EldestChild FROM T WHERE r = 1

DROP TABLE #Parent
DROP TABLE #Child

- agarwala.uw November 03, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I there the first

where

clause should retrieve a child id rather than a parent id.

How about this?

select p.id, c.id from Parents p inner join Children c on p.id = c.parent_id where c.id = (select id from children where age in (select max(age), min(age) from children group by parent_id));

- Rose July 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Table 1: Parents -> (int id, int age, int Child_id) 
Table 2: Children -> (int id, int age, int parent_id) 
Get the parent id, his/her oldest and youngest children ids

select parents.id, children.age from

parents p inner join children c on p.id = c.parent_id
where children.id in (select max(id), min(id) from children group by age)

- intervyou June 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select p.id, c.id from Parents p inner join Children c on p.id = c.parent_id where p.id = (select parent_id from children where age in (select max(age), min(age) from children group by parent_id));

- Sourabh Das June 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select c.parent_id, c.id from children c 
join (select max(age) elder, min(age) young, parent_id from children group by parent_id) c1
on c.age = c1.elder or c.age = c1.young and c.parent_id = c1.parent_id
order by c.parent_id, c.age;

- keajer August 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT p.id AS parent,
       MAX(c.age) AS oldest,
       MIN(c.age) AS youngest
FROM parents AS p
LEFT JOIN children AS c ON c.parent_id = p.id
GROUP BY c.parent_id

- Anonymous October 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select p.id as parent_id, c.id from parents as p
join children c
on p.id= c.parent_id
order by int_age desc
limit 1
union
select p.id as parent_id, c.id from parents as p
join children c
on p.id= c.parent_id
order by int_age asc
limit 1

- Rahul R January 05, 2020 | 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