"class ListNode:
def init(self, val=0, next=None):
self.val = val
self.next = next
def has_cycle(head: ListNode) -> bool:
slow, fast = head, head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast:
return True
return False
debug your code below
node1 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(4)
creates a linked list with a cycle: 1 -> 2 -> 3 -> 4"
Anonymous Roadrunner - "class ListNode:
def init(self, val=0, next=None):
self.val = val
self.next = next
def has_cycle(head: ListNode) -> bool:
slow, fast = head, head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast:
return True
return False
debug your code below
node1 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(4)
creates a linked list with a cycle: 1 -> 2 -> 3 -> 4"See full answer
"Functional requirement's:
partial search while searching for users, products any keywords in the search.
additional keywords in the filter
Black listed words in the search.
Non functional requirements:
low latency,
search through 2 Billion records
recent search should be cached.
Design:
high reads,
we should have caching enabled over the primary db storages.
caching cluster can be added when the search load increases.
read ahead. - check in cache
(periodic cache refresh), lfu, lru
"
Sandeep Y. - "Functional requirement's:
partial search while searching for users, products any keywords in the search.
additional keywords in the filter
Black listed words in the search.
Non functional requirements:
low latency,
search through 2 Billion records
recent search should be cached.
Design:
high reads,
we should have caching enabled over the primary db storages.
caching cluster can be added when the search load increases.
read ahead. - check in cache
(periodic cache refresh), lfu, lru
"See full answer
"Use an index, two pointers, and a set to keep track of elements that you've seen.
pseudo code follows:
for i, elem in enumerate(array):
if elem in set return False
if i > N:
set.remove(array[i-N])"
Michael B. - "Use an index, two pointers, and a set to keep track of elements that you've seen.
pseudo code follows:
for i, elem in enumerate(array):
if elem in set return False
if i > N:
set.remove(array[i-N])"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
"Yes, I need to compare the first half of the first string with the reverse order of the second half of the second string. Repeat this process to the first half of the second string and the second half of the first string."
Noor M. - "Yes, I need to compare the first half of the first string with the reverse order of the second half of the second string. Repeat this process to the first half of the second string and the second half of the first string."See full answer
"a. Sort the array elements.
b. take two pointers at index 0 and index Len-1;
c. if the sum at the two pointers is target; break and return the pair
d. if the sum is smaller, then move left pointer by 1
e. else move right pointer by 1;
run the logic till the target is met or right pointer crosses the left pointer."
Komal S. - "a. Sort the array elements.
b. take two pointers at index 0 and index Len-1;
c. if the sum at the two pointers is target; break and return the pair
d. if the sum is smaller, then move left pointer by 1
e. else move right pointer by 1;
run the logic till the target is met or right pointer crosses the left pointer."See full answer
"Over-fitting of a model occurs when model fails to generalize to any new data and has high variance withing training data whereas in under fitting model isn't able to uncover the underlying pattern in the training data and high bias.
Tree based model like decision tree and random forest are likely to overfit whereas linear models like linear regression and logistic regression tends to under fit.
There are many reasons why a Random forest can overfits easily 1. Model has grown to its full depth a"
Jyoti V. - "Over-fitting of a model occurs when model fails to generalize to any new data and has high variance withing training data whereas in under fitting model isn't able to uncover the underlying pattern in the training data and high bias.
Tree based model like decision tree and random forest are likely to overfit whereas linear models like linear regression and logistic regression tends to under fit.
There are many reasons why a Random forest can overfits easily 1. Model has grown to its full depth a"See full answer
"Problem: Given a modified binary tree, where each node also has a pointer to it's parent, find the first common ancestor of two nodes.
Answer: As it happens, the structure that we're looking at is actually a linked list (one pointer up), so the problem is identical to trying to find if two linked lists share a common node.
How this works is by stacking the two chains of nodes together so they're the same length.
chain1 = node1
chain2= node2
while True:
chain1 = chain1.next
chain2=chain"
Michael B. - "Problem: Given a modified binary tree, where each node also has a pointer to it's parent, find the first common ancestor of two nodes.
Answer: As it happens, the structure that we're looking at is actually a linked list (one pointer up), so the problem is identical to trying to find if two linked lists share a common node.
How this works is by stacking the two chains of nodes together so they're the same length.
chain1 = node1
chain2= node2
while True:
chain1 = chain1.next
chain2=chain"See full answer
"Reinforcement Learning is a type of machine learning where an agent learns to make decisions by trying out different actions and receiving rewards or penalties in return. The goal is to learn, over time, which actions yield the highest rewards.
There are three core components in RL:
The agent — the learner or decision-maker (e.g., an algorithm or robot),
The environment — everything the agent interacts with,
Actions and rewards — the agent takes actions, and the environmen"
Constantin P. - "Reinforcement Learning is a type of machine learning where an agent learns to make decisions by trying out different actions and receiving rewards or penalties in return. The goal is to learn, over time, which actions yield the highest rewards.
There are three core components in RL:
The agent — the learner or decision-maker (e.g., an algorithm or robot),
The environment — everything the agent interacts with,
Actions and rewards — the agent takes actions, and the environmen"See full answer