Google Coding Interview With A Competitive Programmer

Google Coding Interview With A Competitive Programmer

Clément Mihailescu

4 года назад

2,512,129 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Tsarssa
Tsarssa - 08.09.2023 15:37

Only 33 people liked the video, that says a lot.

Ответить
KingOfTheJuice666
KingOfTheJuice666 - 01.09.2023 05:37

Moral of this story, and how to ace any interview:

Be way smarter, better at maths, and a more experienced programmer than the person interviewing you 😂

Ответить
1C3_8RE4K3R
1C3_8RE4K3R - 30.08.2023 20:28

con quel ciuffo...

Ответить
John Thompson
John Thompson - 03.08.2023 04:48

The first problem is actually easily solvable in O(6)

Ответить
Parag g Goyal
Parag g Goyal - 25.06.2023 22:46

I dont get it why cant we just choose 2 corners

Ответить
Kyle
Kyle - 12.05.2023 11:23

Someone remind me in a year so i can rewatch this and see if i have a clue whats going on

Ответить
Alfonso Rodriguez
Alfonso Rodriguez - 11.05.2023 06:32

I didn’t get to program when I went to school but I went to college and got a masters degree in mathematics. I am noticing that when programmers talk about algorithms, they really mean the same thing we call algorithms in math. A set of steps to compute the answer to a problem. Why don’t they just hire a mathematician to do the algorithms and a programmer to write the algorithm into computer language. Am I missing something. Sorry for being old and stupid.

Ответить
Nicolas Blume
Nicolas Blume - 23.04.2023 22:54

Anyone else who had an Ad from AlgoExpert before this video? 😂

Ответить
Robert Ospara
Robert Ospara - 21.02.2023 21:23

The whole truth about the problem is based on example given by interviewer - not good approach.

Ответить
Rahul Dravid
Rahul Dravid - 20.02.2023 18:58

I have an idea for 2nd problem
Just rotate the axis and perform the initial code

Ответить
Bahadır TAŞPINAR
Bahadır TAŞPINAR - 16.02.2023 20:08

Dude starts his answer with “I’m not sure if you’re aware but I’m quite good at computational geometry..” bro what the hell is computational geometry

Ответить
Ashish Verma
Ashish Verma - 03.02.2023 20:28

very nice question

Ответить
Mushishi2872
Mushishi2872 - 30.01.2023 17:33

For the second question we can compare the midpoints and the square of lengths (Δx^2 + Δy^2, to avoid rounding error from sqrt) for all pairs of points, because rectangles have the property that their diagonals have equal length and meet at the midpoint, the complexity would be O(n^2).

Ответить
Yibo Chen
Yibo Chen - 20.01.2023 02:54

The second question can be solved similarly as the first one I think. Instead of limiting to p.x == p_above.x, and creating count([p.y, p_above.y]), let's do count(slope) on every two points which one is higher than the other. Then do a check when you find the same slope, see whether these four points with two same slope can create a rectangle or just a parallelogram. Then it becomes O(N^2) again. Am I right? Looking forward to replies.

Ответить
Ton grand oncle
Ton grand oncle - 18.01.2023 22:52

i am very much a beginner, i have no idea what he is saying but it's kinda mesmerizing

Ответить
Nick
Nick - 13.01.2023 17:02

Hi. For the diagonal vectors, there should be only a small number of vector steps to check to find points inside the coords. If you keep the value of one of the vector numbers equals 1 and use these vectors multiple times as long as you stay inside the coords you should have all possabilitys. You can jump 1 to the right and 2 up with the vector a = (1,2). To keep the angle = 90°, you have to jump with the rotated vector b = a_rot = (-2,1) 2 to the left and 1 up. Afterwards you must jump with the vector -a = (-1, -2) 1 to the left abd 2 down. If all points are inside the coordinates, then you have a valid rectangle. You have to check if you can move through all small vectors with multiples of the vector. You make the vector a jump n times (2 in this case) and jump (1,2) x n(=2) = 2 to the right and 4 up . Theoretically, there should be as many rectangles with a = (2,1) as with a = (1,2) and you could just x2 the result. after (1,2) you need to continue with (1,3) and increase the last number as long as you land inside the coords.

Ответить
Grad Sys
Grad Sys - 07.01.2023 00:38

You have to compare p.y and p_above.y as well.
The code is incomplete.

Ответить
Assembly x86
Assembly x86 - 05.01.2023 20:38

Amazing

Ответить
LetUsEngineerMaterials
LetUsEngineerMaterials - 30.12.2022 07:02

Waw, chatGPT solved the same problem in just one line with combinametrics approach. Image what 3 yrs progress has done to ladder up.

➡QUESTION: Given (x,y) cartesian coordinate points in xy-plane. write a function to determine how many rectangles can be formed on the plane?

➡SOLVED: def num_rectangles(m: int, n: int) -> int:
return m * (m + 1) * n * (n + 1) // 4


➡ This function has a time complexity of O(1), as it only performs a constant number of operations regardless of the input size.

➡Explanation: 🔹To count the number of rectangles that can be formed on a cartesian plane, we can use a combinatorial approach. There are 'm' ways to choose the length of the rectangle and 'n' ways to choose the width. Therefore, the total number of rectangles is 'm * n'.

🔹However, this counts each rectangle multiple times, as the same rectangle can be obtained by swapping the length and width. To correct for this, we divide the result by 2: (m * n) // 2.


🔹However, this still overcounts rectangles that have the same area but different dimensions (e.g. a 2x3 rectangle and a 3x2 rectangle both have an area of 6). To correct for this, we divide the result by another 2: '((m * n) // 2) // 2 = (m * n) // 4'.

🔹Finally, to account for the fact that the dimensions of the rectangles can also be reversed (e.g. a 2x3 rectangle is different from a 3x2 rectangle), we multiply the result by the number of ways to choose each dimension: '(m * n) // 4 * m * n = m * (m + 1) * n * (n + 1) // 4'.

Ответить
DougL
DougL - 29.12.2022 22:19

These coding interviews are masked iq tests.

Ответить
Stefan Redlich
Stefan Redlich - 11.12.2022 04:16

Not sure, but couldn't you also solve problem 2 by just making diagonal lines from left to right and from right to left and then look for parallelograms where only the distance between the opposing sides needs be identical and within the boundaries of the XY grid??? Is that possible and if it is is that easier? Just like from a logical pov

Ответить
shank 087
shank 087 - 02.12.2022 18:39

Took a day to understand this question 🤢

Ответить
Masquerati Macarade
Masquerati Macarade - 27.11.2022 14:23

Squares are rectangles, yes.

Not all rectangles are squares.

Ответить
Suryansh Dey
Suryansh Dey - 17.11.2022 17:04

Lol😂 . Dude it's a simple permutation combination problem!! answer is w*(w-1)*h*(h-1)/4 where w is numbers of points in width and h is numbers of points in height. Eg. Ur pasted points had a width of 3 points and height of 2 so answer is 3*2*2*1/4=3. Simple! (I am 12th student preparing for JEE Advanced. i don't know coding)

Ответить
basir ahmed
basir ahmed - 13.11.2022 14:19

since last month i watch every day this guy Errichto i just love this guy the way he solves the problem and think. i love his confidence and he is the coolest and humble guy i have ever seen

Ответить
asdfgsf
asdfgsf - 04.11.2022 14:22

You can actually have a pair of ints as a the key in a map in C++ without defining a hash function. You can convert it into a string of a, b instead. As long as you're using it just as a key then it should work.

Ответить
asdfgsf
asdfgsf - 03.11.2022 19:38

make_pair is a C++ STL function. Would I have to implement that in an interview?

Ответить
Luis Camacho
Luis Camacho - 01.11.2022 05:50

There is more IQ in this interview than in the entire venezuelan population

Ответить
brij mohan Soni
brij mohan Soni - 18.09.2022 23:10

Hi brother ,,i am 16 year old i complete python coading in ideal ,,😉😉😉😉😉😉

Ответить
abdou Eng
abdou Eng - 21.08.2022 06:37

I can't believe this guy wasn't hired by google , wtf are they expecting a guy that creates an other universe or something

Ответить
Assunta Marie Gozum
Assunta Marie Gozum - 15.08.2022 16:35

Great

Ответить
Valentin Gololobov
Valentin Gololobov - 11.08.2022 01:42

IMHO the better solution is to create a hashmap of vectors, where the key of the hashmap is an angle between vector and one of the axis
after this step you will end up with sets of parallel vectors and you can either find matching vectors from angle +90deg set or just by checking angle between vectors starting points and their lengths, which can be precalculated on the first step , and can be used as a key of a nested hashmap which will give you constant lookup time

Ответить
Saeed
Saeed - 09.08.2022 23:09

Naïve solution.
what if you have just two points below and above then your answer would be 1 but it's wrong, there are no square or rectangle,
if you have 1000,000 points then the solution complexity would be 1000,000 * 1000,000 that most probably would be the problematic.
The most important parts in algorithms is caring corner cases and huge amount of entries.

Ответить
Maria Mytha Nubla
Maria Mytha Nubla - 04.08.2022 07:15

What a great idea

Ответить
OFFICIAL XINFAI
OFFICIAL XINFAI - 30.07.2022 16:21

Ok

Ответить
April Valenzuela
April Valenzuela - 25.07.2022 11:31

google :)

Ответить
Jhona De guzman
Jhona De guzman - 24.07.2022 14:32

This is so helpful therefore I have find my lost account

Ответить
Jhona De guzman
Jhona De guzman - 24.07.2022 14:31

That was an great Idea because of that now i already find my lost account thank you so much

Ответить
Boikobo Nokane
Boikobo Nokane - 20.07.2022 23:20

😂 You guys call squares rectangles or am I the lost one

Ответить
bikram
bikram - 19.07.2022 08:17

Can we do rotation of each point about origin by 45 degree and use same approach the first one like following?

def rotate45(x, y):
return x - y, x + y

Notice that there should be division by root2 but we can scale by same amount to keep it integer. Let me know if this solution is right.

Ответить
Jerome Delara
Jerome Delara - 18.07.2022 19:48

.

Ответить
Julianna Mej Ortiz
Julianna Mej Ortiz - 16.07.2022 10:15

good good good buddy

Ответить
Diego Crespo
Diego Crespo - 13.07.2022 07:26

With respect, this kind of interviews are just useless, write some less or more complex algoritihm its just one part of many, you should know from system architecture to how do you understand what the client really needs, between them you have frameworks, languages, methodologies, how testeable is your code and lot more.

Ответить
I am vasu
I am vasu - 11.07.2022 18:11

Great to see this interview..
i tried to find out the total count of diagonal rectangles...

pseudo code for diagonals
store all pointers in set for search..
// Creating TreeSet containing elements
TreeSet<Pair> store = new TreeSet<>();

// Inserting the pairs in the set
for (int i = 0; i < ob.length; ++i) {
store.add(ob[i]);
}

now apply below formula in loop
for (int i = 0; i < ob.length; ++i) {
for (int j = 0; j < ob.length; ++j) {
Check below 4 points there in it
-- Formula--
1st point a[i][j] is there
2nd point check a[i+1][j+1] is there or not..
3rd point check a[i][j+2] is there or not..
4th point check a[i-1][j+2-1] is there or not..
-----
if all above is true then increase the counter/result

it’s like this..
for example below are the point of 3x3 matrix
(0,2) ‘(1,2)’ (2,2)
‘(0,1)’ (1,1) ‘(2,1)'
(0,0) ‘(0,1)’ (0,2)
(1,0)=8
(2,1)=6 + 1 to both x/y (1,0)
(1,2)=2 + 2 to only y axis (1,0)
(0,1)=4 -1 to both x/y last answer (1,2)

for example below are the point of 4x3 matrix
(0,2) (1,2) '(2,2)’ (3,2)
(0,1) '(1,1)' (2,1) '(3,1)'
(0,0) (0,1) '(0,2)' (3,0)

(2,0),
(3,1), + 1 to both x/y (2,0)
(2,2) + 2 to y axis (2,2)
(1,1) -1 to both x/y last answer (2,2)

Ответить
jajakun peerawayut
jajakun peerawayut - 10.07.2022 18:54

Thanks for

Ответить