"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
"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
"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
"
Compare alternate houses i.e for each house starting from the third, calculate the maximum money that can be stolen up to that house by choosing between:
Skipping the current house and taking the maximum money stolen up to the previous house.
Robbing the current house and adding its value to the maximum money stolen up to the house two steps back.
package main
import (
"fmt"
)
// rob function calculates the maximum money a robber can steal
func maxRob(nums []int) int {
ln"
VContaineers - "
Compare alternate houses i.e for each house starting from the third, calculate the maximum money that can be stolen up to that house by choosing between:
Skipping the current house and taking the maximum money stolen up to the previous house.
Robbing the current house and adding its value to the maximum money stolen up to the house two steps back.
package main
import (
"fmt"
)
// rob function calculates the maximum money a robber can steal
func maxRob(nums []int) int {
ln"See full answer
"I follow a variation of the RICE framework when prioritizing how I ship product features. I start by looking at:
Reach: Because the customer segmentation across our product portfolio is so similar, I tend to hold a lot of weight on product features that will maximize our customer reach with a minimal LOE.
Impact: After establishing which customer segments will benefit from the product feature, I determine the urgency and estimated impact on each customer segment based on customer i"
Ashley C. - "I follow a variation of the RICE framework when prioritizing how I ship product features. I start by looking at:
Reach: Because the customer segmentation across our product portfolio is so similar, I tend to hold a lot of weight on product features that will maximize our customer reach with a minimal LOE.
Impact: After establishing which customer segments will benefit from the product feature, I determine the urgency and estimated impact on each customer segment based on customer i"See full answer
Software Engineer
Behavioral
+8 more
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"We can use dictionary to store cache items so that our read / write operations will be O(1).
Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1)
Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"
Alfred O. - "We can use dictionary to store cache items so that our read / write operations will be O(1).
Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1)
Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"See full answer
"Use a representative of each, e.g. sort the string and add it to the value of a hashmap> where we put all the words that belong to the same anagram together."
Gaston B. - "Use a representative of each, e.g. sort the string and add it to the value of a hashmap> where we put all the words that belong to the same anagram together."See full answer
"It would have been more interesting to focus on the system design rather than the Trie DS, Interviewee could have just mentioned the Trie and passed to things more important.
Interviewee should have focused on the factors on which he wants to scale the API servers, popularity of the query parts ? region may be ? A hash of many factors ?
Caches should have definitely be discussed, Cache eviction policies, Cache invalidation managements...
Interviewee should have mentioned which kind of API pro"
Aymen D. - "It would have been more interesting to focus on the system design rather than the Trie DS, Interviewee could have just mentioned the Trie and passed to things more important.
Interviewee should have focused on the factors on which he wants to scale the API servers, popularity of the query parts ? region may be ? A hash of many factors ?
Caches should have definitely be discussed, Cache eviction policies, Cache invalidation managements...
Interviewee should have mentioned which kind of API pro"See full answer
"// C++ program to print the count of
// subsets with sum equal to the given value X
#include
using namespace std;
// Recursive function to return the count
// of subsets with sum equal to the given value
int subsetSum(int arr[], int n, int i,
int sum, int count)
{
// The recursion is stopped at N-th level
// where all the subsets of the given array
// have been checked
if (i == n) {
// Incrementing the count if sum is
// equal to 0 and returning the count
if (sum == 0)"
Ajay U. - "// C++ program to print the count of
// subsets with sum equal to the given value X
#include
using namespace std;
// Recursive function to return the count
// of subsets with sum equal to the given value
int subsetSum(int arr[], int n, int i,
int sum, int count)
{
// The recursion is stopped at N-th level
// where all the subsets of the given array
// have been checked
if (i == n) {
// Incrementing the count if sum is
// equal to 0 and returning the count
if (sum == 0)"See full answer
"#inplace reversal without inbuilt functions
def reverseString(s):
chars = list(s)
l, r = 0, len(s)-1
while l < r:
chars[l],chars[r] = chars[r],chars[l]
l += 1
r -= 1
reversed = "".join(chars)
return reversed
"
Anonymous Possum - "#inplace reversal without inbuilt functions
def reverseString(s):
chars = list(s)
l, r = 0, len(s)-1
while l < r:
chars[l],chars[r] = chars[r],chars[l]
l += 1
r -= 1
reversed = "".join(chars)
return reversed
"See full answer
"Initialize left pointer: Set a left pointer left to 0.
Iterate through the array: Iterate through the array from left to right.
If the current element is not 0, swap it with the element at the left pointer and increment left.
Time complexity: O(n). The loop iterates through the entire array once, making it linear time.
Space complexity: O(1). The algorithm operates in-place, modifying the input array directly without using additional data structures.
"
Avon T. - "Initialize left pointer: Set a left pointer left to 0.
Iterate through the array: Iterate through the array from left to right.
If the current element is not 0, swap it with the element at the left pointer and increment left.
Time complexity: O(n). The loop iterates through the entire array once, making it linear time.
Space complexity: O(1). The algorithm operates in-place, modifying the input array directly without using additional data structures.
"See full answer
"\# 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
"
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
"def find_primes(n):
lst=[]
for i in range(2,n+1):
is_prime=1
for j in range(2,int(i**0.5)+1):
if i%j==0:
is_prime=0
break
if is_prime:
lst.append(i)
return lst
"
Anonymous Raccoon - "def find_primes(n):
lst=[]
for i in range(2,n+1):
is_prime=1
for j in range(2,int(i**0.5)+1):
if i%j==0:
is_prime=0
break
if is_prime:
lst.append(i)
return lst
"See full answer