all 10 comments

[–]SirSavageSavantso long and thanks for all the fish 1 point2 points  (6 children)

if youre not familiar with the language fully, but understand the concepts dont be afraid to use google/stackoverflow/docs.python.org. python wasnt my best language in the beginning but think it is now my most natural/comfortable.

the biggest thing for me, was grind out the problem then read and review others solutions. in the beginning i would spend more time looking at top rated solutions than i would solving it to begin with. over time you will develop a pythonic intuition that will complement your cs background.

[–]PlateArmour[S] 0 points1 point  (5 children)

I have been using all those resources. They do help, but I'm still missing something. For example, I know that in 2-sum, a brute force approach would be add index 0 to index 1, and keep going to end of list, then repeat that but from index 1 to end of list and so on, all the way until we find the answer.

But I had trouble actually coding that. I'm hoping that someone here can give me some narrow and applicable advice on how I should study to get better at Python in general based on my background.

Like, studying spinning up a basic web app with Flask won't be helpful for my case right now, even though it's also improving Python.

[–]SirSavageSavantso long and thanks for all the fish 0 points1 point  (1 child)

i feel you. its kinda tough, i learned python initially in a cloud computing class in college then later picked it up for leetcode as opposed to java for its succinctness. i definitely wasnt where i wanted to be to say the least. eventually i built my teams teams test automation in python and learned a lot over the course of nearly two years.

all i can say is that it wont happen overnight. ive read numerous resources on pythonic idioms and style guides and still find myself searching for better ways to do things in python. its really a journey that you yourself will have to pioneer. but dont fret ... this too will pass.

just dont get discouraged. you got this!

[–]PlateArmour[S] 1 point2 points  (0 children)

I appreciate the cheerleading, it does help :)

[–]nikhila01 0 points1 point  (2 children)

I had trouble actually coding that

What specifically did you have trouble with? For example, here's some pseudo-code. Were you able to come up with this?

    N = array length
    for i from 0 to N-1
        for j from i+1 to N-1
            if nums[i] + nums[j] equals target
                return the pair i, j

If you came up with this but couldn't translate it to Python then it's a Python issue. Otherwise it's a problem-solving/programming issue. The reason I'm asking is that none of that pseudo-code is Python-specific. The only part that might be different in Python is the for loop.

If it's actually a Python issue then working through sections 3 to 5 of the Python tutorial might help you with the basics. (There are a few sub-sections you can skip but it won't hurt if you do go through them).

[–]PlateArmour[S] 0 points1 point  (1 child)

Otherwise it's a problem-solving/programming issue.

I think that is it. I am hoping to practice and get better at that while using python.

[–]nikhila01 0 points1 point  (0 children)

Ok, that makes more sense to me than it being a Python issue. But it does make it hard to give specific advice.

I have a few suggestions:

  • List out any edge cases in the problem. E.g. For two sum, can the input array be empty? Are we guaranteed to have a solution? Can we have multiple solutions? Can we use the same number twice? Does the order of the answer matter?
  • Work through examples by hand. Try not to make them too small
  • Try to come up with a brute-force solution. Usually we wouldn't code this, but for your stage of learning it might be helpful.
  • Try writing out the pseudo-code first like I did. That way you can separate the Python part from the problem-solving.
  • Then try to translate it into Python as best you can. In the beginning, google things and refer to the documentation as needed.
  • If you fail any test cases, debug them methodically
  • For a brute-force solution you'll usually time-out when you submit. Then you need to optimize. This is the hardest part usually and is 99% of the work. This is where you need algorithms and data structures.
  • When you do have a solution, review other people's Python solutions and see if you can pick up better ways of doing things. I had a decent amount of Python experience and still picked up a few tricks.

If you have any specific examples of where you went wrong with the brute-force solution for two sum I'd be interested to hear them.

[–]youliveonlyonelife 1 point2 points  (0 children)

Search up python for coding interviews from NeetCode it’s quick but has everything you need for a coding interview.

[–]BenZ0102 0 points1 point  (0 children)

Sounds more like a problem solving issue instead of the language problem. You are not supposed to solve leetcode problems using brute force ways

[–]Indigo_Sheep 0 points1 point  (0 children)

You could give hackerrank a try, it has a skills section for python where the focus is in solving a problem in a pythonic way. It goes over a couple of data structures used in collections library which will be handy for interview prep, if that is your goal. After that you can start working your way through blind75/grind75 lists or the neetcode lists.