"`#include
using namespace std;
void printNumbersTillN(int n){
if(n_==0){
return;
}
printNumbersTillN(n-1); // go to the end -> reach 1
cout>_n;
printNumbersTillN(n);
}`"
Jet 1. - "`#include
using namespace std;
void printNumbersTillN(int n){
if(n_==0){
return;
}
printNumbersTillN(n-1); // go to the end -> reach 1
cout>_n;
printNumbersTillN(n);
}`"See full answer
"not sure what's wrong here>
select
a.marketing_channel,
avg(purchasevalue) as avgpurchase_value,
sum(case when a.purchasevalue > 0 then 1 else 0 end) * 1.0 /count(a.sessionid) as conversion_rate
from attribution a
left join usersessions u on a.sessionid = u.session_id
group by a.marketing_channel
order by conversion_rate desc
`"
Shriganesh K. - "not sure what's wrong here>
select
a.marketing_channel,
avg(purchasevalue) as avgpurchase_value,
sum(case when a.purchasevalue > 0 then 1 else 0 end) * 1.0 /count(a.sessionid) as conversion_rate
from attribution a
left join usersessions u on a.sessionid = u.session_id
group by a.marketing_channel
order by conversion_rate desc
`"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
"function spiralCopy(inputMatrix) {
if (inputMatrix.length === 1) return inputMatrix[0];
let lowerY = 0;
let upperY = inputMatrix.length-1;
let lowerX = 0;
let upperX = inputMatrix[0].length-1;
const output = [];
while (true) {
if (lowerX > upperX) break;
for (let x = lowerX; x upperY) break;
for (let y = lowerY; y <= upperY; y++) {
output.push(inputMatrix[y][u"
Tiago R. - "function spiralCopy(inputMatrix) {
if (inputMatrix.length === 1) return inputMatrix[0];
let lowerY = 0;
let upperY = inputMatrix.length-1;
let lowerX = 0;
let upperX = inputMatrix[0].length-1;
const output = [];
while (true) {
if (lowerX > upperX) break;
for (let x = lowerX; x upperY) break;
for (let y = lowerY; y <= upperY; y++) {
output.push(inputMatrix[y][u"See full answer
"To determine if a graph is not a tree, you can check for the following conditions:
Presence of cycles: A graph is not a tree if it contains cycles. In a tree, there should be exactly one unique path between any two vertices. If you can find a cycle in the graph, it cannot be a tree.
Insufficient number of edges: A tree with N vertices will have exactly N-1 edges. If the graph has fewer or more than N-1 edges, then it is not a tree.
Disconnected components: A tree is a connected graph, m"
Vaibhav C. - "To determine if a graph is not a tree, you can check for the following conditions:
Presence of cycles: A graph is not a tree if it contains cycles. In a tree, there should be exactly one unique path between any two vertices. If you can find a cycle in the graph, it cannot be a tree.
Insufficient number of edges: A tree with N vertices will have exactly N-1 edges. If the graph has fewer or more than N-1 edges, then it is not a tree.
Disconnected components: A tree is a connected graph, m"See full answer
Software Engineer
Coding
+2 more
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"with t1 as (select
employee_name,
department_id,
salary,
avg(salary) over (partition by departmentid) as avgsalary,
abs(salary - avg(salary) over (partition by department_id)) as diff
from employees
)
select
employee_name,
department_id,
salary,
avg_salary,
denserank() over (partition by departmentid order by diff desc) as deviation_rank
from t1
order by departmentid asc, deviationrank asc, employee_name
`"
Alexey T. - "with t1 as (select
employee_name,
department_id,
salary,
avg(salary) over (partition by departmentid) as avgsalary,
abs(salary - avg(salary) over (partition by department_id)) as diff
from employees
)
select
employee_name,
department_id,
salary,
avg_salary,
denserank() over (partition by departmentid order by diff desc) as deviation_rank
from t1
order by departmentid asc, deviationrank asc, employee_name
`"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
"
from typing import Optional
class Node:
def init(self, val: int, prev: Optional['Node'] = None, next: Optional['Node'] = None):
self.val = val
self.prev = prev
self.next = next
def split(head):
if not head or not head.next:
return head
slow = head
fast = head.next
while fast and fast.next:
slow = slow.next
fast = fast.next.next
mid = slow.next
slow.next = None
if mid:
mid.prev = None
"
Akash C. - "
from typing import Optional
class Node:
def init(self, val: int, prev: Optional['Node'] = None, next: Optional['Node'] = None):
self.val = val
self.prev = prev
self.next = next
def split(head):
if not head or not head.next:
return head
slow = head
fast = head.next
while fast and fast.next:
slow = slow.next
fast = fast.next.next
mid = slow.next
slow.next = None
if mid:
mid.prev = None
"See full answer
"function knapsack(weights, values, cap) {
const indicesByValue = Object.keys(weights).map(weight => parseInt(weight));
indicesByValue.sort((a, b) => values[b]-values[a]);
const steps = new Map();
function knapsackStep(cap, sack) {
if (steps.has(sack)) {
return steps.get(sack);
}
let maxOutput = 0;
for (let index of indicesByValue) {
if (!sack.has(index) && weights[index] <= cap) {
maxOutput ="
Tiago R. - "function knapsack(weights, values, cap) {
const indicesByValue = Object.keys(weights).map(weight => parseInt(weight));
indicesByValue.sort((a, b) => values[b]-values[a]);
const steps = new Map();
function knapsackStep(cap, sack) {
if (steps.has(sack)) {
return steps.get(sack);
}
let maxOutput = 0;
for (let index of indicesByValue) {
if (!sack.has(index) && weights[index] <= cap) {
maxOutput ="See full answer
"Implemented the Java code to find the largest island. It is similar to count the island. But in this we need to keep track of max island and compute its perimeter."
Techzen I. - "Implemented the Java code to find the largest island. It is similar to count the island. But in this we need to keep track of max island and compute its perimeter."See full answer
"we can create 2 sets for rows and columns and store the rows and column having 0 and then just check in a loop if the count of that row is greater than 0 llly for column then put the row and column to zero"
Bhavya V. - "we can create 2 sets for rows and columns and store the rows and column having 0 and then just check in a loop if the count of that row is greater than 0 llly for column then put the row and column to zero"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
"Not my answer, but rather the details of this question. It should include the following functions:
int insertNewCustomer(double revenue) -> returns a customer ID (assume auto-incremented & 0-based)
int insertNewCustomer(double revenue, int referrerID) -> returns a customer ID (assume auto-incremented & 0-based)
Set getLowestKCustomersByMinTotalRevenue(int k, double minTotalRevenue) -> returns customer IDs
Note: The total revenue consists of the revenue that this customer bring"
Anzhe M. - "Not my answer, but rather the details of this question. It should include the following functions:
int insertNewCustomer(double revenue) -> returns a customer ID (assume auto-incremented & 0-based)
int insertNewCustomer(double revenue, int referrerID) -> returns a customer ID (assume auto-incremented & 0-based)
Set getLowestKCustomersByMinTotalRevenue(int k, double minTotalRevenue) -> returns customer IDs
Note: The total revenue consists of the revenue that this customer bring"See full answer
"bool isValidBST(TreeNode* root, long min = LONGMIN, long max = LONGMAX){
if (root == NULL)
return true;
if (root->val val >= max)
return false;
return isValidBST(root->left, min, root->val) &&
isValidBST(root->right, root->val, max);
}
`"
Alvaro R. - "bool isValidBST(TreeNode* root, long min = LONGMIN, long max = LONGMAX){
if (root == NULL)
return true;
if (root->val val >= max)
return false;
return isValidBST(root->left, min, root->val) &&
isValidBST(root->right, root->val, max);
}
`"See full answer
"SELECT u.id as user_id, u.name,
COUNT(t.product_id) AS orders
FROM users u
JOIN transactions t
ON
t.user_id = u.id
JOIN products p
ON
p.id = t.product_id
GROUP BY u.id, u.name
ORDER BY orders DESC
LIMIT 1
`"
Derrick M. - "SELECT u.id as user_id, u.name,
COUNT(t.product_id) AS orders
FROM users u
JOIN transactions t
ON
t.user_id = u.id
JOIN products p
ON
p.id = t.product_id
GROUP BY u.id, u.name
ORDER BY orders DESC
LIMIT 1
`"See full answer