"\# 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
"This is just a two line solve, I'm not sure why it's being made more complicated?
function productExceptSelf(nums) {
// your code goes here
const product = nums.reduce((acc, val) => acc * val, 1);
return nums.map(num => num === 0 ? 0 : Math.floor(product/num));
}
`"
Marc S. - "This is just a two line solve, I'm not sure why it's being made more complicated?
function productExceptSelf(nums) {
// your code goes here
const product = nums.reduce((acc, val) => acc * val, 1);
return nums.map(num => num === 0 ? 0 : Math.floor(product/num));
}
`"See full answer
"
from typing import List
def getnumberof_islands(binaryMatrix: List[List[int]]) -> int:
if not binaryMatrix: return 0
rows = len(binaryMatrix)
cols = len(binaryMatrix[0])
islands = 0
for r in range(rows):
for c in range(cols):
if binaryMatrixr == 1:
islands += 1
dfs(binaryMatrix, r, c)
return islands
def dfs(grid, r, c):
if (
r = len(grid)
"
Rick E. - "
from typing import List
def getnumberof_islands(binaryMatrix: List[List[int]]) -> int:
if not binaryMatrix: return 0
rows = len(binaryMatrix)
cols = len(binaryMatrix[0])
islands = 0
for r in range(rows):
for c in range(cols):
if binaryMatrixr == 1:
islands += 1
dfs(binaryMatrix, r, c)
return islands
def dfs(grid, r, c):
if (
r = len(grid)
"See full answer
"function findPrimes(n) {
if (n < 2) return [];
const primes = [];
for (let i=2; i <= n; i++) {
const half = Math.floor(i/2);
let isPrime = true;
for (let prime of primes) {
if (i % prime === 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.push(i);
}
}
return primes;
}
`"
Tiago R. - "function findPrimes(n) {
if (n < 2) return [];
const primes = [];
for (let i=2; i <= n; i++) {
const half = Math.floor(i/2);
let isPrime = true;
for (let prime of primes) {
if (i % prime === 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.push(i);
}
}
return primes;
}
`"See full answer
Data Engineer
Data Structures & Algorithms
+4 more
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"from typing import List
def three_sum(nums: List[int]) -> List[List[int]]:
nums.sort()
triplets = set()
for i in range(len(nums) - 2):
firstNum = nums[i]
l = i + 1
r = len(nums) - 1
while l 0:
r -= 1
elif potentialSum < 0:
l += 1
"
Anonymous Roadrunner - "from typing import List
def three_sum(nums: List[int]) -> List[List[int]]:
nums.sort()
triplets = set()
for i in range(len(nums) - 2):
firstNum = nums[i]
l = i + 1
r = len(nums) - 1
while l 0:
r -= 1
elif potentialSum < 0:
l += 1
"See full answer
"const ops = {
'+': (a, b) => a+b,
'-': (a, b) => a-b,
'/': (a, b) => a/b,
'': (a, b) => ab,
};
function calc(expr) {
// Search for + or -
for (let i=expr.length-1; i >= 0; i--) {
const char = expr.charAt(i);
if (['+', '-'].includes(char)) {
return opschar), calc(expr.slice(i+1)));
}
}
// Search for / or *
for (let i=expr.length-1; i >= 0; i--) {
const char = expr.charAt(i);
if"
Tiago R. - "const ops = {
'+': (a, b) => a+b,
'-': (a, b) => a-b,
'/': (a, b) => a/b,
'': (a, b) => ab,
};
function calc(expr) {
// Search for + or -
for (let i=expr.length-1; i >= 0; i--) {
const char = expr.charAt(i);
if (['+', '-'].includes(char)) {
return opschar), calc(expr.slice(i+1)));
}
}
// Search for / or *
for (let i=expr.length-1; i >= 0; i--) {
const char = expr.charAt(i);
if"See full answer
"I would define success by first figuring out what our goal is by building the reels feature. Are we trying to increase DAUs? Increase enagement? Etc... For the sake of this, I think to define success it makes most sense to see if there is an increase in the amount of time users are spending on instagram. If time spent per user increases, it is likely that ad spend can increase and in turn increases instagram's reveue.
We need to be sure that there are guard rails in place and make sure that by"
Josh L. - "I would define success by first figuring out what our goal is by building the reels feature. Are we trying to increase DAUs? Increase enagement? Etc... For the sake of this, I think to define success it makes most sense to see if there is an increase in the amount of time users are spending on instagram. If time spent per user increases, it is likely that ad spend can increase and in turn increases instagram's reveue.
We need to be sure that there are guard rails in place and make sure that by"See full answer
"Arrays.sort(inputarray)
sliding window with a size of 2.
Check for the sum in the sliding window.
subtract the start when window moves"
Sridhar R. - "Arrays.sort(inputarray)
sliding window with a size of 2.
Check for the sum in the sliding window.
subtract the start when window moves"See full answer
"Problem Statement: The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2) with F(0) = 1 and F(1) = 1.
The solution is given in the problem statement itself.
If the value of n = 0, return 1.
If the value of n = 1, return 1.
Otherwise, return the sum of data at (n - 1) and (n - 2).
Explanation: The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, typically starting with 0 and 1.
Java Solution:
public static int fib(int n"
Rishi G. - "Problem Statement: The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2) with F(0) = 1 and F(1) = 1.
The solution is given in the problem statement itself.
If the value of n = 0, return 1.
If the value of n = 1, return 1.
Otherwise, return the sum of data at (n - 1) and (n - 2).
Explanation: The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, typically starting with 0 and 1.
Java Solution:
public static int fib(int 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
"This may seem tricky at first, but this is actually an Expansion problem, since we're expanding to a new market. The only difference is this is specifically for small businesses within that market. This is the formula you should use when tackling these types of interview questions:
Ask clarifying questions
Perform user analysis
Market risk analysis
State goals
Perform channel analysis
Prioritize growth channels
Strategy
Summarize
Witho"
Exponent - "This may seem tricky at first, but this is actually an Expansion problem, since we're expanding to a new market. The only difference is this is specifically for small businesses within that market. This is the formula you should use when tackling these types of interview questions:
Ask clarifying questions
Perform user analysis
Market risk analysis
State goals
Perform channel analysis
Prioritize growth channels
Strategy
Summarize
Witho"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
"int main()
{
int a1[7]={1,2,3,4,5,6,7};
int a2[7]={1,9,10,11,12,13,14};
vectorv;
v.insert(v.begin(),begin(a1),end(a1));
v.insert(v.begin(),begin(a2),end(a2));
int a3[v.size()];
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
a3[i]=v[i];
}
}
`"
Aryan D. - "int main()
{
int a1[7]={1,2,3,4,5,6,7};
int a2[7]={1,9,10,11,12,13,14};
vectorv;
v.insert(v.begin(),begin(a1),end(a1));
v.insert(v.begin(),begin(a2),end(a2));
int a3[v.size()];
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
a3[i]=v[i];
}
}
`"See full answer
"I would start with the company vision then assuming we have more than one product team, craft the vision for the product through a collaboration of PMs and Tech leads, then based on that I will define the scope of each product team's milestones to achieve the product vision and go from both ends to fill the gap from what we already have and what needed to achieve the milestones."
Seyed rasoul J. - "I would start with the company vision then assuming we have more than one product team, craft the vision for the product through a collaboration of PMs and Tech leads, then based on that I will define the scope of each product team's milestones to achieve the product vision and go from both ends to fill the gap from what we already have and what needed to achieve the milestones."See full answer