"public int minInsertions(String s) {
int n = s.length();
int dp = new intn;
for (int len = 2; len <= n; n++) {
for (int i = 0; i + len - 1 < n: i++) {
int j = i + len - 1;
if (s.charAt(i) == s.charAt(j)) {
dpi = dpi + 1;
} else {
dpi = 1 + Math.min(dpi + 1, dpi);
}
}
}
return dp0;
}
`"
Jatin S. - "public int minInsertions(String s) {
int n = s.length();
int dp = new intn;
for (int len = 2; len <= n; n++) {
for (int i = 0; i + len - 1 < n: i++) {
int j = i + len - 1;
if (s.charAt(i) == s.charAt(j)) {
dpi = dpi + 1;
} else {
dpi = 1 + Math.min(dpi + 1, dpi);
}
}
}
return dp0;
}
`"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
"Try not to take hints from the interviewer for solving the problem.
They may provide hints but it would impact the final decision
"
Laxman kishore K. - "Try not to take hints from the interviewer for solving the problem.
They may provide hints but it would impact the final decision
"See full answer
Software Engineer
Coding
+1 more
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"select e.firstname as firstname,
m.salary as manager_salary
from employees e join employees m on e.manager_id = m.id
where e.salary > m.salary;
`"
Ravi K. - "select e.firstname as firstname,
m.salary as manager_salary
from employees e join employees m on e.manager_id = m.id
where e.salary > m.salary;
`"See full answer
"from collections import deque
from typing import List
def longestsubarraydifflessthan_n(nums: List[int], N: int) -> int:
"""
Find the length of the longest contiguous subarray such that the difference
between any two elements in the subarray is less than N.
Equivalent condition:
max(subarray) - min(subarray) < N
Approach (Optimal):
Sliding window with two monotonic deques:
max_d: decreasing deque of indices (front is index of current max"
Ramachandra N. - "from collections import deque
from typing import List
def longestsubarraydifflessthan_n(nums: List[int], N: int) -> int:
"""
Find the length of the longest contiguous subarray such that the difference
between any two elements in the subarray is less than N.
Equivalent condition:
max(subarray) - min(subarray) < N
Approach (Optimal):
Sliding window with two monotonic deques:
max_d: decreasing deque of indices (front is index of current max"See full answer
"function longestCommonPrefix(arr1, arr2) {
const prefixSet = new Set();
for (let num of arr1) {
let str = num.toString();
for (let i = 1; i <= str.length; i++) {
prefixSet.add(str.substring(0, i));
}
}
let longestPrefix = "";
for (let num of arr2) {
let str = num.toString();
for (let i = 1; i <= str.length; i++) {
let prefix = str.substring(0, i);
if (prefixSet.has(prefix)) {
"
Maykon henrique D. - "function longestCommonPrefix(arr1, arr2) {
const prefixSet = new Set();
for (let num of arr1) {
let str = num.toString();
for (let i = 1; i <= str.length; i++) {
prefixSet.add(str.substring(0, i));
}
}
let longestPrefix = "";
for (let num of arr2) {
let str = num.toString();
for (let i = 1; i <= str.length; i++) {
let prefix = str.substring(0, i);
if (prefixSet.has(prefix)) {
"See full answer
"Here if we breakdown each dependency [A,B] , We need to check if there a cycle in Dependency Graph. If there is cycle installation is not possible, If there is no cycle installation is possible.
Steps :
1: Build the graph
2: Perform DFS based Cycle Detection
3: Check each package if those packages have cycle or not."
Venkata rakesh M. - "Here if we breakdown each dependency [A,B] , We need to check if there a cycle in Dependency Graph. If there is cycle installation is not possible, If there is no cycle installation is possible.
Steps :
1: Build the graph
2: Perform DFS based Cycle Detection
3: Check each package if those packages have cycle or not."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
"
def closest_palindrome(n: str) -> str:
"""
Finds the closest palindromic number to n (excluding itself).
Assumptions:
If two palindromes are equally close, return the smaller one.
n is a positive integer represented as a string.
Time Complexity: O(1)
Space Complexity: O(1)
"""
length = len(n)
num = int(n)
Helper to build palindrome from a prefix
def makepalindrome(prefix: int, isodd_length: bool) -> int:
s = str(prefi"
Ramachandra N. - "
def closest_palindrome(n: str) -> str:
"""
Finds the closest palindromic number to n (excluding itself).
Assumptions:
If two palindromes are equally close, return the smaller one.
n is a positive integer represented as a string.
Time Complexity: O(1)
Space Complexity: O(1)
"""
length = len(n)
num = int(n)
Helper to build palindrome from a prefix
def makepalindrome(prefix: int, isodd_length: bool) -> int:
s = str(prefi"See full answer
"Assumptions -
Multiple reader/writer threads issue set() [with transaction] and get() operations concurrently
All data can fit into memory.
Requirements -
Good performance (ex. less lock contention)
Optimize memory footprint (ex. don't store stale entries in memory)
Naive Approach -
Wrap a standard hashmap/dictionary with reader-writer lock. We can also shard the map to reduce lock contention (ex. 32 segments for 32 core cpu)
Allocate local buffer to a writer when a transacti"
Pushkar G. - "Assumptions -
Multiple reader/writer threads issue set() [with transaction] and get() operations concurrently
All data can fit into memory.
Requirements -
Good performance (ex. less lock contention)
Optimize memory footprint (ex. don't store stale entries in memory)
Naive Approach -
Wrap a standard hashmap/dictionary with reader-writer lock. We can also shard the map to reduce lock contention (ex. 32 segments for 32 core cpu)
Allocate local buffer to a writer when a transacti"See full answer
"def is_palindrome(s: str) -> bool:
new = ''
for a in s:
if a.isalpha() or a.isdigit():
new += a.lower()
return (new == new[::-1])
debug your code below
print(is_palindrome('abcba'))
`"
Anonymous Roadrunner - "def is_palindrome(s: str) -> bool:
new = ''
for a in s:
if a.isalpha() or a.isdigit():
new += a.lower()
return (new == new[::-1])
debug your code below
print(is_palindrome('abcba'))
`"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