JavaScript interview with a LinkedIn engineer: Two sum

preview_player
Показать описание


Рекомендации по теме
Комментарии
Автор

27:50 what are they building in the background. spaceship??

gsb
Автор

damn i hope i get this question when i get my interview lol

kibi.mp
Автор

It’s a sliding window problem. But the guy has first solution stuck in his mind. Just need to start clean slate

Spdroo
Автор

i've just started to learn JS and thought i would give this problem a try. i think my solution is slightly more optimal timewise than the one in the video. if not, let me know

function pairWithGivenDifference( arr, diff )
{
let set = new Set();
let len = arr.length;

for( let i = 0; i < len; i++ )
{
let curval = arr[i];
if( set.has( curval ) ) {
let j = curval + (( set.has(curval - diff - diff) )? -diff: diff);

return [curval, j];
}
else {
set.add(curval + diff);
set.add(curval - diff);
}
}

return [];
}

mazthespaz
Автор

what do you think about this solution:

const checkdifference = (list, diff) => {
const pair = [];
const subDif = list.map(x => x - diff)
subDif.forEach(x => {
let check = list.includes(x)
if (check) {
pair.push( x + diff, x);
}
})
return pair;
}

georgepappas
Автор

We might be having a problem in the second question. The code seems to still have a bug

NormanBarasa
Автор

Glad you are sharing this ! Thank you.

DevsLikeUs
Автор

90% of companies should not have anyone writing a binary tree. Linkedin is an outlier. This is a special case for an interview.

nathansire