"WITH logins AS(SELECT
user_id,
timestamp,
RANK() OVER(PARTITION BY userid ORDER BY timestamp ASC) AS loginorder
FROM useractivitylog
WHERE activity_type = 'LOGIN')
SELECT
l1.user_id,
l1.timestamp AS current_login,
l2.timestamp AS previous_login,
(strftime('%s', l1.timestamp) - strftime('%s', l2.timestamp)) / 60 AS minutes_elapsed
FROM logins AS l1
JOIN logins AS l2
ON l1.userid = l2.userid
AND l1.loginorder - l2.loginorder = 1
GROUP BY l1.user_id,"
Alvin P. - "WITH logins AS(SELECT
user_id,
timestamp,
RANK() OVER(PARTITION BY userid ORDER BY timestamp ASC) AS loginorder
FROM useractivitylog
WHERE activity_type = 'LOGIN')
SELECT
l1.user_id,
l1.timestamp AS current_login,
l2.timestamp AS previous_login,
(strftime('%s', l1.timestamp) - strftime('%s', l2.timestamp)) / 60 AS minutes_elapsed
FROM logins AS l1
JOIN logins AS l2
ON l1.userid = l2.userid
AND l1.loginorder - l2.loginorder = 1
GROUP BY l1.user_id,"See full answer
"public class HashMap {
public class Element {
T key;
V value;
Element(T k, V v) {
this.key = k;
this.value = v;
}
}
private static final int DEFAULT_CAPACITY = 16;
private static final float LOAD_FACTOR = 0.75f;
private LinkedList[] table = new LinkedList[DEFAULT_CAPACITY];
private int size = 0;
private int threshold = (int) (DEFAULTCAPACITY * LOADFACTOR);
public void put(T k"
Md kamrul H. - "public class HashMap {
public class Element {
T key;
V value;
Element(T k, V v) {
this.key = k;
this.value = v;
}
}
private static final int DEFAULT_CAPACITY = 16;
private static final float LOAD_FACTOR = 0.75f;
private LinkedList[] table = new LinkedList[DEFAULT_CAPACITY];
private int size = 0;
private int threshold = (int) (DEFAULTCAPACITY * LOADFACTOR);
public void put(T k"See full answer
"I couldn't follow the solution offered here, but my solution seemed to pass 6/6 tests. Any feedback is welcome, thank you!
def encrypt(word):
en_word = ""
for i in range(len(word)):
if i == 0:
en_word += chr(ord(word[0])+1)
else:
num = ord(word[i]) + ord(en_word[i-1])
while num > 122:
num -= 26
en_word += chr(num)
return en_word
def decrypt(word):
de_word = ""
for i in range(len(word)):
if i == 0:
de_word += chr(ord(word[i]"
Anonymous Armadillo - "I couldn't follow the solution offered here, but my solution seemed to pass 6/6 tests. Any feedback is welcome, thank you!
def encrypt(word):
en_word = ""
for i in range(len(word)):
if i == 0:
en_word += chr(ord(word[0])+1)
else:
num = ord(word[i]) + ord(en_word[i-1])
while num > 122:
num -= 26
en_word += chr(num)
return en_word
def decrypt(word):
de_word = ""
for i in range(len(word)):
if i == 0:
de_word += chr(ord(word[i]"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
"https://www.geeksforgeeks.org/find-local-minima-array/
I coded O(N) but after that gave a binary approach aswell.
After that he also gave a varient of this problem in which, local minima means that the number is strictly less than its adjacent (we cannot do binary search there sample test case [1,1,1,1,1,1,0,1] or [1,0,1,1,1,1,1,1] using mid we cannot determine if the minima is on left or right). we have to do a linear search or find recursively."
Anonymous Porcupine - "https://www.geeksforgeeks.org/find-local-minima-array/
I coded O(N) but after that gave a binary approach aswell.
After that he also gave a varient of this problem in which, local minima means that the number is strictly less than its adjacent (we cannot do binary search there sample test case [1,1,1,1,1,1,0,1] or [1,0,1,1,1,1,1,1] using mid we cannot determine if the minima is on left or right). we have to do a linear search or find recursively."See full answer
"We are asked to calculate Sum(over value) for time in (t - window_size, t) where key in (key criteria).
To develop a function to set this up.
Let w be the window size. I would have an observer of some kind note the key-value, and for the first w windows just add the value to a temporary variable in memory if the key meets the key criteria. Then it would delete the oldest value and add the new value if the new key meets the criteria. At each step after "w", we would take the sum / w and store"
Prashanth A. - "We are asked to calculate Sum(over value) for time in (t - window_size, t) where key in (key criteria).
To develop a function to set this up.
Let w be the window size. I would have an observer of some kind note the key-value, and for the first w windows just add the value to a temporary variable in memory if the key meets the key criteria. Then it would delete the oldest value and add the new value if the new key meets the criteria. At each step after "w", we would take the sum / w and store"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
"select DISTINCT p.product_id,
p.product_name ,
CASE when sale_date is null then 'Not Sold'
else 'Sold'
END as sale_status
from products p
left join sales s
on p.productid= s.productid
`"
Gowtami K. - "select DISTINCT p.product_id,
p.product_name ,
CASE when sale_date is null then 'Not Sold'
else 'Sold'
END as sale_status
from products p
left join sales s
on p.productid= s.productid
`"See full answer
"Test case is wrong. It expects to sort in asc order of month_year.
-- Write your query here
SELECT
strftime('%Y-%m', createdat) AS monthyear,
COUNT(DISTINCT userid) AS numcustomers,
COUNT(t.id) AS num_orders,
SUM(price * quantity) AS order_amt
FROM
transactions t
INNER JOIN products p
ON t.product_id = p.id
GROUP BY
month_year
ORDER BY
month_year
;
"
Aneesha K. - "Test case is wrong. It expects to sort in asc order of month_year.
-- Write your query here
SELECT
strftime('%Y-%m', createdat) AS monthyear,
COUNT(DISTINCT userid) AS numcustomers,
COUNT(t.id) AS num_orders,
SUM(price * quantity) AS order_amt
FROM
transactions t
INNER JOIN products p
ON t.product_id = p.id
GROUP BY
month_year
ORDER BY
month_year
;
"See full answer
"WITH suspicious_transactions AS (
SELECT
c.first_name,
c.last_name,
t.receipt_number,
COUNT(t.receiptnumber) OVER (PARTITION BY c.customerid) AS noofoffences
FROM
customers c
JOIN
transactions t ON c.customerid = t.customerid
WHERE
t.receipt_number LIKE '%999%'
OR t.receipt_number LIKE '%1234%'
OR t.receipt_number LIKE '%XYZ%'
)
SELECT
first_name,
last_name,
receipt_number,
noofoffences
FROM
suspicious_transactions
WHERE
noofoffences >= 2;"
Jayveer S. - "WITH suspicious_transactions AS (
SELECT
c.first_name,
c.last_name,
t.receipt_number,
COUNT(t.receiptnumber) OVER (PARTITION BY c.customerid) AS noofoffences
FROM
customers c
JOIN
transactions t ON c.customerid = t.customerid
WHERE
t.receipt_number LIKE '%999%'
OR t.receipt_number LIKE '%1234%'
OR t.receipt_number LIKE '%XYZ%'
)
SELECT
first_name,
last_name,
receipt_number,
noofoffences
FROM
suspicious_transactions
WHERE
noofoffences >= 2;"See full answer