"SELECT
e1.empid AS manageremployee_id,
e1.empname AS managername,
COUNT(e2.empid) AS numberofdirectreports
FROM employees AS e1
INNER JOIN employees AS e2
ON e2.managerid = e1.empid
GROUP BY e1.emp_id
HAVING COUNT(e2.emp_id) >= 2
ORDER BY numberofdirectreports DESC, managername ASC
`"
Alvin P. - "SELECT
e1.empid AS manageremployee_id,
e1.empname AS managername,
COUNT(e2.empid) AS numberofdirectreports
FROM employees AS e1
INNER JOIN employees AS e2
ON e2.managerid = e1.empid
GROUP BY e1.emp_id
HAVING COUNT(e2.emp_id) >= 2
ORDER BY numberofdirectreports DESC, managername ASC
`"See full answer
"The solution produces the same result as the 'prescribed solution' yet it does not get accepted In the test results section
transcript['year'] = transcript['year'].astype(str)
df = pd.pivottable(data = transcript, index = 'studentid', columns = 'year', values = 'yearlygpa', aggfunc = 'mean').resetindex()
df = df[(df['2021'] < df['2022']) & (df['2022'] < df['2023'])]
df['average_gpa'] = df[['2021', '2022', '2023']].mean(axis=1).round(2)
return df
"
Prachi G. - "The solution produces the same result as the 'prescribed solution' yet it does not get accepted In the test results section
transcript['year'] = transcript['year'].astype(str)
df = pd.pivottable(data = transcript, index = 'studentid', columns = 'year', values = 'yearlygpa', aggfunc = 'mean').resetindex()
df = df[(df['2021'] < df['2022']) & (df['2022'] < df['2023'])]
df['average_gpa'] = df[['2021', '2022', '2023']].mean(axis=1).round(2)
return df
"See full answer
"select a.playername as player1, b.playername as player2,
abs(a.level-b.level) as level_disparity
from players a
cross join players b
on a.playername < b.playername
where abs(a.level-b.level) <=5
order by level_disparity
`"
Gowtami K. - "select a.playername as player1, b.playername as player2,
abs(a.level-b.level) as level_disparity
from players a
cross join players b
on a.playername < b.playername
where abs(a.level-b.level) <=5
order by level_disparity
`"See full answer
"SELECT COUNT(DISTINCT o.customerid) AS customers, d.departmentname
FROM orders o
INNER JOIN departments d
ON d.departmentid = o.departmentid
WHERE d.departmentname IN ('Electronics','Fashion') AND o.orderdate BETWEEN '2022-01-01' AND '2022-12-31'
GROUP BY d.department_name;
`"
Derrick M. - "SELECT COUNT(DISTINCT o.customerid) AS customers, d.departmentname
FROM orders o
INNER JOIN departments d
ON d.departmentid = o.departmentid
WHERE d.departmentname IN ('Electronics','Fashion') AND o.orderdate BETWEEN '2022-01-01' AND '2022-12-31'
GROUP BY d.department_name;
`"See full answer
"The best and average of both the algorithms is same which is O(nlog(n)), but the worst time complexity of QuickSort is O(n^2){a case where all the elements are sorted in opposite to the fashion/order you want} while the worst TC for merge sort remains the same O(nlog(n)).
and The SC for QS=O(logn) and MS=O(n)."
The_ A. - "The best and average of both the algorithms is same which is O(nlog(n)), but the worst time complexity of QuickSort is O(n^2){a case where all the elements are sorted in opposite to the fashion/order you want} while the worst TC for merge sort remains the same O(nlog(n)).
and The SC for QS=O(logn) and MS=O(n)."See full answer
"Definitely nice to think of this without memorization, but there is a well known algorithm for this problem, which is the Levenshtein Distance.
Lev(a,b) = len(a) if len(b) == 0
= len(b) if len(a) == 0
= lev(a[1:], b[1:] if a[0] == b[0]
= 1 + min (lev(a, b[1:]), lev(a[1:], b), lev(a[1:], b[1:]))
https://en.wikipedia.org/wiki/Levenshtein_distance
I'm sure some optimizations could be made with heuristic."
Nicholas S. - "Definitely nice to think of this without memorization, but there is a well known algorithm for this problem, which is the Levenshtein Distance.
Lev(a,b) = len(a) if len(b) == 0
= len(b) if len(a) == 0
= lev(a[1:], b[1:] if a[0] == b[0]
= 1 + min (lev(a, b[1:]), lev(a[1:], b), lev(a[1:], b[1:]))
https://en.wikipedia.org/wiki/Levenshtein_distance
I'm sure some optimizations could be made with heuristic."See full answer