"Function signature for reference:
def calculate(servers: List[int], k: int) -> int:
...
To resolve this, you can use binary search considering left=0 and right=max(servers) * k
so
Example:
servers=[1,4,5] First server handle 1 request in let's say 1 second, second 4 seconds and last 5 seconds.
k=10
So I want to know the minimal time to process 10 requests
Get the mid for timeline
mid = (left+right)//2 -> mid is 25
Check how many we could process
25//1 = 25 25//4=6 25//5=5 so 25 + 6 +"
Babaa - "Function signature for reference:
def calculate(servers: List[int], k: int) -> int:
...
To resolve this, you can use binary search considering left=0 and right=max(servers) * k
so
Example:
servers=[1,4,5] First server handle 1 request in let's say 1 second, second 4 seconds and last 5 seconds.
k=10
So I want to know the minimal time to process 10 requests
Get the mid for timeline
mid = (left+right)//2 -> mid is 25
Check how many we could process
25//1 = 25 25//4=6 25//5=5 so 25 + 6 +"See full answer
"Sorted the array and stored the minimum difference in a variable and then traversed the array for the pairs having minimum difference"
Aashka C. - "Sorted the array and stored the minimum difference in a variable and then traversed the array for the pairs having minimum difference"See full answer
"from collections import deque
def updateword(words, startword, end_word):
if end_word not in words:
return None # Early exit if end_word is not in the dictionary
queue = deque([(start_word, 0)]) # (word, steps)
visited = set([start_word]) # Keep track of visited words
while queue:
word, steps = queue.popleft()
if word == end_word:
return steps # Found the target word, return steps
for i in range(len(word)):
"
叶 路. - "from collections import deque
def updateword(words, startword, end_word):
if end_word not in words:
return None # Early exit if end_word is not in the dictionary
queue = deque([(start_word, 0)]) # (word, steps)
visited = set([start_word]) # Keep track of visited words
while queue:
word, steps = queue.popleft()
if word == end_word:
return steps # Found the target word, return steps
for i in range(len(word)):
"See full answer
"Requirements and Goals
Primary Goal:Store key-value pairs in a cache with efficient access (reads/writes).
Evict items based on a certain “rank,” which might reflect popularity, frequency, or custom ranking logic.
Functional Requirements:Put(key, value, rank): Insert or update a key with the given value and rank.
Get(key): Retrieve the value associated with the key if it exists.
Evict(): If the cache is at capacity, evict the item with the lowest rank (or according"
Alvis F. - "Requirements and Goals
Primary Goal:Store key-value pairs in a cache with efficient access (reads/writes).
Evict items based on a certain “rank,” which might reflect popularity, frequency, or custom ranking logic.
Functional Requirements:Put(key, value, rank): Insert or update a key with the given value and rank.
Get(key): Retrieve the value associated with the key if it exists.
Evict(): If the cache is at capacity, evict the item with the lowest rank (or according"See full answer
Engineering Manager
Coding
+1 more
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"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
"I would assume that this is similar to an intervals question. Meeting Rooms II (https://www.lintcode.com/problem/919/?fromId=203&_from=collection) on Leetcode seems like the closest comparison, it's a premium question so I linked Lintcode.
I'm assuming that we also need to just return the minimum number of cars used. You need to sort for the most optimal solution, so you're constrained by an O(nlogn) time complexity. So any sorting solution could work (using a heap, sorting the array input arra"
Sohum S. - "I would assume that this is similar to an intervals question. Meeting Rooms II (https://www.lintcode.com/problem/919/?fromId=203&_from=collection) on Leetcode seems like the closest comparison, it's a premium question so I linked Lintcode.
I'm assuming that we also need to just return the minimum number of cars used. You need to sort for the most optimal solution, so you're constrained by an O(nlogn) time complexity. So any sorting solution could work (using a heap, sorting the array input arra"See full answer
"Since the problem asks for a O(logN) solution, I have to assume that the numbers are already sorted, meaning the same number are adjacent to each other, the value of the numbers shouldn't matter, and they expect us to use Binary Search.
First, we should analyze the pattern of a regular number array without a single disrupter.
Index: 0 1 2 3 4. 5 6. 7. 8. 9
Array:[1, 1, 2, 2, 4, 4, 5, 5, 6, 6]
notice the odd indexes are always referencing the second of the reoccurring numbers and t"
Bamboo Y. - "Since the problem asks for a O(logN) solution, I have to assume that the numbers are already sorted, meaning the same number are adjacent to each other, the value of the numbers shouldn't matter, and they expect us to use Binary Search.
First, we should analyze the pattern of a regular number array without a single disrupter.
Index: 0 1 2 3 4. 5 6. 7. 8. 9
Array:[1, 1, 2, 2, 4, 4, 5, 5, 6, 6]
notice the odd indexes are always referencing the second of the reoccurring numbers and t"See full answer
"2 Approaches:
1) The more intuitive approach is doing a multi-source BFS from all cats and storing the distance of closest cats. Then do a dfs/bfs from rat to bread.
Time Complexity: O(mn + 4^L) where L is path length, worst case L could be mn
Space Complexity: O(m*n)
2) The first approach should be fine for interviews. But if they ask to optimize it further, you can use Binary Search. Problems like "Finding max of min distance" or "Finding min of max" could be usually solved by BS.
"
Karan K. - "2 Approaches:
1) The more intuitive approach is doing a multi-source BFS from all cats and storing the distance of closest cats. Then do a dfs/bfs from rat to bread.
Time Complexity: O(mn + 4^L) where L is path length, worst case L could be mn
Space Complexity: O(m*n)
2) The first approach should be fine for interviews. But if they ask to optimize it further, you can use Binary Search. Problems like "Finding max of min distance" or "Finding min of max" could be usually solved by BS.
"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
"It was like say we have a library A which has a library B as a dependency and so on, how would we determine in the dependency chain that whether there is a circular depedency?"
Chris R. - "It was like say we have a library A which has a library B as a dependency and so on, how would we determine in the dependency chain that whether there is a circular depedency?"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
"find total sum. assign that to rightsum
traverse from left to right: keep updating left sum and right sum, when they match return the index.
else if you reach end return -1 or not found"
Rahul J. - "find total sum. assign that to rightsum
traverse from left to right: keep updating left sum and right sum, when they match return the index.
else if you reach end return -1 or not found"See full answer
"Used Recursive approach to traverse the binary search tree and sum the values of the nodes that fall within the specified range [low, high]"
Srikant V. - "Used Recursive approach to traverse the binary search tree and sum the values of the nodes that fall within the specified range [low, high]"See full answer