Solving a Facebook Data Science Interview Questions | (SQL Interview Questions and Answer)

preview_player
Показать описание
This SQL data science interview question was asked by Facebook. I’ll cover both the question and answer and give a detailed explanation of the approach. I walkthrough each step of my answer, assumptions, approach, and explain every line of code I write. This is literally how I would answer every data science interview question and prepare for every data science interview at FAANG companies and others.

This question can seem hard when you first read it. But this question can be broken down into multiple parts. We cover how to build a CTE or SQL subquery to classify results in the top 3 positions and the LEFT JOIN the table to the original table so that you can preserve the number of rows, which you’ll need to count when calculating a percentage. Most importantly, we’ll cover what the resulting SQL LEFT JOIN will look like so that you can understand how to write the percentage formula in the SELECT clause. This question covers concepts that are commonly found in data science interviews at Facebook and Google.

______________________________________________________________________

______________________________________________________________________
Timestamps:

Intro: (0:00)
Interview Question: (0:13)
Exploring The Data: (0:34)
Solution Framework Before Coding: (1:03)
Coding: SUBQUERY: (3:29)
Coding: LEFT JOIN: (4:03)
Coding: Calculating Percentage: (4:59)
______________________________________________________________________
About The Platform:

I'm using StrataScratch, a platform that allows you to practice real data science interview questions. There are over 1000+ interview questions that cover coding (SQL and python), statistics, probability, product sense, and business cases.

I created this platform because I wanted to build a resource to specifically help prepare data scientists for their technical interviews and to generally improve their analytical skills. Over my career as a data scientist, I never was able to find a dedicated platform for data science interview prep. LeetCode and HackerRank were the closest but these platforms specifically serve the computer developer community so their questions focus more on algorithms that working with data.

______________________________________________________________________
Contact:

If you have any questions, comments, or feedback, please leave them here!
______________________________________________________________________
Рекомендации по теме
Комментарии
Автор

Select sum(case when position =3 then 1 else 0)/count(*) from table

AnilKumar-bdyt
Автор

Even more simplified version of solution ->

select as result
from
(select count(*) as den, count(case when position<=3 then position else null end) as num
from fb_search_results
) temp


By the way, love your videos and methods :)

himanisethi
Автор

My solution
with cte1 as (select round(sum(case when clicked=1 and search_results_position<=3 then 1
else 0 end), 2)*100 no_clicked,
round(sum(case when clicked=0 and search_results_position<=3 then 1
else 0 end), 2)*100 no_not_clicked
from fb_search_events)
select no_clicked/(select count(*) from fb_search_events) top_3_clicked, no_not_clicked/(select count(*) from fb_search_events) top_3_notclicked from cte1

dwaipayansaha
Автор

These videos are super great, Nate, thanks!

besartc.
Автор

Joins are difficult to comprehend :( so here's one without join:
with cet1
as
(
-- rank the positions
select result_id, position,
DENSE_RANK() over(order by position) rank
from fb_search_results

),
cet2
as
(
-- count top 3 search results
select count(*) as top_3_searches
from (
select rank
from cet1
where rank < 4
) a
),
cet3
as
(
-- count total number of search results
select count(result_id) as total_searches
from fb_search_results
)

-- calculate the percentage of top 3 search results
select top_3_percentage
from cet2 c2, cet3 c3

shobhamourya
join shbcf.ru