"check the count of both sentences if the same then start loop on words count and check the presence of words are the same."
Suleman A. - "check the count of both sentences if the same then start loop on words count and check the presence of words are the same."See full answer
"function knapsack(weights, values, cap) {
const indicesByValue = Object.keys(weights).map(weight => parseInt(weight));
indicesByValue.sort((a, b) => values[b]-values[a]);
const steps = new Map();
function knapsackStep(cap, sack) {
if (steps.has(sack)) {
return steps.get(sack);
}
let maxOutput = 0;
for (let index of indicesByValue) {
if (!sack.has(index) && weights[index] <= cap) {
maxOutput ="
Tiago R. - "function knapsack(weights, values, cap) {
const indicesByValue = Object.keys(weights).map(weight => parseInt(weight));
indicesByValue.sort((a, b) => values[b]-values[a]);
const steps = new Map();
function knapsackStep(cap, sack) {
if (steps.has(sack)) {
return steps.get(sack);
}
let maxOutput = 0;
for (let index of indicesByValue) {
if (!sack.has(index) && weights[index] <= cap) {
maxOutput ="See full answer
"from typing import List
def productExceptSelf(nums: List[int]) -> List[int]:
if len(nums) <= 1:
raise Exception("nums must contain at least 2 items.")
Initialize totalProduct to the first number in nums. Later, we will populate this
as the product of ALL numbers in nums.
totalProduct = nums[0] if nums[0] != 0 else 1
If there is more than 1 zero in nums, all products will end up zero.
But if there's only 1 zero, there will be 1 nonzer"
Gemma S. - "from typing import List
def productExceptSelf(nums: List[int]) -> List[int]:
if len(nums) <= 1:
raise Exception("nums must contain at least 2 items.")
Initialize totalProduct to the first number in nums. Later, we will populate this
as the product of ALL numbers in nums.
totalProduct = nums[0] if nums[0] != 0 else 1
If there is more than 1 zero in nums, all products will end up zero.
But if there's only 1 zero, there will be 1 nonzer"See full answer
"
read_dir(path: str) -> list[str] returns the full path of all files and sub- directories of a given directory.
is_file(path: str) -> bool: returns true if the path points to a regular file.
is_dir(path: str) -> bool: returns true if the path points to a directory.
read_file(path: str) -> str: reads and returns the content of the file.
The algorithm: notice that storing all the file contents' is too space intensive, so we can't read all the files' contents to store and compare with each"
Idan R. - "
read_dir(path: str) -> list[str] returns the full path of all files and sub- directories of a given directory.
is_file(path: str) -> bool: returns true if the path points to a regular file.
is_dir(path: str) -> bool: returns true if the path points to a directory.
read_file(path: str) -> str: reads and returns the content of the file.
The algorithm: notice that storing all the file contents' is too space intensive, so we can't read all the files' contents to store and compare with each"See full answer
"Leetcode 347: Heap + Hashtable
Follow up question: create heap with the length of K instead of N (more time complexity but less space )"
Chen J. - "Leetcode 347: Heap + Hashtable
Follow up question: create heap with the length of K instead of N (more time complexity but less space )"See full answer
"def findAlibaba(countOfRooms, strategy):
#countofrooms: num rooms
#listRooms rooms to look for alibabba
possiblePlaces = []
#initialize rooms
for i in range(countOfRooms):
possiblePlaces.append(True)
for i in range(len(strategy)):
roomToCheck = strategy[i]
#Room is marked as unavailable
possiblePlaces[roomToCheck] = False
#Next day calculatins
nextDayPlaces = []
for j in range(countOfRooms):
nextDayPla"
JOBHUNTER - "def findAlibaba(countOfRooms, strategy):
#countofrooms: num rooms
#listRooms rooms to look for alibabba
possiblePlaces = []
#initialize rooms
for i in range(countOfRooms):
possiblePlaces.append(True)
for i in range(len(strategy)):
roomToCheck = strategy[i]
#Room is marked as unavailable
possiblePlaces[roomToCheck] = False
#Next day calculatins
nextDayPlaces = []
for j in range(countOfRooms):
nextDayPla"See full answer
"I first asked few clarifying questions like the return array may need not contain the list of building in the same order, to which the interviewer agreed.
Then I came up with an approach where we iterate the array from right to left and keep a max variable which will keep the value of the current max. When we find an item which is greater than max we update the max and add this element into our solution. The interviewer agreed for the approach.
I discussed few corner scenarios with the interview"
Rishabh N. - "I first asked few clarifying questions like the return array may need not contain the list of building in the same order, to which the interviewer agreed.
Then I came up with an approach where we iterate the array from right to left and keep a max variable which will keep the value of the current max. When we find an item which is greater than max we update the max and add this element into our solution. The interviewer agreed for the approach.
I discussed few corner scenarios with the interview"See full answer
"I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."
Mourya C. - "I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."See full answer
"Definitely nice to think of this without memorization, but there is a well known algorithm for this problem, which is the Levenshtein Distance.
Lev(a,b) = len(a) if len(b) == 0
= len(b) if len(a) == 0
= lev(a[1:], b[1:] if a[0] == b[0]
= 1 + min (lev(a, b[1:]), lev(a[1:], b), lev(a[1:], b[1:]))
https://en.wikipedia.org/wiki/Levenshtein_distance
I'm sure some optimizations could be made with heuristic."
Nicholas S. - "Definitely nice to think of this without memorization, but there is a well known algorithm for this problem, which is the Levenshtein Distance.
Lev(a,b) = len(a) if len(b) == 0
= len(b) if len(a) == 0
= lev(a[1:], b[1:] if a[0] == b[0]
= 1 + min (lev(a, b[1:]), lev(a[1:], b), lev(a[1:], b[1:]))
https://en.wikipedia.org/wiki/Levenshtein_distance
I'm sure some optimizations could be made with heuristic."See full answer
"let str = 'this is a test of programs';
let obj={};
for (let s of str )
obj[s]?(obj[s]=obj[s]+1):(obj[s]=1)
console.log(JSON.stringify(obj))"
Anonymous Emu - "let str = 'this is a test of programs';
let obj={};
for (let s of str )
obj[s]?(obj[s]=obj[s]+1):(obj[s]=1)
console.log(JSON.stringify(obj))"See full answer