"`#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
"A much better solution than the one in the article, below:
It looks like the ones writing articles here in Javascript do not understand the time/space complexity of javascript methods.
shift, splice, sort, etc... In the solution article you have a shift and a sort being done inside a while, that is, the multiplication of Ns.
My solution, below, iterates through the list once and then sorts it, separately. It´s O(N+Log(N))
class ListNode {
constructor(val = 0, next = null) {
th"
Guilherme F. - "A much better solution than the one in the article, below:
It looks like the ones writing articles here in Javascript do not understand the time/space complexity of javascript methods.
shift, splice, sort, etc... In the solution article you have a shift and a sort being done inside a while, that is, the multiplication of Ns.
My solution, below, iterates through the list once and then sorts it, separately. It´s O(N+Log(N))
class ListNode {
constructor(val = 0, next = null) {
th"See full answer
Software Engineer
Coding
+4 more
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"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
"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
"function areSentencesSimilar(sentence1, sentence2, similarPairs) {
if (sentence1.length !== sentence2.length) return false;
for (let i=0; i (w1 === word1 && !visited.has(w2)) || (w2 === word1 && !visited.has(w1)));
if (!edge) {
"
Tiago R. - "function areSentencesSimilar(sentence1, sentence2, similarPairs) {
if (sentence1.length !== sentence2.length) return false;
for (let i=0; i (w1 === word1 && !visited.has(w2)) || (w2 === word1 && !visited.has(w1)));
if (!edge) {
"See full answer
"A red-black tree is a self-balancing binary search tree. The motivation for this is that the benefits of O(logN) search, insertion, and deletion that a binary tree provides us will disappear if we let the tree get too "imbalanced" (e.g. there are too many nodes on one side of the tree or some branches have a depth that is way out of proportion to the average branch depth). This imbalance will occur if we don't adjust the tree after inserting or deleting nodes, hence our need for self-balancing c"
Alex M. - "A red-black tree is a self-balancing binary search tree. The motivation for this is that the benefits of O(logN) search, insertion, and deletion that a binary tree provides us will disappear if we let the tree get too "imbalanced" (e.g. there are too many nodes on one side of the tree or some branches have a depth that is way out of proportion to the average branch depth). This imbalance will occur if we don't adjust the tree after inserting or deleting nodes, hence our need for self-balancing c"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
"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
"
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
"Hi, my solution gives the exact numerical values as the proposed solution, but it doesn't pass the tests. Am I missing something, or is this a bug?
def findrevenueby_city(transactions: pd.DataFrame,
users: pd.DataFrame,
exchange_rate: pd.DataFrame) -> pd.DataFrame:
gets user city for each user id
userids = users[['id', 'usercity']]
and merge on transactions
transactions = transactions.merge(user_ids, how='left"
Gabriel P. - "Hi, my solution gives the exact numerical values as the proposed solution, but it doesn't pass the tests. Am I missing something, or is this a bug?
def findrevenueby_city(transactions: pd.DataFrame,
users: pd.DataFrame,
exchange_rate: pd.DataFrame) -> pd.DataFrame:
gets user city for each user id
userids = users[['id', 'usercity']]
and merge on transactions
transactions = transactions.merge(user_ids, how='left"See full answer
"Schema is wrong - id from product is mapped to id from transactions, id from product should point to product_id in transcations table"
Arshad P. - "Schema is wrong - id from product is mapped to id from transactions, id from product should point to product_id in transcations table"See full answer