r/learnpython • u/[deleted] • Feb 05 '20
I keep failing coding interviews - best way to learn data structures and algorithms?
For context, I'm a Stats major with some programming experience. I know how to code in Python from the standpoint of knowing syntax and OOP concepts. Outside of this, I know Matplotlib, NumPy, and Pandas. I attended a few SWE intern interviews and totally bombed the coding challenges. I was asked about what type of algorithm would be most efficient for the challenge and I had to tell them I had no idea. For HackerRank challenges, I am able to code the solution, but it is nowhere near efficient. If anyone has any Python related DS&A resources which I could use to learn this topic well and that could subsequently help me in these interviews I would really appreciate it!
20
u/steelersexcel93 Feb 05 '20
check out csmajors subreddit. General recommendation for algo questions is Leetcode
10
Feb 06 '20
For python, get a good book. I recommend Data Structures and Algorithms in Python by Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser. Only downside is there isn't an answer sheet for the end of chapter exercises, but hints are provided that will assist you.
9
u/RangerPretzel Python 3.7+ Feb 06 '20
Review this Programmer Competency Matrix
This will help you identify your strengths and weaknesses. Figure out where you're weakest and start reading up.
15
u/FGVel0ciTy Feb 05 '20
LeetCode is pretty good way to practice coding algorithms but to learn them I would recommend youtubing certain problems.
https://www.youtube.com/channel/UCmJz2DV1a3yfgrR7GqRtUUA
Back to back SWE is a pretty good channel to learn the concepts of different algorithms but they do their problems in Java. Still helpful to glance abstract concepts from the videos though.
13
u/duhhobo Feb 05 '20
you need to learn about big O notation and algorithm complexity as well. There will be multiple solutions to a question, and you need to understand which is the most performant and why.
4
Feb 06 '20
I'm about 2/3 of the way through this, and I strongly recommend it as an incredibly informative and interesting resource for understanding algorithms, but it's hard to recommend unequivocally, given its length. Most people probably don't have the time to read well over 1000 pages on this topic.
I was looking for this book, which I have heard is good, and I stumbled on this, which may or may not be good, but seems to be free, which is nice.
13
u/Magnivilator Feb 05 '20
Try Project Euler.
17
u/Decency Feb 06 '20 edited Jul 23 '25
I enjoyed Project Euler, too. Many of the problems are complex enough that if you do them in an inefficient way, you simply won't be able to solve them. So it requires you to use a correct approach that helps ensure that you can handle that kind of complexity.
3
u/ckini123 Feb 06 '20
I haven't gone through all of it but I've enjoyed what I've read of this: https://runestone.academy/runestone/books/published/pythonds/index.html
Entirely free book that covers basic data structures and algorithms; there are interactive exercises to make sure you're keeping up with material. I'd really recommend you pick any one of the resources here and just following it. Websites like HackerRank and Leetcode are good for practicing but take some time to actually learn the basics.
3
u/Darth_Ender_Ro Feb 06 '20
Learning data structures and algorithms is a long and difficult process. Do not expect to do it in 1 month. The best way to do it is to start. Understand the concept of a, let’s say linked list, and then implement it yourself. Fail 100 times until you get it. Don’t copy it after your first fail. Then move on. Later on come back to the linked list, try to do it from memory. Have fun.
2
u/zoldier Feb 06 '20
I prefer codewars over hackerrank due to codewars showing the most clever user solutions after you submitted your answer
2
u/say_fuck_no_to_rules Feb 06 '20
Deliberately and patiently work through (don’t just read!) Gayle Laakmann McDowell’s Cracking the Coding Interview. It will help put the concepts of Big-O etc. into context with the type of problems you’ll encounter in a whiteboard-style interview. I have a BS in CS, and I didn’t read it until after I’d been in the industry for about 5 years, but it was still super helpful in giving me greater confidence and more accurately display my competence in interviews.
1
u/notParticularlyAnony Feb 06 '20
Great book, but not great for learning the basics of algorithms/data structures. For that, see the other answers here.
2
u/safwankdb Feb 06 '20
There is a book written for people like you. It'll surely suit your needs. It's called 'Cracking the Coding Interview'. Have a look at it.
1
1
u/not_a_theorist Feb 06 '20
I'm coming from a similar place and I recommend https://www.coursera.org/specializations/algorithms
1
u/Deezl-Vegas Feb 06 '20
Practice with problems that feel a bit easy for you. You should be able to grasp the solution in 2-4 minutes and code it out in under 10.
When you meet a problem that you don't understand and/or melts your brain, give up after 2 minutes and check the answer.
Side study topics include: arrays, loops, stacks and queues, linked lists and trees, sorting algos, big O notation, regex and string manipulation, map/filter/reduce.
The main skills for whiteboard algos are knowing the solution in advance and breaking the problem into smaller parts. This strategy exposes you to lots of problems, and it gets you good at fixing little bugs and handling edge cases. Exposure to tons of problems and writing a lot of small chunks of code are key. Every complex algorithm is composed of simple algorithms.
1
u/PaulRudin Feb 06 '20
It can be a bit hit and miss. Over the years I've aced some technical interviews and made a mess in others. The problem can be that in a relatively short time you need to spot exactly what the underlying issue is and how to address it. If you start out down the wrong path it's hard to reset in this kind of setting.
For a good grasp of the fundamentals of data structures and algorithms I recommend Tim Roughgarden's lecture course, available for free on YouTube. See http://timroughgarden.org/videos.html
1
1
u/sephiap Feb 06 '20
Honestly, I've never come across a resource better than Elements of Programming Interviews - it has study guides with timescales before interviews, thorough topic explanations, and EPI Judge that gives barebones skeletons of solutions and an automated checker for offline practice.
Edit: added a link to their free sample that shows the structure of the book.
1
u/notParticularlyAnony Feb 06 '20
Data structures and algorithms in Python:
https://www.amazon.com/Structures-Algorithms-Python-Michael-Goodrich/dp/1118290275
1
u/varun_bat Feb 10 '20
I was in similar situation as you are and came across book "Algorithms" on the subject by Prof. Robert SedgeWick. Also audited his coursera course and really loved his teaching style. Highly recommended for people who love coding but are from non computer science background as datstructures and algorithms is very fundamental to the field and is a topic of most of the tech interviews.
1
u/twisted_mentality Feb 05 '20
Love the username btw.
I have heard good things about LeetCode, although I haven’t tried it out yet. My gut reaction is to just Google and YouTube to find out what the most common algorithm structures are, and then begin studying those structures until you feel comfortable enough. Also, so lock interviews.
I need to study to stay fresh and prepare myself. Message me if you’d like to focus and exam he study plans/ideas.
0
Feb 06 '20
Algoexpert.io is pretty cheap and has everything you need
4
Feb 06 '20
[removed] — view removed comment
1
Feb 06 '20
I was thinking about buying it. Would you care to elaborate why it's shallow? Thanks.
3
u/balthazar_brat Feb 07 '20
As a former subscriber I'll say it's not worth, Leetcode and CTCI is more than enough also discussion section in leetcode is very good you can get many solutions for same problem some cool tricks that you never know, don't worry much about most optimal solution worry about understanding and be able to solve problems.
1
0
u/kabooozie Feb 06 '20 edited Feb 06 '20
People have given good resources. Practice is important, so I’d suggest the CodeSignal website for practice problems and challenges.
Also Cormen worked with Khan Academy to do a pretty cool data structures and algorithms course for free on KA.
-2
347
u/dbramucci Feb 06 '20
You may want to read some books that cover some fundamentals in c.s. like
Data-Structures
complexity analysis (big-O notation)
program architecture (like mvc: model-view-controller)
classic algorithms (like Binary Search, Dijkstras and A* search algorithms, sorting algorithms, ...), concurrency
parts of the standard library like
collectionsmultiprocessingjsondatabases (namely SQL such as
sqlite)Recursion
Testing
Unit Testing
Integration Testing
Functional Testing
Niche tools like
Property-based testing
Fuzzing
Mutation Testing
It sounds like you currently need data-structures, complexity analysis and classic algorithms some resources include
Think Python: How to Think Like a Computer Scientist by Allen B. Downey
An introduction to Python that covers the basics and introduces some useful fundamentals like recursion, algorithm analysis and interface design.
Introduction to Algorithms, 3e by Cormen, Leiserson, Rivest, Stein
A book you will need to buy (physical editions exist)/checkout from your school/city library (interlibrary loans + book requests can help here). This book is a real big introduction to algorithms and will cover Data-Structures, Complexity Analysis and many algorithms to a greater extent than most c.s. undergraduate students will study. It's also a massive 1300 page book and costs on the order of $50 dollars to buy, but it's a nice reference book to own. This book is largely written in psuedocode
Structure and Interpretation of Computer Programs, by Abelson, Sussman, and Sussman
SICP is a classic in computer science education that introduces readers to fundamental computer science ideas like recursion, functions and how programming works. This source uses a version of Scheme, not Python but the book's lessons aren't about its particular language choice. If you use this source, I'd advice checking out the physical copy or the unofficial digital edition which has a much more readable website (HTML) and pdf than the official ebook does.
MIT Open Courseware
6.0001 Introduction to Computer Science and Programming in Python
An introduction course that might help you catch some holes in your fundamentals. Maybe nobody has introduced you to Immutable types and here you will encounter that (in lecture 5)
6.005 Software Construction
How to write code that works for big projects, not just short hacky scripts that barely work and are hard to change without adding bugs. (No video lectures, online textbook, code in Java)
6.006 Introduction to Algorithms
A course to introduce you to algorithms including popular ones like breadth-first search and how to think with algorithms.
6.046J Design and Analysis of Algorithms
More algorithms for you to study if 6.006 wasn't enough.
(also, I don't think you need to learn all/most of the stuff above, I just list it because it will help you identify what you don't know and where you can learn it)