Good solution. I'd use StringBuilder instead of String wherever lots of manipulation is required. It's faster and consumes less memory since extra objects are not being created every time you add a character.
@naveennaik37058 ай бұрын
Great video🔥🔥 aapke videos dekh ke Mera DSA mein interest badh raha hai. Keep it up
@algorithmsbyaditi8 ай бұрын
Thank you so much 😊
@motivationworld277 ай бұрын
Line mar ra hai aap par me bata hu clear aapko improve karna chye apko padhane ka way but knowledge hai apko
@Ybash29794 ай бұрын
i haven't seen much of your content , but the ones seen the solutions are too accurate and easy !!
@algorithmsbyaditi4 ай бұрын
Thank youu !
@tanaysrivastava93033 ай бұрын
Nice explaination ma'am, but can you further explain the code in upcoming videos ,it would be helpful....
@algorithmsbyaditi3 ай бұрын
Will improve, Thanks.
@Ayush372628 ай бұрын
Awesome explanation!!! How to think like that? I was solving this question using a matrix and storing every character in it 😢
@algorithmsbyaditi8 ай бұрын
Just need to think that the number of strings to be concatenated is equal to the number of rows.
@sushantnand39746 ай бұрын
Neetcode faltu me chada rakha h, 2min me samjhaya didi ne, thankss
@algorithmsbyaditi5 ай бұрын
Thank youu !
@pranawkaushal29322 ай бұрын
public String convert(String s, int numRows) { if (numRows == 1) return s; // Edge case for a single row StringBuilder[] rows = new StringBuilder[numRows]; for (int i = 0; i < numRows; i++) { rows[i] = new StringBuilder(); } int i = 0; while (i < s.length()) { for (int index = 0; index < numRows && i < s.length(); index++) { rows[index].append(s.charAt(i++)); } for (int index = numRows - 2; index > 0 && i < s.length(); index--) { rows[index].append(s.charAt(i++)); } } StringBuilder sb = new StringBuilder(); for (StringBuilder str : rows) { sb.append(str.toString()); } return sb.toString(); } We can use StringBuilder instead of String for memory optimization
@algorithmsbyaditi2 ай бұрын
Great work !
@GauravSingh-xs6qn3 ай бұрын
Radhe radhe 😊
@samchopra1006 ай бұрын
Nice explanation! I got an idea from your video that how can we solve it. Optimised your solution to solve it with single iteration. Swift Code: func convert(_ s: String, _ numRows: Int) -> String { guard numRows != 1 else { return s } var temp = [String](repeating: "", count: numRows) var count: Int = 0 for (index, ele) in s.enumerated() { if (index + 1 + count) % numRows == 0 { count += 1 } let isBottom = count % 2 != 0 if isBottom { temp[numRows - 1 - ((index + count) % numRows)] = temp[numRows - 1 - ((index + count) % numRows)] + String(ele) } else { temp[(index + count) % numRows] = temp[(index + count) % numRows] + String(ele) } } return temp.reduce(into: "") { (p , c) in p += c } }
@algorithmsbyaditi5 ай бұрын
Great work !
@QuadbTech8 ай бұрын
Great explanation 😮
@shivam1gaur6 ай бұрын
Radhe Radhe
@Viratrohit1844 ай бұрын
Please make video in English
@meetpatel.477 ай бұрын
How many leetcode questions are enough for freshers? your linkedin?
@amanisdreaming39147 ай бұрын
probably 250-300. also depends on your cognitive skills.
@randomeverything83045 ай бұрын
150 are enough. baaki tension lene se kuch nhi hota. Enjoy life.
@meetpatel.475 ай бұрын
@@randomeverything8304 gand fati padi he yahape apply karte karte
@surendrasa9516 ай бұрын
mene khud ka code banaya alag uska runtime 15ms aa raha hai submit karne per.