Комментарии:
Only 33 people liked the video, that says a lot.
Ответить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 😂
con quel ciuffo...
ОтветитьThe first problem is actually easily solvable in O(6)
ОтветитьI dont get it why cant we just choose 2 corners
ОтветитьSomeone remind me in a year so i can rewatch this and see if i have a clue whats going on
Ответить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.
ОтветитьAnyone else who had an Ad from AlgoExpert before this video? 😂
ОтветитьThe whole truth about the problem is based on example given by interviewer - not good approach.
ОтветитьI have an idea for 2nd problem
Just rotate the axis and perform the initial code
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
Ответитьvery nice question
Ответить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).
Ответить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.
Ответитьi am very much a beginner, i have no idea what he is saying but it's kinda mesmerizing
Ответить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.
ОтветитьYou have to compare p.y and p_above.y as well.
The code is incomplete.
Amazing
Ответить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'.
These coding interviews are masked iq tests.
Ответить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
ОтветитьTook a day to understand this question 🤢
ОтветитьSquares are rectangles, yes.
Not all rectangles are squares.
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)
Ответить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
Ответить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.
Ответитьmake_pair is a C++ STL function. Would I have to implement that in an interview?
ОтветитьThere is more IQ in this interview than in the entire venezuelan population
ОтветитьHi brother ,,i am 16 year old i complete python coading in ideal ,,😉😉😉😉😉😉
ОтветитьI can't believe this guy wasn't hired by google , wtf are they expecting a guy that creates an other universe or something
ОтветитьGreat
Ответить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
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.
What a great idea
ОтветитьOk
Ответитьgoogle :)
ОтветитьThis is so helpful therefore I have find my lost account
ОтветитьThat was an great Idea because of that now i already find my lost account thank you so much
Ответить😂 You guys call squares rectangles or am I the lost one
Ответить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.
.
Ответитьgood good good buddy
Ответить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.
Ответить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)
Thanks for
Ответить