"def getcheapestcost(rootNode):
\# need to do DFS for each branch
\# but this can be done recursively
n = len(rootNode.children)
if n == 0:
return 0
else:
min_cost = float('inf')
for i in range(len(n)):
tempcost = getcheapest_cost(rootNode.children[i])
if (tempcost < mincost):
mincost = tempcost
return min_cost + rootNode.cost
\# A node
class Node:
\# Constructor to create a new node
def init\(self, cost):
self.cost = cost
self.children = []
self.parent = None"
Anonymous Owl - "def getcheapestcost(rootNode):
\# need to do DFS for each branch
\# but this can be done recursively
n = len(rootNode.children)
if n == 0:
return 0
else:
min_cost = float('inf')
for i in range(len(n)):
tempcost = getcheapest_cost(rootNode.children[i])
if (tempcost < mincost):
mincost = tempcost
return min_cost + rootNode.cost
\# A node
class Node:
\# Constructor to create a new node
def init\(self, cost):
self.cost = cost
self.children = []
self.parent = None"See full answer
"def flatten_dictionary(dictionary):
\# return a flattened dictionary - int/string/another dictionary values
\# if the key is empty, exclude from the output
\# concat using a "." btwn them
\# add to res which is { "key.a.b.etc": "value" }
\# iterate through the key value pairs
\# while there is a key value pair in the value
\# continue going through that, until the value is an int/string
flatDic = {}
flatDicHelper("", dictionary, flatDic)
print(flatDic)
return flatDic
def flatDicHelper(initialKey"
Anonymous Owl - "def flatten_dictionary(dictionary):
\# return a flattened dictionary - int/string/another dictionary values
\# if the key is empty, exclude from the output
\# concat using a "." btwn them
\# add to res which is { "key.a.b.etc": "value" }
\# iterate through the key value pairs
\# while there is a key value pair in the value
\# continue going through that, until the value is an int/string
flatDic = {}
flatDicHelper("", dictionary, flatDic)
print(flatDic)
return flatDic
def flatDicHelper(initialKey"See full answer
"Here's a simpler solution:
select
u.username
, count(p.postid) as countposts
from posts as p
join users as u
on p.userid = u.userid
where p.likes >= 100
group by 1
order by 2 desc, 1 asc
limit 3
`"
Bradley E. - "Here's a simpler solution:
select
u.username
, count(p.postid) as countposts
from posts as p
join users as u
on p.userid = u.userid
where p.likes >= 100
group by 1
order by 2 desc, 1 asc
limit 3
`"See full answer
"`select employeeid, employeename, sum(maxscore) totalscore
from (
select e.id employeeid, e.name employeename, tr.testid , max(tr.score) maxscore
from employees e
join test_results tr
on e.id = tr.employee_id
group by tr.employeeid, tr.testid
order by 1
)
group by 1,2
order by 3 desc`
`"
Abbas M. - "`select employeeid, employeename, sum(maxscore) totalscore
from (
select e.id employeeid, e.name employeename, tr.testid , max(tr.score) maxscore
from employees e
join test_results tr
on e.id = tr.employee_id
group by tr.employeeid, tr.testid
order by 1
)
group by 1,2
order by 3 desc`
`"See full answer
"SELECT pro.id, pro.title, pro.budget, COUNT(employeeid) AS numemployees, SUM(e.salary) as total_salaries
FROM projects pro
JOIN employeesprojects ep ON ep.projectid = pro.id
JOIN employees e ON e.id = ep.employee_id
GROUP BY project_id;
`"
Zacharias E. - "SELECT pro.id, pro.title, pro.budget, COUNT(employeeid) AS numemployees, SUM(e.salary) as total_salaries
FROM projects pro
JOIN employeesprojects ep ON ep.projectid = pro.id
JOIN employees e ON e.id = ep.employee_id
GROUP BY project_id;
`"See full answer
"SELECT d.name as departmentname,e.id as employeeid,e.firstname,e.lastname,MAX(e.salary) as salary
FROM employees e LEFT JOIN departments d
ON e.department_id=d.id
GROUP BY department_name
ORDER BY department_name;"
Anisha S. - "SELECT d.name as departmentname,e.id as employeeid,e.firstname,e.lastname,MAX(e.salary) as salary
FROM employees e LEFT JOIN departments d
ON e.department_id=d.id
GROUP BY department_name
ORDER BY department_name;"See full answer
"Limit and rank() only works if there are no 2 employees with same salary ( which is okay for this use case)
For the query to pass all the test results, we need to use dense_rank
with ranked_employees as
(
select id, firstname, lastname, salary,
denserank() over(order by salary desc) as salaryrank
from employees
)
select id, firstname, lastname, salary from ranked_employees
where salary_rank <= 3
`"
Vysali K. - "Limit and rank() only works if there are no 2 employees with same salary ( which is okay for this use case)
For the query to pass all the test results, we need to use dense_rank
with ranked_employees as
(
select id, firstname, lastname, salary,
denserank() over(order by salary desc) as salaryrank
from employees
)
select id, firstname, lastname, salary from ranked_employees
where salary_rank <= 3
`"See full answer
"I'm pretty sure Exponent's answer is wrong.
In the snippet below, they use "pl.name = 'Telephones' to attempt to filter down to the Telephone transactions, but they do this within a LEFT JOIN which means all product_lines rows are returned.
> LEFT JOIN product_lines pl
> ON p.productlineid = pl.id
> AND pl.name = 'Telephones'
Below is my solution. Also, I didn't see anywhere that said the "amount" column was in cents instead of dollars, but I still divided by 100 to be consistent with Exp"
Bradley E. - "I'm pretty sure Exponent's answer is wrong.
In the snippet below, they use "pl.name = 'Telephones' to attempt to filter down to the Telephone transactions, but they do this within a LEFT JOIN which means all product_lines rows are returned.
> LEFT JOIN product_lines pl
> ON p.productlineid = pl.id
> AND pl.name = 'Telephones'
Below is my solution. Also, I didn't see anywhere that said the "amount" column was in cents instead of dollars, but I still divided by 100 to be consistent with Exp"See full answer
"--country names are UPPERCASE but the table in the in the question showing lowercase. That's why it took me a while to figure it out until I ran the country column
WITH RECURSIVE Hierarchy AS (
SELECT
e.Emp_ID,
CONCAT(e.FirstName, ' ', e.MiddleName, ' ', e.LastName) AS FullName,
e.Manager_ID,
0 AS Level,
CASE
WHEN e.Country = 'IRELAND' THEN s.Salary * 1.09
WHEN e.Country = 'INDIA' THEN s.Salary * 0.012
ELSE s.Salary
"
Victor N. - "--country names are UPPERCASE but the table in the in the question showing lowercase. That's why it took me a while to figure it out until I ran the country column
WITH RECURSIVE Hierarchy AS (
SELECT
e.Emp_ID,
CONCAT(e.FirstName, ' ', e.MiddleName, ' ', e.LastName) AS FullName,
e.Manager_ID,
0 AS Level,
CASE
WHEN e.Country = 'IRELAND' THEN s.Salary * 1.09
WHEN e.Country = 'INDIA' THEN s.Salary * 0.012
ELSE s.Salary
"See full answer
"Interviewer: Design a Meta Product for space travel.
Me: I would first likely ask a few clarifying questions. Can we discuss more about what do we mean by a product for space travel? Is it like a physical product or a software product? Any existing suite of products that we want to integrate this into?
Interviewer: It can be a digital platform – a combination of software and services, integrated in a single ecosystem. It's not a physical product like a spacecraft, but rather a pla"
Ankit M. - "Interviewer: Design a Meta Product for space travel.
Me: I would first likely ask a few clarifying questions. Can we discuss more about what do we mean by a product for space travel? Is it like a physical product or a software product? Any existing suite of products that we want to integrate this into?
Interviewer: It can be a digital platform – a combination of software and services, integrated in a single ecosystem. It's not a physical product like a spacecraft, but rather a pla"See full answer
"Clarifications:
Where are we launching? -- US first
1:1 or n:n video conferencing? -- you assume
Consumers or Business? -- consumers
Part of FB or standalone product? -- part of messenger app
Is it MVP launch or a full feature product? -- MVP
What capabilities exist in the video conference product? -- you assume what capabilities will be
> Trends and Markets
Competitors:
Consumer
Zoom
Google Meet
Business:
Slack
MS Teams
Trends:
More and more people are usi"
Aniket A. - "Clarifications:
Where are we launching? -- US first
1:1 or n:n video conferencing? -- you assume
Consumers or Business? -- consumers
Part of FB or standalone product? -- part of messenger app
Is it MVP launch or a full feature product? -- MVP
What capabilities exist in the video conference product? -- you assume what capabilities will be
> Trends and Markets
Competitors:
Consumer
Zoom
Google Meet
Business:
Slack
MS Teams
Trends:
More and more people are usi"See full answer