r/learnprogramming • • 7h ago

What to do !

I know how to write code, but not in the LeetCode style . I also want to do DSA, and my seniors told me to learn a coding language too i know (I already know C, python ). Tell me what all I should do in this situation first .

5 Upvotes

11 comments sorted by

4

u/JohnsTech_dev 6h ago

you dont need another language for dsa, python is fine for leetcode and most interviewers are ok with it. C is painful for it tbh, no hashmap out of the box.

what worked for me was doing problems by topic instead of random ones. like 15 easy array/hashmap problems, then two pointers, then sliding window. if stuck more than 30 min read the solution, close it, and write it again from memory next day

2

u/FinancialTrack5007 6h ago

From where and how to practice DSA .
the main issue is that when i write code in Leetcode in normal way example print int (input()) it shows it as incorrect hope you are understanding this issue

And if i needed to study other lang what would you suggest C++ , java , javascript ?

2

u/a3th3rus 6h ago

LeetCode puzzles have already handled the simple but tedious IO part for you, so that you can focus on the DSA part. If you want to see something, you can print it, but there's no input() in LeetCode. Make sure you delete all the print statements before submitting your code, because print is an IO operation, and IO is slow.

1

u/FinancialTrack5007 6h ago

What i mean is that , there is specific format in which the code has to be written in Leetcode ie "Class solution,-> " honesty from where i learnt python this was not taught to me
how do i handle these type of situations

1

u/a3th3rus 6h ago edited 6h ago

If that's your problem, then you need to learn Python more, or do Advent of Code which only gives you the puzzles and their inputs as plain text, and only asks for your final result. You can solve them with any language and any tool you like, and code in any way you see fit (sometimes even without coding).

2

u/Academic-Tie6223 4h ago

LeetCode really does hand you the IO on a plate, that's the whole point. When I started doing DSA on my own I wasted two days just parsing hahastdin in C before I even got to the algorithm. Skip that noise, just focus on solving the problem.

1

u/JohnsTech_dev 1h ago

for the other language, c++ or java. both have proper collections for dsa (stl in c++, hashmap/treemap/priorityqueue in java). java if youre mostly targeting placements here since alot of service company interviews expect it anyway, c++ if you want to try codeforces later. js is awkward for dsa, theres no built in heap so you end up writing one

1

u/moonfable42 6h ago

First relearn basic DSA concepts like arrays, strings, recursion, then move to leetcode easy problems in python. Once you get comfortable move to mediums. Do like 1-2 problems a day consistently instead of binge solving. After a month or two start timing yourself like a real interview.

1

u/FinancialTrack5007 6h ago

From where and how to practice DSA .
if i needed to study other lang what would you suggest C++ , java , javascript ?

1

u/a3th3rus 6h ago

Try automating some of your simple but repetitive works. If you don't have one, see if your friends have any that you can help with. For example, my wife (a translator) always have the need for extracting text that needs to be translated from a certain format of XML, and I wrote a Ruby script for that, and another for stuffing the translated text back to that XML.

Also, if you play video games, you can write some algorithm for yourself to minmax something. For example, I've written something that finds the optimal fights in Valkyrie Profile to gain as much exp as possible with no member levels up.

1

u/Perfect-Schedule-546 1h ago

don't add a third language. DSA is the same in C and Python, and learning a new
one now just makes you slow at typing while you're already learning the real
skill.

pick python since you know it, spend a month on arrays/hashmaps/two pointers
before you touch trees, and do 2-3 problems a day instead of 20 in one night.

leetcode style is pattern recognition, not coding ability. it feels different
from your normal code because it is a different skill you train it, you're
not missing it.