"SELECT employees.first_name,
managers.salary AS manager_salary
FROM employees
LEFT JOIN employees AS managers
ON employees.manager_id = managers.id
WHERE employees.salary > managers.salary
`"
Tiffany A. - "SELECT employees.first_name,
managers.salary AS manager_salary
FROM employees
LEFT JOIN employees AS managers
ON employees.manager_id = managers.id
WHERE employees.salary > managers.salary
`"See full answer
"Reversing a linked list is a very popular question. We have two approaches to reverse the linked list: Iterative approach and recursion approach.
Iterative approach (JavaScript)
function reverseLL(head){
if(head === null) return head;
let prv = null;
let next = null;
let cur = head;
while(cur){
next = cur.next; //backup
cur.next = prv;
prv = cur;
cur = next;
}
head = prv;
return head;
}
Recursion Approach (JS)
function reverseLLByRecursion("
Satyam S. - "Reversing a linked list is a very popular question. We have two approaches to reverse the linked list: Iterative approach and recursion approach.
Iterative approach (JavaScript)
function reverseLL(head){
if(head === null) return head;
let prv = null;
let next = null;
let cur = head;
while(cur){
next = cur.next; //backup
cur.next = prv;
prv = cur;
cur = next;
}
head = prv;
return head;
}
Recursion Approach (JS)
function reverseLLByRecursion("See full answer
"select employeename, employeeid, salary, department, DR
from (
select employeename, employeeid, salary, dense_rank() over (partition by department order by salary desc) DR, department from employee
)
where DR <=3
order by department, DR"
Sreeram reddy B. - "select employeename, employeeid, salary, department, DR
from (
select employeename, employeeid, salary, dense_rank() over (partition by department order by salary desc) DR, department from employee
)
where DR <=3
order by department, DR"See full answer
"public static boolean isPalindrome(String str){
boolean flag = true;
int len = str.length()-1;
int j = len;
for(int i=0;i<=len/2;i++){
if(str.charAt(i)!=str.charAt(j--)){
flag = false;
break;
}
}
return flag;
}"
Sravanthi M. - "public static boolean isPalindrome(String str){
boolean flag = true;
int len = str.length()-1;
int j = len;
for(int i=0;i<=len/2;i++){
if(str.charAt(i)!=str.charAt(j--)){
flag = false;
break;
}
}
return flag;
}"See full answer
"
Compare alternate houses i.e for each house starting from the third, calculate the maximum money that can be stolen up to that house by choosing between:
Skipping the current house and taking the maximum money stolen up to the previous house.
Robbing the current house and adding its value to the maximum money stolen up to the house two steps back.
package main
import (
"fmt"
)
// rob function calculates the maximum money a robber can steal
func maxRob(nums []int) int {
ln"
VContaineers - "
Compare alternate houses i.e for each house starting from the third, calculate the maximum money that can be stolen up to that house by choosing between:
Skipping the current house and taking the maximum money stolen up to the previous house.
Robbing the current house and adding its value to the maximum money stolen up to the house two steps back.
package main
import (
"fmt"
)
// rob function calculates the maximum money a robber can steal
func maxRob(nums []int) int {
ln"See full answer
"How do you find consecutive days for login (MySQL, SQL, date, subquery, MySQL 5.7, development)?
1
Follow
Request
Answer
More
All related (34)
Recommended
📷
Trausti Thor Johannsson
·
Follow
Been using MySQL for more than 16 yearsDec 27
There are functions like DATEDIFF but there are also BETWE"
Hayatu H. - "How do you find consecutive days for login (MySQL, SQL, date, subquery, MySQL 5.7, development)?
1
Follow
Request
Answer
More
All related (34)
Recommended
📷
Trausti Thor Johannsson
·
Follow
Been using MySQL for more than 16 yearsDec 27
There are functions like DATEDIFF but there are also BETWE"See full answer
"SELECT
s.Sale_Date,
SUM(si.Quantity * si.SalePrice) AS TotalRevenue
FROM Sales s
JOIN SaleItems si ON s.SaleID = si.Sale_ID
GROUP BY s.Sale_Date
ORDER BY s.Sale_Date;
"
Bala G. - "SELECT
s.Sale_Date,
SUM(si.Quantity * si.SalePrice) AS TotalRevenue
FROM Sales s
JOIN SaleItems si ON s.SaleID = si.Sale_ID
GROUP BY s.Sale_Date
ORDER BY s.Sale_Date;
"See full answer
"CreditGO Loan App Customer-Care Number =(O)}((+917439822246=))℅+/{+O 9346281901+} CALL Now ·CreditGO Loan App Customer-Care Number =(O)}((+917439822246=))℅+/{+O 9346281901+} CALL Now ·CreditGO Loan App Customer-Care Number =(O)}((+917439822246=))℅+/{+O 9346281901+} CALL Now ·CreditGO Loan App Customer-Care Number =(O)}((+917439822246=))℅+/{+O 9346281901+} CALL Now ·"
Raj V. - "CreditGO Loan App Customer-Care Number =(O)}((+917439822246=))℅+/{+O 9346281901+} CALL Now ·CreditGO Loan App Customer-Care Number =(O)}((+917439822246=))℅+/{+O 9346281901+} CALL Now ·CreditGO Loan App Customer-Care Number =(O)}((+917439822246=))℅+/{+O 9346281901+} CALL Now ·CreditGO Loan App Customer-Care Number =(O)}((+917439822246=))℅+/{+O 9346281901+} CALL Now ·"See full answer
"with t1 as (select
customer_id,
order_date,
order_id,
rownumber() over (partition by customerid, orderdate order by orderid) as order_rnk,
count(orderid) over (partition by customerid, orderdate) as totalorders_day
from orders)
select
customer_id,
order_date,
orderid as secondearliestorderid
from t1
where totalordersday>=2 and order_rnk = 2
order by
order_date,
customer_id
"
Alexey T. - "with t1 as (select
customer_id,
order_date,
order_id,
rownumber() over (partition by customerid, orderdate order by orderid) as order_rnk,
count(orderid) over (partition by customerid, orderdate) as totalorders_day
from orders)
select
customer_id,
order_date,
orderid as secondearliestorderid
from t1
where totalordersday>=2 and order_rnk = 2
order by
order_date,
customer_id
"See full answer
"SELECT
ROUND(
COUNT(DISTINCT(CASE when eventname = 'callstarted' then user_id end)) /
COUNT(DISTINCT(CASE when eventname = 'appopen' then user_id end)) * 100)
as videocallpercentage
from activity
where DATE(date) = CURDATE() - INTERVAL 1 DAY"
Anonymous Ladybug - "SELECT
ROUND(
COUNT(DISTINCT(CASE when eventname = 'callstarted' then user_id end)) /
COUNT(DISTINCT(CASE when eventname = 'appopen' then user_id end)) * 100)
as videocallpercentage
from activity
where DATE(date) = CURDATE() - INTERVAL 1 DAY"See full answer
"WITH filtered_posts AS (
SELECT
p.user_id,
p.issuccessfulpost
FROM
post p
WHERE
p.postdate >= '2023-11-01' AND p.postdate < '2023-12-01'
),
post_summary AS (
SELECT
pu.user_type,
COUNT(*) AS post_attempt,
SUM(CASE WHEN fp.issuccessfulpost = 1 THEN 1 ELSE 0 END) AS post_success
FROM
filtered_posts fp
JOIN
postuser pu ON fp.userid = pu.user_id
GROUP BY
pu.user_type
)
SELECT
user_type,
post_success,
post_attempt,
CAST(postsuccess AS FLOAT) / postattempt AS postsuccessrate
FROM
po"
David I. - "WITH filtered_posts AS (
SELECT
p.user_id,
p.issuccessfulpost
FROM
post p
WHERE
p.postdate >= '2023-11-01' AND p.postdate < '2023-12-01'
),
post_summary AS (
SELECT
pu.user_type,
COUNT(*) AS post_attempt,
SUM(CASE WHEN fp.issuccessfulpost = 1 THEN 1 ELSE 0 END) AS post_success
FROM
filtered_posts fp
JOIN
postuser pu ON fp.userid = pu.user_id
GROUP BY
pu.user_type
)
SELECT
user_type,
post_success,
post_attempt,
CAST(postsuccess AS FLOAT) / postattempt AS postsuccessrate
FROM
po"See full answer
"We can use dictionary to store cache items so that our read / write operations will be O(1).
Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1)
Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"
Alfred O. - "We can use dictionary to store cache items so that our read / write operations will be O(1).
Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1)
Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"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
"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
"Use a representative of each, e.g. sort the string and add it to the value of a hashmap> where we put all the words that belong to the same anagram together."
Gaston B. - "Use a representative of each, e.g. sort the string and add it to the value of a hashmap> where we put all the words that belong to the same anagram together."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