"with top_players as(
Select
team_id,
player_name,
max(gamescore) as maxscore
,denserank() over(partition by teamid order by max(game_score) desc) rk
from players p join scores s on p.playerid=s.playerid
group by
player_name,
team_id
)
Select
team_id,
player_name,
max_score
from top_players
where rk<=2
order by teamid, maxscore desc
`"
Victor N. - "with top_players as(
Select
team_id,
player_name,
max(gamescore) as maxscore
,denserank() over(partition by teamid order by max(game_score) desc) rk
from players p join scores s on p.playerid=s.playerid
group by
player_name,
team_id
)
Select
team_id,
player_name,
max_score
from top_players
where rk<=2
order by teamid, maxscore desc
`"See full answer
"public static void sortBinaryArray(int[] array) {
int len = array.length;
int[] res = new int[len];
int r=len-1;
for (int value : array) {
if(value==1){
res[r]= 1;
r--;
}
}
System.out.println(Arrays.toString(res));
}
`"
Nitin P. - "public static void sortBinaryArray(int[] array) {
int len = array.length;
int[] res = new int[len];
int r=len-1;
for (int value : array) {
if(value==1){
res[r]= 1;
r--;
}
}
System.out.println(Arrays.toString(res));
}
`"See full answer
"Here is my implementation:
select
marketing_channel,
AVG(purchasevalue) as avgpurchase_value
from
attribution
group by marketing_channel
order by avgpurchasevalue DESC
;
There is no need to copy and past the line of code for calculating the average into order by, just Alias is enough because going by the order of execution in sql, Always, order by is executed after executing select clause."
Maliki U. - "Here is my implementation:
select
marketing_channel,
AVG(purchasevalue) as avgpurchase_value
from
attribution
group by marketing_channel
order by avgpurchasevalue DESC
;
There is no need to copy and past the line of code for calculating the average into order by, just Alias is enough because going by the order of execution in sql, Always, order by is executed after executing select clause."See full answer
Data Scientist
Coding
+1 more
🧠Want an expert answer to a question? Saving questions lets us know what content to make next.
"Problem Statement: The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2) with F(0) = 1 and F(1) = 1.
The solution is given in the problem statement itself.
If the value of n = 0, return 1.
If the value of n = 1, return 1.
Otherwise, return the sum of data at (n - 1) and (n - 2).
Explanation: The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, typically starting with 0 and 1.
Java Solution:
public static int fib(int n"
Rishi G. - "Problem Statement: The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2) with F(0) = 1 and F(1) = 1.
The solution is given in the problem statement itself.
If the value of n = 0, return 1.
If the value of n = 1, return 1.
Otherwise, return the sum of data at (n - 1) and (n - 2).
Explanation: The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, typically starting with 0 and 1.
Java Solution:
public static int fib(int n"See full answer
"-- The text of the task is a bit confusing. If the status is repeated several
-- times, then in the end you should show as start_date the date of the first
-- occurrence, and in end_date the date of the last occurrence of this status,
-- and not the date of the beginning of the next status
with t1 as (select
order_id,
status,
orderdate as startdate,
lead(orderdate) over (partition by orderid order by orderdate) as enddate,
ifnull(lag(status) over (partition by order_id order by or"
Alexey T. - "-- The text of the task is a bit confusing. If the status is repeated several
-- times, then in the end you should show as start_date the date of the first
-- occurrence, and in end_date the date of the last occurrence of this status,
-- and not the date of the beginning of the next status
with t1 as (select
order_id,
status,
orderdate as startdate,
lead(orderdate) over (partition by orderid order by orderdate) as enddate,
ifnull(lag(status) over (partition by order_id order by or"See full answer
"SELECT order_amount
FROM (
SELECT *, rank() OVER(ORDER BY order_amount desc) as ranking
FROM departments d
LEFT JOIN orders o
ON d.departmentid = o.departmentid
LEFT JOIN customers c
ON o.customerid = c.customerid
WHERE department_name = 'Fashion'
)
where ranking = 2"
Jacky T. - "SELECT order_amount
FROM (
SELECT *, rank() OVER(ORDER BY order_amount desc) as ranking
FROM departments d
LEFT JOIN orders o
ON d.departmentid = o.departmentid
LEFT JOIN customers c
ON o.customerid = c.customerid
WHERE department_name = 'Fashion'
)
where ranking = 2"See full answer
"-- LTV = Sum of all purchases made by that user
-- order the results by desc on LTV
select
u.user_id,
sum(a.purchase_value) as LTV
from
user_sessions u
join
attribution a
on u.sessionid = a.sessionid
group by
u.user_id
order by sum(a.purchase_value) desc"
Mohit C. - "-- LTV = Sum of all purchases made by that user
-- order the results by desc on LTV
select
u.user_id,
sum(a.purchase_value) as LTV
from
user_sessions u
join
attribution a
on u.sessionid = a.sessionid
group by
u.user_id
order by sum(a.purchase_value) desc"See full answer
"Binary Search on the array and after than compare the numbers at low and the high pointers whichever is closest is the answer. Because after the binary search low will be pointing to a number which is immediate greater than x and high will be pointing to a number which is immediate lesser than x.
int low = 0;
int high = n-1;
while(low <= high){
int mid = (low + high) / 2;
if(x == arr[mid]) return mid; //if x is already present then it will be the closest
else if(x < arr[mid]) high"
Shashwat K. - "Binary Search on the array and after than compare the numbers at low and the high pointers whichever is closest is the answer. Because after the binary search low will be pointing to a number which is immediate greater than x and high will be pointing to a number which is immediate lesser than x.
int low = 0;
int high = n-1;
while(low <= high){
int mid = (low + high) / 2;
if(x == arr[mid]) return mid; //if x is already present then it will be the closest
else if(x < arr[mid]) high"See full answer
"select
sub.name subreddit_name,
count(distinct us.userid) totalusers
from user_subreddit as us
left join subreddit as sub
on us.subredditid = sub.subredditid
group by
us.subreddit_id
having
count(distinct us.user_id) > 3"
Lucas G. - "select
sub.name subreddit_name,
count(distinct us.userid) totalusers
from user_subreddit as us
left join subreddit as sub
on us.subredditid = sub.subredditid
group by
us.subreddit_id
having
count(distinct us.user_id) > 3"See full answer
"def validateIP(ip):
"""
@param ip: str
@return: bool
"""
\# ip needs to be in X.X.X.X
\# X is from 0 to 255
\# split the ip at "."
split = ip.split('.')
if (len(split) != 4):
return False
for number in split:
if (int(number) 255):
return False
return True"
Anonymous Owl - "def validateIP(ip):
"""
@param ip: str
@return: bool
"""
\# ip needs to be in X.X.X.X
\# X is from 0 to 255
\# split the ip at "."
split = ip.split('.')
if (len(split) != 4):
return False
for number in split:
if (int(number) 255):
return False
return True"See full answer
"class Solution:
def missingNumber(self, nums: list[int]) -> int:
Sorting approach
n = len(nums)
s = n*(n+1)//2
r = s - sum(nums)
return self.r
l = [3,0,1]
print(missingNumber(l))"
Rohit B. - "class Solution:
def missingNumber(self, nums: list[int]) -> int:
Sorting approach
n = len(nums)
s = n*(n+1)//2
r = s - sum(nums)
return self.r
l = [3,0,1]
print(missingNumber(l))"See full answer
"Example:
bucket A: 3 liters capacity
bucket B: 5 liters capacity
goal: 4 liters
You are asked to print the logical sequence to get to the 4 liters of water in one bucket.
Follow up:
How would you solve the problem if you have more than 2 buckets of water?"
B. T. - "Example:
bucket A: 3 liters capacity
bucket B: 5 liters capacity
goal: 4 liters
You are asked to print the logical sequence to get to the 4 liters of water in one bucket.
Follow up:
How would you solve the problem if you have more than 2 buckets of water?"See full answer
"-- filter for december and november data
-- the total order amount per depatment per month
-- department, month, order_amount
with monthly_orders AS (
SELECT
department_id,
strftime('%m', order_date) AS month,
SUM(orderamount) AS orderamount
FROM
orders
WHERE
orderdate >= '2022-11-01' AND orderdate < '2023-01-01'
group by
department_id, month
),
-- -- add difference from this month to last ( use lag )
monthly_comp"
Aneesha K. - "-- filter for december and november data
-- the total order amount per depatment per month
-- department, month, order_amount
with monthly_orders AS (
SELECT
department_id,
strftime('%m', order_date) AS month,
SUM(orderamount) AS orderamount
FROM
orders
WHERE
orderdate >= '2022-11-01' AND orderdate < '2023-01-01'
group by
department_id, month
),
-- -- add difference from this month to last ( use lag )
monthly_comp"See full answer
"select
customer_id,
order_date,
orderid as earliestorder_id
from (
select customer_id,
order_date,
order_id,
rownumber() over (partition by customerid, orderdate order by orderdate) as orderrankper_customer
from orders
) sub_table
where orderrankper_customer=1
order by orderdate, customerid;
Standard solution assumed that the orderid indicates which order comes in first. However this is not always the case, and sometime orderid can be random number withou"
Jessica C. - "select
customer_id,
order_date,
orderid as earliestorder_id
from (
select customer_id,
order_date,
order_id,
rownumber() over (partition by customerid, orderdate order by orderdate) as orderrankper_customer
from orders
) sub_table
where orderrankper_customer=1
order by orderdate, customerid;
Standard solution assumed that the orderid indicates which order comes in first. However this is not always the case, and sometime orderid can be random number withou"See full answer