We can also reverse rows and then transpose that will decrease complexity for i in range(len(matrix)//2): matrix[i],matrix[len(matrix)-i-1]=matrix[len(matrix)-1-i],matrix[i] for i in range(len(matrix)): for j in range(i,len(matrix)): matrix[i][j],matrix[j][i]=matrix[j][i],matrix[i][j]
@nwokolobueze72912 жыл бұрын
This explanation is for dummies like myself. Thanks Michael.
@anupestuff4 жыл бұрын
Hey Michael, I highly appreciate your effort for making the video. It takes lot of effort and I understand that fact. I also wanted to mention that as an experienced developer I expected you to understand the fact that 99% of the engineers won't know this transpose and reverse method and the expectation here is to be able to solve it with just logic. Good numbers of folks have solved it using just logic and playing around with indexes and same complexity. Refer to leetcode discuss section. I feel you should promote logic reasoning than knowledge based answer. Good Luck and hope you take this as positive criticism.
@AlgosWithMichael4 жыл бұрын
True, thanks for the feedback
@tl7955 Жыл бұрын
Dude I can’t express how clear u delivered. You have the best tempo and explain i ve ever saw. I have to comment to show how good you r. Btw i like the keyboard sound!
@tl7955 Жыл бұрын
At meanwhile, u can consider buy you a graphics tablet. It’s fun and helps recording videos a lot
@AlgosWithMichael Жыл бұрын
I appreciate that!
@RohitKulkarni08104 жыл бұрын
Your videos are great my guy! Thanks for helping everyone out!
@AlgosWithMichael4 жыл бұрын
Happy to help!
@RohitKulkarni08104 жыл бұрын
@@AlgosWithMichael lmao I have a placement test in 8 hours and I've only been watching your playlists for over 4 hours now and it's helped me so much. Keep doing what you do man, you deserve all the support!
@AlgosWithMichael4 жыл бұрын
Eh I appreciate that man. Hope you did well!
@剑胆琴心吉他弹唱4 ай бұрын
Thanks Michael! This Transpose (flip diagonally) + reverse(columns) algorithm is mind blowing! Very simple and easy to follow. I am thinking on top of my mind if this is also going to work. Swap element at ( i, j ) with element at ( j, n-1-i ). Can you please provide some insight on this? Thank you very much!
@yitingg79424 жыл бұрын
This is so mind-blowing lol. How did you think of it Michael ? Thanks a lot for taking your time to fully explain it again!
@AlgosWithMichael4 жыл бұрын
Of course, thank you for watching!
@AxelKingsley3 жыл бұрын
Hi Michael, looking in your video description, I don't agree with your assessment that the runtime is O(N^2). Here's my reasoning: Logarithmic Running Time is defined as the increase in runtime *in proportion* to your input. Looks like the way you're defining it, the runtime is N-squared if N is the number of Rows. While that's technically true, it doesn't take into account that each row is *also* increasing in size whenever you add an element. Here are some examples: 2 x 2 Matrix: There are 4 cells in your input 3 x 3 Matrix: There are 9 cells in your input 4 x 4 Matrix: There are 16 cells in your input So, while the runtime is increasing exponentially for each row you add, it *isn't* because of the algorithm, but instead entirely to do with the fact that the amount of input is also increasing exponentially. A better way to define the runtime of this solution is O(N), where N is the number of "pixels" in your matrix. It just so happens that the valid inputs to the problem *only* come in square sizes (1, 4, 9, 16, 25), so it appears to increase at N-squared rate when you increase the dimensions of the input. Another way of looking at this: What if the requested algorithm only counted each cell and returned the tally? It wouldn't be fair to say that the tally function runs in N-squared time, because every time you add a new row, every row also gets bigger. The *input* increases at the same rate as the runtime, and therefore it is reasonable to label this as O(N), linear time.