"class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
temp = [nums[0]]
for num in nums:
if temp[-1]< num:
temp.append(num)
else:
index = bisect_left(temp,num)
temp[index] = num
return len(temp)
"
Mahima M. - "class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
temp = [nums[0]]
for num in nums:
if temp[-1]< num:
temp.append(num)
else:
index = bisect_left(temp,num)
temp[index] = num
return len(temp)
"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
"#simple solution
1.firstly find the node in the bst (O(logn) time complexity it take)
2.now removing the node consists of 3 cases:
1.if the node is leaf (no children):
(keep track of parent and do)
parent.left or parent.right=NULL
simply remove the node ()
2.if(has one child) replace the node with its child
3.if has both childs
we replace the node with either inorder predesor(max of left tree)or inorder succesor and remove
the node wh"
Sambangi C. - "#simple solution
1.firstly find the node in the bst (O(logn) time complexity it take)
2.now removing the node consists of 3 cases:
1.if the node is leaf (no children):
(keep track of parent and do)
parent.left or parent.right=NULL
simply remove the node ()
2.if(has one child) replace the node with its child
3.if has both childs
we replace the node with either inorder predesor(max of left tree)or inorder succesor and remove
the node wh"See full answer
"How do you find consecutive days for login (MySQL, SQL, date, subquery, MySQL 5.7, development)?
1
Follow
Request
Answer
More
All related (34)
Recommended
📷
Trausti Thor Johannsson
·
Follow
Been using MySQL for more than 16 yearsDec 27
There are functions like DATEDIFF but there are also BETWE"
Hayatu H. - "How do you find consecutive days for login (MySQL, SQL, date, subquery, MySQL 5.7, development)?
1
Follow
Request
Answer
More
All related (34)
Recommended
📷
Trausti Thor Johannsson
·
Follow
Been using MySQL for more than 16 yearsDec 27
There are functions like DATEDIFF but there are also BETWE"See full answer
Data Engineer
Coding
+1 more
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"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
"import java.util.*;
public class NetworkTopology {
public int topologytype(int N, int M, int[] input3, int[] input4) {
if (M != N - 1 && M != N) return -1; // Fast check for invalid cases
int[] degree = new int[N + 1]; // Degree of each node (1-based indexing)
// Build the degree array
for (int i = 0; i < M; i++) {
degree[input3[i]]++;
degree[input4[i]]++;
}
// Check for Bus Topology
boolean isBus = (M"
Alessandro R. - "import java.util.*;
public class NetworkTopology {
public int topologytype(int N, int M, int[] input3, int[] input4) {
if (M != N - 1 && M != N) return -1; // Fast check for invalid cases
int[] degree = new int[N + 1]; // Degree of each node (1-based indexing)
// Build the degree array
for (int i = 0; i < M; i++) {
degree[input3[i]]++;
degree[input4[i]]++;
}
// Check for Bus Topology
boolean isBus = (M"See full answer
"Batch Packing Problem
In Amazon’s massive warehouse inventory, there are different types of products. You are given an array products of size n, where products[i] represents the number of items of product type i. These products need to be packed into batches for shipping.
The batch packing must adhere to the following conditions:
No two items in the same batch can be of the same product type.
The number of items packed in the current batch must be strictly greater than the number pack"
Anonymous Goat - "Batch Packing Problem
In Amazon’s massive warehouse inventory, there are different types of products. You are given an array products of size n, where products[i] represents the number of items of product type i. These products need to be packed into batches for shipping.
The batch packing must adhere to the following conditions:
No two items in the same batch can be of the same product type.
The number of items packed in the current batch must be strictly greater than the number pack"See full answer
"Example:
bucket A: 3 liters capacity
bucket B: 5 liters capacity
goal: 4 liters
You are asked to print the logical sequence to get to the 4 liters of water in one bucket.
Follow up:
How would you solve the problem if you have more than 2 buckets of water?"
B. T. - "Example:
bucket A: 3 liters capacity
bucket B: 5 liters capacity
goal: 4 liters
You are asked to print the logical sequence to get to the 4 liters of water in one bucket.
Follow up:
How would you solve the problem if you have more than 2 buckets of water?"See full answer
"You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line.
Example:
S = "abracadabra sample"
K = 11
Output:
abracadabra
sample
Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"
B. T. - "You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line.
Example:
S = "abracadabra sample"
K = 11
Output:
abracadabra
sample
Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"See full answer
""""
Delete k th node from from last of LL
"""
from typing import List
class ListNode:
def init(self, val=None, next=None):
self.val = val
self.next = next
def delkthnode(start: ListNode, k: int)->ListNode:
"""
Returns success or failure
"""
have 2 pointers
#fast and slow ptr
we need to delete n-k th node
fast ptr - traverse k step
start slow ptr
remaining steps for fast ptr to cover the end is n-k
tha"
Rego Z. - """"
Delete k th node from from last of LL
"""
from typing import List
class ListNode:
def init(self, val=None, next=None):
self.val = val
self.next = next
def delkthnode(start: ListNode, k: int)->ListNode:
"""
Returns success or failure
"""
have 2 pointers
#fast and slow ptr
we need to delete n-k th node
fast ptr - traverse k step
start slow ptr
remaining steps for fast ptr to cover the end is n-k
tha"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