The Most Asked Coding Interview Question By Big Tech!!

preview_player
Показать описание
Solution to a very popular coding interview question asked recently by Google - 2 Sum.

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

🚀 Exclusive DSA Course Vid - Click on Channel Page! 🚀

AlgoJS
Автор

There's no way google asks twosum in interviews

VedankPande
Автор

Maybe they'd give you a complement for finding this.

yyxzzx
Автор

To everyone saying Google wouldn’t ask it, I’ve done multiple coding interviews for tech companies and the first question is always something easy like this. They want to know that you have a basic grounding in programming (plenty of uni graduates still haven’t learnt anything yet since they search answers or cheat), they want to know how you approach problems in general and they want to test your knowledge of time complexity. An easy question like this lets a recruiter instantly fail your application quickly if you couldn’t do it to certain standard (without the recruiter needing to be extremely technical), the harder questions that come afterwards test knowledge of algorithms and data structures and let companies deny you for a certain role, or categorise you for different teams.

KebabTM
Автор

When you build the map, it will take you "n" steps to add an element (inserting a new element into a binary search tree, which is what a map is at base is worst case N). So every time you invoke the map.set(..) option, you have a "hidden cost" of N, making the total complexity O(N^2) in case no elements are found.

nagyzoli
Автор

I suggest you experiment with providing the intuition behind the solution up front - then walk through the solution. It makes it easier to learn in my opinion.

evanfreethy
Автор

function solution(nums, target){
let start = 0;
let end = nums.length - 1;
let res = [];
while(start <= end){
if(nums[start] + nums[end] == target){
res.put(nums[start], nums[end]);
start++;
end- -;
}else if(nums[start] + nums[end] > target){
end- -;
}else{
start++;
}
}
return res;
}

Time complexity- O(n)

nitishkumarprusty
Автор

One way to solve this is to calculate number of possible combos then use a while loop to exhaust every combo in parallel

classicjonesy
Автор

The singular of "indices" is "index"!

gavindeane
Автор

You forgot the other part of this question and that is the follow up. How do you handle large data sets that won’t fit into a single array // handle multiple data streams to allow them to run in parallel.

SirBearingtonSupporter
Автор

function solution(nums, target) {
return [0, 1]
}

complexity O(1)
you're welcome

meow
Автор

we need subtitles for your videos, much love for you <3

thecorleone
Автор

No, its not O(n). Its O(n²) what you did there. Maps use Hashmaps which have O(n) worst case complexity. Yielding O(n²) overall complexity. It is only O(n) _average_ complexity. Important difference.

FeuervogelIra
Автор

You know you grind leetcode when you know the url for this problem and level by heart.

mlguy
Автор

function solution(target, nums) {
const list = [];
for (let i = 0; i < nums.length; ++i) {
const computation = target - nums[i];
if (computation <= 0 || !nums.includes(computation)) {
continue;
}
list.push([nums.indexOf(computation), i]);
}
return list;
}

supergamerstv
Автор

Please write ✍️ condition at the top - it is convenient to have a condition in the form of text 📝 before the task. Thank you for this great content.

roman-romadin
Автор

Spelling without jumping to different parts of the code, amazing, especially for the speaker

alexanderten
Автор

function solution (nums, target) {
for (i = 0; i < nums.length; i++) {
for (j = i+1; j < nums.length; j++) {
if (nums[i]+nums[j] == target)
return [i, j];
}
}
return null;
}

zahoorahmedsayyad
Автор

simple staff hahaha

const nums = [-2, -5, 1, 15, 2, 7];
const target = 9;

function solution(nums, target) {
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) return [i, j];
}
}

return [];
}

console.log(solution(nums, target));

parisgiannoukos
Автор

i think doing it binary search style is better left and right if their sum> num right-- or sum==num left and right or left-- should be more efficient

sidharthshanu