ZigZag Conversion - Leetcode 6 - Python

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


0:00 - Read the problem
1:50 - Drawing Explanation
8:30 - Coding Explanation

leetcode 6

#coding #interview #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.
Рекомендации по теме
Комментарии
Автор

liked this video, disliked the leetcode problem

atifhu
Автор

Using += on strings creates new strings on each iteration in linear time and space. Might I suggest using a list and appending each character (constant amortised time/space), then converting to string before returning.

henryCcc
Автор

While less elegant, I feel like the solution to this problem where you assign a list for each row and move up and down while assigning each letter from the input to a given list is a bit more intuitive. It's less space efficient but I think it's good to learn as well

samlee
Автор

How can we come up with this type of solution in 45 min interview? 🤕

smartsoothing
Автор

Hi, I think if you move "increment = 2 * (numRows -1)" out of for loop may be better to understand. Still a really great solution! Thank you!

canxingbu
Автор

Dang, what timing, I was searching for your solution of this question today and couldn't find it. This question is little confusing to understand. Thanks for uploading!

KeshavKumar
Автор

I Think this solution is really what comes to my head over the strings one, i couldn't break it down somehow. Thank you for the explanation

pvrohanraj
Автор

If I had to answer this I would fail, just properly parsing the instructions felt difficult till I saw you draw the zig zag.

Tony-ynrr
Автор

Hi, Can you do Subsets 2? Couldn't find any good video for that problem. You explain every problem's solution nicely.

eltonlobo
Автор

thanks Neetcode! I cant think of a use case when this would be needed in real life

butoyighyslain
Автор

Thanks for your tutorial, I can't understand this question's solutions wrote by others until I watched this video.😂

jktruimp
Автор

it's pretty funny though that instead of a straightforward simulation you wrote the formula that you know. good luck to come up with this formula in an interview

name_surname_
Автор

In the Medium Playlist, 75-88 are the same as 89-102, I think you've added them twice by mistake. 
Thanks for coming in clutch with all your videos man, really do appreciate it.

ratikdubey
Автор

class Solution {
public:
string convert(string s, int numRows) {
if (numRows == 1) return s;

string ans = "";
for (int r = 0; r < numRows; r++) {
int inc = 2 * (numRows-1);
for (int i = r; i < s.length(); i += inc) {
ans += s[i];
if (r > 0 && r < numRows-1 && i + inc - 2 * r < s.length()) {
ans += s[i + inc - 2*r];
}
}
}
return ans;
}
};

vipulchaudhary_js
Автор

Hey I just did this one. I bet your solution is 300x more elegant though

Edit: It is. :p

asdasddas
Автор

Awesome... I think I got a little bit of tricked by the section 'pointer'. I made two vairables and switch the flag in every step and increase it by the first variable or the second variable depending on the flag. But this solution is much eaiser to read and simple... Thanks for uploading this video!

licokr
Автор

Hey! Your videos are great! Can you please solve leetcode problem 68 text justification ? It is a hard problem and has a 89.13% frequency of being asked.

cmpe
Автор

I saw this question and laughed at the discussion 😂

nathaniepeter
Автор

Hey can you do all top 100 questions of leetcode 🙂🙂

VINAYKUMAR-obco
Автор

Hey, i had a bit of confusion still can you help me out
in explanation for 2nd and 3rd row you used formula as increment-2*rownumber, but in code you used + i I didn't catch that from where that "i" come from, so can you explain bit about it.

nikhilshetty