"In python
def find_duplicates(arr1: List[int], arr2: List[int]) -> List[int]:
result = list(set(arr1) & set(arr2))
return result
"
Sammy R. - "In python
def find_duplicates(arr1: List[int], arr2: List[int]) -> List[int]:
result = list(set(arr1) & set(arr2))
return result
"See full answer
"with cte as
(select (count(postid)/count(userid)) as avgpost, avg(issuccessfulpost) as avgsuccess
from post)
select p.userid,sum(issuccessfulpost) as postsuccess,count(p.postid) as postattempt,ROUND(avg(issuccessfulpost),2) as postsuccessrate
from post p,cte c
on p.user_id
group by p.user_id
having postattempt>c.avgpost and postsuccessrate<c.avg_success
order by postsuccessrate desc"
Devanshu K. - "with cte as
(select (count(postid)/count(userid)) as avgpost, avg(issuccessfulpost) as avgsuccess
from post)
select p.userid,sum(issuccessfulpost) as postsuccess,count(p.postid) as postattempt,ROUND(avg(issuccessfulpost),2) as postsuccessrate
from post p,cte c
on p.user_id
group by p.user_id
having postattempt>c.avgpost and postsuccessrate<c.avg_success
order by postsuccessrate desc"See full answer
"1) select avg(session) from table where session> 180
2) select round(sessiontime/300)*300 as sessionbin, count() as sessioncount from table group by round(sessiontime/300)300 order by session_bin
3) SELECT t1.country AS country_a,
t2.country AS country_b
FROM (
SELECT country, COUNT(*) AS session_count
FROM yourtablename
GROUP BY country
) AS t1
JOIN (
SELECT country, COUNT(*) AS session_count
FROM yourtablename
`GROUP BY countr"
Erjan G. - "1) select avg(session) from table where session> 180
2) select round(sessiontime/300)*300 as sessionbin, count() as sessioncount from table group by round(sessiontime/300)300 order by session_bin
3) SELECT t1.country AS country_a,
t2.country AS country_b
FROM (
SELECT country, COUNT(*) AS session_count
FROM yourtablename
GROUP BY country
) AS t1
JOIN (
SELECT country, COUNT(*) AS session_count
FROM yourtablename
`GROUP BY countr"See full answer
"function serialize(list) {
for (let i=0; i 0xFFFF) {
throw new Exception(String ${list[i]} is too long!);
}
const prefix = String.fromCharCode(length);
list[i] = ${prefix}${list[i]};
console.log(list[i])
}
return list.join('');
}
function deserialize(s) {
let i=0;
const length = s.length;
const output = [];
while (i < length) {
"
Tiago R. - "function serialize(list) {
for (let i=0; i 0xFFFF) {
throw new Exception(String ${list[i]} is too long!);
}
const prefix = String.fromCharCode(length);
list[i] = ${prefix}${list[i]};
console.log(list[i])
}
return list.join('');
}
function deserialize(s) {
let i=0;
const length = s.length;
const output = [];
while (i < length) {
"See full answer
"You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line.
Example:
S = "abracadabra sample"
K = 11
Output:
abracadabra
sample
Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"
B. T. - "You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line.
Example:
S = "abracadabra sample"
K = 11
Output:
abracadabra
sample
Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"See full answer
Software Engineer
Coding
+1 more
🧠Want an expert answer to a question? Saving questions lets us know what content to make next.
"\# Definition for a binary tree node.
class TreeNode:
def init(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution:
def maxPathSum(self, root: TreeNode) -> int:
self.max_sum = float('-inf')"
Jerry O. - "\# Definition for a binary tree node.
class TreeNode:
def init(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution:
def maxPathSum(self, root: TreeNode) -> int:
self.max_sum = float('-inf')"See full answer
"Count items between indices within compartments
compartments are delineated by by: '|'
items are identified by: '*'
input_inventory = "*||||"
inputstartidxs = [1, 4, 6]
inputendidxs = [9, 5, 8]
expected_output = [3, 0, 1]
Explanation:
"*||||"
0123456789... indices
++ + # within compartments
^ start_idx = 1
^ end_idx = 9
-- - # within idxs but not within compartments
"*||||"
0123456789... indices
"
Anonymous Unicorn - "Count items between indices within compartments
compartments are delineated by by: '|'
items are identified by: '*'
input_inventory = "*||||"
inputstartidxs = [1, 4, 6]
inputendidxs = [9, 5, 8]
expected_output = [3, 0, 1]
Explanation:
"*||||"
0123456789... indices
++ + # within compartments
^ start_idx = 1
^ end_idx = 9
-- - # within idxs but not within compartments
"*||||"
0123456789... indices
"See full answer
"with max_score as(
select
test_id,
employee_id,
max(score) as max_score
from test_results as t1
join tests as t2
on t1.test_id=t2.id
group by 2,1
)
select
id as employee_id,
name as employee_name,
sum(maxscore) as totalscore
from employees as e
join max_score as m
on e.id=m.employee_id
group by 1,2
order by 3 desc, 1
`"
Victor N. - "with max_score as(
select
test_id,
employee_id,
max(score) as max_score
from test_results as t1
join tests as t2
on t1.test_id=t2.id
group by 2,1
)
select
id as employee_id,
name as employee_name,
sum(maxscore) as totalscore
from employees as e
join max_score as m
on e.id=m.employee_id
group by 1,2
order by 3 desc, 1
`"See full answer
"-- Write your query here
select
p.id,
p.title,
p.budget,
count(e.id) as num_employees,
sum(e.salary) as total_salaries
from projects p
join employeesprojects ep on p.id = ep.projectid
join employees e on ep.employee_id = e.id
group by 1
order by 5 desc;
`"
Anonymous Roadrunner - "-- Write your query here
select
p.id,
p.title,
p.budget,
count(e.id) as num_employees,
sum(e.salary) as total_salaries
from projects p
join employeesprojects ep on p.id = ep.projectid
join employees e on ep.employee_id = e.id
group by 1
order by 5 desc;
`"See full answer
"SELECT
items.item_category,
SUM(orders.orderquantity) AS totalunitsorderedlast7days
FROM orders
JOIN items
ON orders.itemid = items.itemid
WHERE orders.order_date BETWEEN DATE('now', '-6 days') AND DATE('now')
GROUP BY items.item_category
`"
Salome L. - "SELECT
items.item_category,
SUM(orders.orderquantity) AS totalunitsorderedlast7days
FROM orders
JOIN items
ON orders.itemid = items.itemid
WHERE orders.order_date BETWEEN DATE('now', '-6 days') AND DATE('now')
GROUP BY items.item_category
`"See full answer
"def friend_distance(friends, userA, userB):
step = 0
total_neighs = set()
llen = len(total_neighs)
total_neighs.add(userB)
while len(total_neighs)!=llen:
s = set()
step += 1
llen = len(total_neighs)
for el in total_neighs:
nes = neighbours(friends, userA, el)
if userA in nes:
return step
for p in nes:
s.add(p)
for el in s:
total_neighs.add(el)
return -1
def neighbours(A,n1, n2):
out = set()
for i in range(len(A[n2])):
if An2:
out.add(i)
return out"
Batman X. - "def friend_distance(friends, userA, userB):
step = 0
total_neighs = set()
llen = len(total_neighs)
total_neighs.add(userB)
while len(total_neighs)!=llen:
s = set()
step += 1
llen = len(total_neighs)
for el in total_neighs:
nes = neighbours(friends, userA, el)
if userA in nes:
return step
for p in nes:
s.add(p)
for el in s:
total_neighs.add(el)
return -1
def neighbours(A,n1, n2):
out = set()
for i in range(len(A[n2])):
if An2:
out.add(i)
return out"See full answer
"WITH discount AS (
SELECT
name,
type,
CASE
WHEN type = 'Electronic' THEN price * 0.90
WHEN type = 'Clothing' THEN price * 0.80
WHEN type = 'Grocery' THEN price * 0.95
WHEN type = 'Book' THEN price * 0.85
ELSE price
END AS discounted_price
FROM products
)
SELECT
name,
type,
ROUND(discountedprice, 2) AS discountedprice
FROM discount;
`"
Salome L. - "WITH discount AS (
SELECT
name,
type,
CASE
WHEN type = 'Electronic' THEN price * 0.90
WHEN type = 'Clothing' THEN price * 0.80
WHEN type = 'Grocery' THEN price * 0.95
WHEN type = 'Book' THEN price * 0.85
ELSE price
END AS discounted_price
FROM products
)
SELECT
name,
type,
ROUND(discountedprice, 2) AS discountedprice
FROM discount;
`"See full answer