DEV Community

DEV Community

Amy Haddad

Posted on Feb 16, 2021 • Updated on Feb 26, 2021 • Originally published at amymhaddad.com

How to Get Better at Solving Programming Problems

Most of us have been given the same advice: to become a better problem solver, you need to solve more problems. But this advice is too simplistic. Getting good at anything requires more than just reps. It’s also how you go about it.

Besides, when programmers hear the advice “solve more problems,” they often think that “more” means faster. It’s a mistake I made when starting out.

The problem-solving treadmill can be detrimental to learning and improving. Early on I’d speed through one problem and head to the next. But the reality of that approach soon set in. By focusing on quantity, I compromised quality and missed key learnings along the way.

It’s not to say that repetition doesn’t matter; it does. However, repetition alone doesn’t get to the heart of the matter. The process does.

I have a vested interest in this topic: I want to get better at solving problems in order to improve as a programmer. So here I offer my plan of attack. It involves reps to be sure—and a whole lot more.

1. Solve a Variety of Problems on a Variety of Platforms

“I was obsessed with HackerRank when I began learning to code,” said an instructor of a Python course I was taking. Although it’s fine to have a favorite platform, don’t limit yourself to a single one. Here’s why: you need to be ready for anything.

One goal of mine is to toggle smoothly among different problem types and across different platforms. The problems on Interview Cake are different than those in Reuven Lerner’s book, Python Workout . Likewise I find the problem statements in Lerner’s Weekly Python Exercise different from those on HackerRank.

I have my preferences, to be sure. However, I need to be able to solve problems of all types. So I’m using a variety of platforms and resources to get practice.

Here are some examples:

  • Interview Cake
  • Cracking the Coding Interview by Gayle Laakmann McDowell
  • Python Workout by Reuven Lerner
  • Weekly Python Exercise by Reuven Lerner

On Sundays, when I make my plan for the week ahead, I select a few problems from the above resources. I’m deliberate about it. For example, I’ll pick a problem that focuses on binary search from LeetCode. Then, one that focuses on data structures from one of Reuven Lerner’s sources.

This practice prevents me from getting too comfortable. I can’t rely on the same data structure or technique. I need to be able to pick the best tool for the job. I’ve got to be able to pivot.

It also challenges me. That’s because I select problems that push me to the edge of my limits, a feature of what psychologist Anders Ericsson calls “deliberate practice.”

Deliberate practice is all about skill development. It’s a fully-focused, conscious effort that takes you out of your “comfort zone,” centers on a specific goal, and “demands near-maximal effort,” Ericsson explains in his excellent book, Peak .

In other words, you’re not going through the motions doing something that comes easy or natural. “The hallmark of . . . deliberate practice,” Ericsson writes, “is that you try to do something you cannot do.”

2. Cross-Train Your Programming Brain

You often hear about athletes who incorporate cross-training into their routine. For example, a runner completes a bike workout or two each week. It makes a lot of sense: by cross-training athletes push their cardiovascular fitness from a different angle.

Cross-training for programmers is a topic I’ve written about before. Yet, more needs to be said about the benefits of this approach. Just like an athlete cross-trains to improve their cardiovascular fitness, I’m incorporating cross-training to improve my mental fitness.

My cross-training involves solving math problems. I apply the same tactics I’d use to solve a programming problem but in mathematics. Same process, different context.

My current math book provides the cross-training benefits mentioned above. But it’s doing something more: it’s helping me build my intuition for solving problems.

That’s an important point. I don’t want to memorize a math equation or process. I want to intuitively know when to use it. The same is true when solving programming problems.

3. Learn from Your Solutions

All of us get stuck and all of us get errors while problem-solving. We use these failures to help us figure out what to do differently.

Oftentimes that’s where the learning stops. Once we’ve solved the problem we’re anxious to move along. But don’t.

Mathematician Richard Hamming suggests that’s when the learning should begin.

“I regard the study of successes as being basically more important than the study of failures...there are so many ways of being wrong and so few of being right, studying successes is more efficient,” Hamming writes in his book, The Art of Doing Science and Engineering .

This idea of "looking back" and studying your successes is a topic I've written about previously , and it's worth noting again. You always hear about how we need to "learn from our failures." But Hamming is right: there's so much to learn from our successes.

So one of the biggest changes I’ve made to my problem-solving process is putting Hamming’s words to practice. I vividly recall solving my first problem that involved a linked list, a data structure that was new to me at the time. After I solved the problem, I studied it intently. I copied my solution into a Google Doc file and used comments to explain the code to myself.

I wanted to ensure I clearly understood what I did and why for this critical reason: so I could do it again.

4. Get Feedback

Awareness can be a wonderful teacher.

Don’t assume your solutions are great. Find out for yourself by getting feedback. Feedback is a critical factor when it comes to getting better. It’s also a component of deliberate practice.

There are two ways I’m getting feedback.

First, after I complete a problem, I study the solutions of others. Sometimes resources, like LeetCode and Cracking the Coding Interview , provide the solution. Other times I find the solution of a programmer who’s solved the same problem. Sometimes use both.

Either way, the next step is the same: I start at the top of the solution and explain each line in my own words. I speculate why the programmer chose this particular data structure, for example. Then, I write a short summary of the program to solidify the core concepts or new approaches that I just learned about.

Putting something complicated, like a line of code, into your own words is a great test to see if you really understand it. Plus, you get practice at another core skill: reading code .

If there’s something that’s new to me, I research it. I compare their code to my own. I study. I evaluate. I learn. It’s an arduous process, but I get so much from it.

The second way to get feedback is to simply ask another programmer for it. Video calls are helpful to step through code line by line in real time. Although, pull requests are useful, too.

There’s a point to the feedback: apply it! Put your learnings into practice.

5. Be Consistent

Now let’s talk about repetition. Problem-solving is a skill. Like any skill, it takes time to build. It simply doesn’t happen overnight or over a weekend. That’s why I devote time each day to problem-solving.

There’s a common reaction to this daily practice: “There’s too much to learn. I can’t spend time each day problem-solving.”

My response is two-fold. First, there’s always going to be something more to learn, always .

Second, in large part programming is problem-solving. It's fundamental to our craft. It’s worthy of your time and attention each day. Here’s the caveat: make your daily practice intentional.

It’s an Art

Many people regard problem-solving as an art. I happen to agree with that sentiment. The same can be said for the process itself.

The ideas outlined in this article are my approach for getting better at problem-solving. Your approach may look very different. The point is this: be intentional about your practice. Quality matters; make each problem count.

Programmer and writer: amymhaddad.com | programmerspyramid.com | I tweet about programming, learning, and productivity @amymhaddad

Originally published on amymhaddad.com .

Top comments (0)

pic

Templates let you quickly answer FAQs or store snippets for re-use.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink .

Hide child comments as well

For further actions, you may consider blocking this person and/or reporting abuse

vkolencik profile image

How I Structure My Day as a Software Developer

vkolencik - Aug 25

getvm profile image

Mastering JavaScript: A Comprehensive Collection of Free Online Tutorials

GetVM - Aug 25

akshatsoni26 profile image

Understanding the Key Differences Between | and || in TypeScript

Akshat Soni - Aug 25

mahrukh_adeel profile image

Exciting News: Windows Community Toolkit v8.1 is here

Mahrukh Adeel - Aug 24

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Featured-Thumbnails_1200x558-1

10 Common Obstacles of Those Struggling to Learn Code

Stephan-Miller.jpg?w=648

  • Share article on Twitter
  • Share article on Facebook
  • Share article on LinkedIn

Learning to code can be challenging. Not only do you have to learn syntax, but there are so many new concepts to learn as well, and many of them don’t relate to anything else you’ve studied in the past.

Struggling to learn code is completely normal and expected. Most beginners go through at least one rough patch (and often several) while they’re learning to code, but the good news is that a lot of these rough patches involve similar obstacles. Even professional developers with years of experience run into some of these problems.

In this article, we look at 10 of the top obstacles beginners face when they’re learning how to code, and how to overcome them.

Learn something new for free

Intro to chatgpt, 1. you have trouble finding the time to code.

For many aspiring developers, it can be challenging to find the time you need to learn how to code. The key to overcoming this obstacle is to have a goal in mind. Envision where you’ll be when you’ve mastered a new programming language and all the new opportunities you’ll have with your new skills.

If that seems too far away, you could focus on building a coding passion project. While you might’ve already completed a few projects in your coursework, finding a project you’re excited about will help keep you motivated and engaged in your learning.

It’s also worth keeping in mind that finding the time to learn any new skill ultimately comes down to discipline. Try looking at your schedule, especially when you have nothing to do or when you’re switching from one task to another. Most people can find time if they look.

Once you find a good time to study, stick to it. Learning only when you can find the time never works. Make the time.

2. You want to learn too fast

Being motivated to learn how to code will help you get through the rough spots, but you can also take it too far. When you’re learning to code, you have to crawl before you can walk. Remember — you’ll get there, but you need to start with the basics and build your skills. Many of the courses in our course catalog are designed for beginners and will make sure you start your coding education with a firm foundation.

Many learners ambitiously tackle advanced concepts without mastering the basics, which leads to frustration and quitting. It’s crucial to first build a strong foundation by thoroughly understanding fundamental principles before moving on to more complex topics. This approach will provide a solid groundwork and make advanced concepts easier to comprehend and apply effectively. 

3. You get frustrated

If you ask a seasoned developer, we’re willing to bet they’ll tell you that getting frustrated with coding is simply part of the process, and it’s something you have to get used to.

Just remember that you’re a beginner. Everyone was “bad” at coding in the beginning. You can always ask team members, the coding community, or the QA department for help. (See #8.)

Also, know that every company building applications today usually has a QA department working full-time. So bugs are expected, even in code written by professional developers.

4. Imposter syndrome grabs ahold of you

When coding becomes a struggle, you might think you aren’t cut out for a career as a developer. This lack of confidence is common, especially when you’re just starting out. In fact, it even has a name — impostor syndrome . But, don’t give up! If you fail, that’s okay. You may even find that you learn more from your mistakes.

Sarai Fernandez , Codecademy’s Computer Science and AI Domain Manager, recommends reframing the way you view failure. “If I try and fail, I’ll be in the same place I would have been if I didn’t try at all,” she says. “At least, if I try, there’s a chance at success. Realizing that failure usually has the same exact result as not trying at all has helped trying and failure seem less ‘scary’ to me. After all, not trying isn’t scary, so why should failure be?”

5. You use Google to help you code a lot

If you’re someone who turns to Google for help when you’re stuck, you might think this means you’ll never cut it as a developer. Wrong! You’ve just stumbled upon the #1 tool in the professional developer’s toolbox.

Even coding tests in many technical interviews will allow you to search with Google. The syntax, keywords, and methods of programming languages are hard to remember, but as long as you know where to look for the answer, you’re on the right path.

Malachi Constant , another member of our forums, agrees with this:

“Wholeheartedly agree though, it can be frustrating sometimes too buuut a large part of coding is figuring out the problem and a whole lot of googling/stack overflow…”

6. You aren’t motivated to learn

A lack of motivation makes it especially hard to learn to code. While we all have different things that get us motivated, one thing that might help you is to surround yourself with people who are passionate about coding.

Try socializing with other developers who are building something interesting, and pick up some of their excitement to learn. Find a time slot every day to code and put it on your calendar. As you build your skills daily, you’ll be able to do more things with code and see the possibilities, which will fuel your motivation.

7. You have trouble remembering what you learn

Learning to code is slightly different than learning other topics that require a lot of memorization. With programming, the best way to learn and retain your new skills is by writing code.

Programming is a very abstract subject. You’re turning text into actions and graphics on the computer, representing something in the physical world. There are at least two layers of abstractions here, and getting your hands dirty with code will help everything “click.” Try some coding challenges and complete some coding projects to practice.

In our forums, toastedpitabread suggests this:

“Take notes, but they don’t have to be on paper. Good note taking is essential to getting the most out of your study. Sometimes it’s good to take notes while studying, sometimes it’s good after. I find that audio memos help me tremendously, and for certain things, even video notes help me also. ‘Talking’ a problem out while drawing it on paper is another good thing to try if you haven’t.”

We also have a complete guide to remembering everything when you’re learning to code .

8. You don’t know who to ask for help

We’ve already told you one of the secrets of professional programmers: Google is their best friend. But, many of them also turn to Stack Overflow.

Stack Overflow is a great resource for developers. Every dev has issues once in a while, and the Stack Overflow coding community is happy to help you find the answer. All you have to do is ask.

While we’re on the topic of asking, check out our own coding forum , where you can find help from other coders who are on the same path as you.

Roy , who we heard from earlier, puts it this way:

“Your community is here for that exact reason. Mind, because there is a huge diversity of expression, we might have to grow a thick skin and learn tolerance and empathy. It also means we have to be willing to admit confusion. Nobody is judging our code on anything but its own merit. That never reflects on the writer.”

9. You don’t know what technology to start with

It can be difficult to decide which programming language to learn and which one matches your strengths and interests. It can also be challenging to figure out exactly what you’ll be able to do with your new skills. And all this confusion can, understandably, lead to indecision.

While there are a number of programming languages that we recommend learning first , you can also take our sorting quiz , which will recommend a language that’s right for you and your approach to problem-solving.​​ The good news? You really can’t choose the “wrong” language when you’re first starting out. All programming languages share common concepts, and programmers typically need to know multiple languages.

10. You don’t know what you should be learning

If you’re not sure what you should be learning, one trick is to narrow down your interests. Are you more interested in web development or mobile development ? Do you want to create video games or get into machine learning ?

Once you’ve narrowed this down, you can start researching specific job titles and looking at the skills you’ll need for those roles. You can also look into our Career Paths, which include courses that teach the skills you’ll need to successfully start out on your new journey. Here are a few of the Career Paths we offer:

  • If you’re interested in building websites and web applications, check out our Full-Stack Engineer Career Path to learn both front-end and back-end development .
  • If you’d rather create the UI for web applications, check out our Front-End Engineer Career Path .
  • If creating web services for web applications is of more interest to you, check out our Back-End Engineer Career Path .
  • If working with machine learning and artificial intelligence sounds like something you want to do, check out our Data Scientist Career Path .
  • If you’d rather use data for analysis to gather insights, then our Data Analyst Career path is for you.

Codecademy can help those struggling to learn code

Running into obstacles as you code doesn’t just happen to beginners. All programmers — even those who’ve been coding for years — struggle from time to time. It’s completely normal and expected, and the key to overcoming those struggles is to stick with it. You’ll get there with patience and dedication.

Still, there’s a difference between learning on your own and being guided along the right course while you learn. Here at Codecademy, many of our coding courses are designed specifically for beginners. Try one of our courses, and if you need support along the way, you can find peers who have made it through the struggles you’re going through and are willing to help out in our forums .

Related courses

Learn to code with blockly, choosing a programming language, choosing a career in tech, subscribe for news, tips, and more, related articles.

Cybersecurity_Blog_F_Cybersecurity_Thumbnail_01.png?w=1024

4 In-Demand Cybersecurity Skills That Will Help Get You Hired

Seize the job opportunities in cybersecurity by learning these key technical skills.

What-Is-CoffeeScript-.png?w=1024

What Is CoffeeScript?

What is CoffeeScript, and is it worth learning? In this article, we explain how it changed the way we write both front-end and back-end JavaScript code.

Header-Image_2083x875-2.webp?w=1024

Context Switching Is Killing Your Productivity — 6 Tips for Focus

Context switching doesn’t just affect your productivity, it causes stress and frustration too. Here are some ways to manage interruptions at work.

6-Small-Wins-To-Celebrate-On-Your-Journey-To-Becoming-A-Professional-Developer-1.png?w=1024

7 Small Wins To Celebrate On Your Journey To Becoming A Professional Developer

Having an end goal is important, but so is celebrating your progress. Here are some milestones to look forward to as you learn how to code.

6-Most-Popular-Programming-Languages-for-Game-Development.png?w=1024

7 Most Popular Programming Languages for Game Development

Learn the best languages for game development and why developers choose to use them. Discover how our classes can get you started with game design.

7-Organizations-Helping-Girls---Women-Build-Careers-in-Tech-1.jpg?w=1024

8 Organizations Helping Girls & Women Build Careers in Tech

There’s a gender gap in tech — but it’s getting smaller thanks to organizations like these.

staying-accountable-coding-goals.png?w=1024

5 Ways to Stay Accountable to Your Learning Goals in 2024

Planning to learn to code in 2024? We’ve put together a list of 6 tips and resources to help you stay accountable to your coding goals this year.

  • All Articles List
  • 15 April 2024
  • 14783 views

Problem-Solving. How to Boost Your Ability to Solve Programming Tasks and Challenges

Problem-Solving. How to Boost Your Ability to Solve Programing Tasks and Challenges - 1

8 Steps to Improve Your Problem-Solving Skills as a Rookie Programmer

1. make sure you understand the problem, 2. break down the problem into smaller ones, 3. plan the solution first, 4. solve programming problems on various preparation platforms.

Java webinar

One of the most popular tech interview platforms with a huge community and over 1650 problems for you to practice. Supports 14 programming languages including Java.

Interview Cake

Another well-known website with all kinds of content for programmers, including programming tasks, articles, tips and lots of interview questions.

HackerEarth

Besides programming problems, this platform allows you to test yourself in mock interviews, as well as to participate in coding competitions and hackathons.

5. Use CodeGym to practice and learn how to approach programming problems

6. play coding games to practice problem-solving while having fun, 7. extend your knowledge of design patterns, algorithms, and data structures, 8. get feedback, 4 major applied programming techniques for problem solving, 1. debugging.

Read more:

2. Code Refactoring

3. using data structures & algorithms.

Read more:

4. Using Version Control Systems

Java university

Expert advice

Problem-Solving. How to Boost Your Ability to Solve Programing Tasks and Challenges - 2

What else to read:

8 Signs You Aren't Meant to Be a Programmer

3

Your changes have been saved

Email is sent

Email has already been sent

Please verify your email address.

You’ve reached your account maximum for followed topics.

Key Takeaways

  • Lack of experimental creativity hampers programming; open-mindedness and willingness to try new approaches are essential for success.
  • Independence and self-motivation are also vital; the ability to solve problems and continuously learn is necessary to thrive.
  • Logical thinking and a passion for solving puzzles are crucial. Without these traits, coding can be frustrating and unrewarding.

Is programming right for me? Will I like coding? Asking yourself these questions and answering them honestly may have you thinking twice. The reality: some people just hate coding.

If you're unsure whether you're meant to be a programmer, here are some signs that may indicate a bad fit.

1. You Lack Experimental Creativity

I hate programming. Is coding for me? You may have just answered your own question.

Despite its foundation in logic, programming is very much a creative art. A new program is like a blank canvas. Your paintbrushes and palette of colors are languages, frameworks, and libraries. You need a vision for your creation and the creativity to bring that vision to life.

Coding purists will tell you that there's only one way to write good code, which is far from the case. That's like saying there's only one way to build a house, write a novel, or bake a cake. There are many ways to code software; you should be willing to experiment.

Without a natural sense of curiosity, you'll develop tunnel vision. You'll have a hard time coming up with new ideas. At that point, programming becomes mundane work and loses the spark of excitement that likely drew you to tech in the first place.

2. You Aren't Independently Driven

Am I cut out for computer science? If you've got the drive, you most certainly are.

You won't be successful in anything unless you're incredibly driven. That's a universal truth, but it's especially true in programming.

A good programmer is able to motivate themselves. Peel back all the other layers; programming, just like any trade, is fundamentally repetitive. If you have trouble investing yourself in the type of work that being a developer demands, you're going to struggle and will likely burn out.

You have to be able to solve problems using your initiative. A lot of new problems will resemble the problems from last week. A plumber doesn't ask for a new type of sink to fix when he shows up at a client's house. They just solve the problem and prepare themselves for the next one.

Because of this, you’ll find the solutions to some problems by working on others. Experienced programmers will gain a wealth of knowledge over time. You have to be passionate in your drive to seek these recurrences and patterns out at every opportunity. Tomorrow, things will be easier as a direct result.

3. You Can't Stand Logic Problems

How to know if coding is for you? You have to ask yourself that question.

It's a common misconception that you have to be a mathematical genius to understand programming . You're not at a disadvantage if you weren't an A+ student in school. You do, however, need the ability to solve problems using logical, algorithmic thinking.

Do you have a natural fascination with puzzles? Are you inquisitive and eager to learn why our digital world works the way it does? If not, you're going to find yourself frustrated when you run into these pillars of the craft. They should intrigue you. If they don't, you may want to reconsider.

Much of the intellectual payoff that programming offers comes from solving a puzzle. The more complicated the puzzle is, the more rewarding it feels when you finally crack it. If this feeling doesn't light your fire, programming will be nothing more than an endless parade of frustration and disappointment.

4. You Aren't a Fan of Doing Research

coworkers working together

No matter how much you know about coding, you're always going to run into uncharted territory. Perhaps you're working on a web app, and you can't quite get a framework to cooperate. Maybe your latest project uses Python and you’ve spent ten years mastering Java .

How do you overcome these challenges? There's no master handbook to pop open; the answers must be sought after of your own volition. All you have is code documentation, Google, and the drive to ask the right questions.

If you're not comfortable getting down into the weeds, you won't thrive in a career in programming. It's not always the brainiest developers who end up being the most successful. It's the ones who understand how to break down problems and build the pieces back up into solutions.

5. You Prefer Normal Work Hours

Is programming for me? Absolutely not. I hate working late at night.

Programming jobs are flexible. Some jobs in tech will have you work on-site in an office. Some allow you to work remotely. You can work for a start-up as a freelancer to pave your path, or you can choose a FAANG company for a more traditional corporate career.

In either case, a successful programmer needs to be dedicated. It's not uncommon to hear stories of late nights, long coding sessions, and a diminished work-life balance in either scenario. Software development comes rife with strict deadlines; meeting these deadlines isn't always possible if you're dying to hit the road by five PM.

To get all of the necessary work done, developers often invest plenty of personal time into their work. Even freelancers have to grind through long hours to stay ahead of the competition.

And when do you finally get off the clock? It can be hard to disconnect yourself from your work; you'll likely face long nights lying down for bed, your brain rattling off syntax and possible workarounds. Coding is a labor of love.

How to know if programming is for you: you enjoy the feeling of this constant companion, even when you're supposed to be sleeping. So, if you hate programming, it will be tough to survive the continuous grind.

6. You're Focused Primarily on Salary

hand holding fan made of USD bills

Programming can provide a good living, there's no doubt about it. Perhaps you were skimming job sites and found yourself taken aback by what the top companies in the industry offer entry-level developers. You're not the first, and won't be the last, to try your hand at coding to earn your slice of the pie.

As the market becomes saturated, you'll need to invest in yourself continuously to remain competitive enough to shine in a professional setting. A four-year degree is often (though not always) required, with master's degrees becoming increasingly common in higher-up positions.

Can you make a lot of money as a programmer ? Absolutely. But it won't be an easy road—if you're looking to get rich quickly, you might as well play the lottery.

7. You Don’t Enjoy Constant Learning

Man working on a code

Just like with medical studies, coding requires a specific, evolving skill set that benefits from regular upgrades. As technology evolves, so too does the developer's required knowledge base.

Despite Python and Java consistently topping the market as far as popular languages go, there's seemingly a new language or framework to learn every day. New workarounds, solutions, workflows, syntax... the list goes on.

If you're not someone who wants to keep upgrading their skills, again and again, programming might not be up your alley.

8. You're Not a Fan of Networking

Woman writing down while talking on a video call

While research and analysis are important aspects of coding, there's a necessary soft skill that all programmers need: networking. Community support is extremely helpful when it comes to crossing bumps in the road.

Just like writer’s block, even professional coders need some help to get them through the rough patches. In this regard, the opportunity to reach out to experts who can assist you is invaluable.

While introverts often gravitate towards a career in programming, you’ll have a better chance of succeeding if you’re not afraid to network. If you aren't comfortable stepping out of your comfort zone to secure a job or get help on your latest project, you might want to think about another line of work.

I Don't Like Coding. What Should I Do?

Programming is not for everyone, but you shouldn't give up before you've given coding an honest effort. The best way to find out if coding is right for you is to jump right in and try it. Learn how to script , learn a language, learn from programming books. Anything that broadens your understanding of the craft will help you decide, and this takes time.

The good news: there are many niche opportunities in tech if you're adamant about finding a career you enjoy. If you've already got the degree but discovered coding is not for you, don’t worry. There are plenty of non-programming jobs for computer science graduates that you can consider.

Coding Is Not for Everyone

While anyone can learn how to write code, that's not the same as enjoying a long career doing something you love. It's entirely possible to be a talented developer and still not find a perfect fit.

If you have a heart for business but want to remain connected to the software industry, you'll always be able to find a place in tech to learn and grow. In our bustling world, leaders who understand the intricate process of programming are always in high demand.

  • Programming
  • Work & Career

How to Solve Coding Problems with a Simple Four Step Method

Madison Kanna

I had fifteen minutes left, and I knew I was going to fail.

I had spent two months studying for my first technical interview.

I thought I was prepared, but as the interview came to a close, it hit me: I had no idea how to solve coding problems.

Of all the tutorials I had taken when I was learning to code, not one of them had included an approach to solving coding problems.

I had to find a method for problem-solving—my career as a developer depended on it.

I immediately began researching methods. And I found one. In fact, what I uncovered was an invaluable strategy. It was a time-tested four-step method that was somehow under the radar in the developer ecosystem.

In this article, I’ll go over this four-step problem-solving method that you can use to start confidently solving coding problems.

Solving coding problems is not only part of the developer job interview process—it’s what a developer does all day. After all, writing code is problem-solving.

A method for solving problems

This method is from the book How to Solve It by George Pólya. It originally came out in 1945 and has sold over one million copies.

His problem-solving method has been used and taught by many programmers, from computer science professors (see Udacity’s Intro to CS course taught by professor David Evans) to modern web development teachers like Colt Steele.

Let’s walk through solving a simple coding problem using the four-step problem-solving method. This allows us to see the method in action as we learn it. We'll use JavaScript as our language of choice. Here’s the problem:

Create a function that adds together two numbers and returns that value. There are four steps to the problem-solving method:

  • Understand the problem.
  • Devise a plan.
  • Carry out the plan.

Let’s get started with step one.

Step 1: Understand the problem.

When given a coding problem in an interview, it’s tempting to rush into coding. This is hard to avoid, especially if you have a time limit.

However, try to resist this urge. Make sure you actually understand the problem before you get started with solving it.

Read through the problem. If you’re in an interview, you could read through the problem out loud if that helps you slow down.

As you read through the problem, clarify any part of it you do not understand. If you’re in an interview, you can do this by asking your interviewer questions about the problem description. If you’re on your own, think through and/or Google parts of the question you might not understand.

This first step is vital as we often don’t take the time to fully understand the problem. When you don’t fully understand the problem, you’ll have a much harder time solving it.

To help you better understand the problem, ask yourself:

What are the inputs?

What kinds of inputs will go into this problem? In this example, the inputs are the arguments that our function will take.

Just from reading the problem description so far, we know that the inputs will be numbers. But to be more specific about what the inputs will be, we can ask:

Will the inputs always be just two numbers? What should happen if our function receives as input three numbers?

Here we could ask the interviewer for clarification, or look at the problem description further.

The coding problem might have a note saying, “You should only ever expect two inputs into the function.” If so, you know how to proceed. You can get more specific, as you’ll likely realize that you need to ask more questions on what kinds of inputs you might be receiving.

Will the inputs always be numbers? What should our function do if we receive the inputs “a” and “b”? Clarify whether or not our function will always take in numbers.

Optionally, you could write down possible inputs in a code comment to get a sense of what they’ll look like:

//inputs: 2, 4

What are the outputs?

What will this function return? In this case, the output will be one number that is the result of the two number inputs. Make sure you understand what your outputs will be.

Create some examples.

Once you have a grasp of the problem and know the possible inputs and outputs, you can start working on some concrete examples.

Examples can also be used as sanity checks to test your eventual problem. Most code challenge editors that you’ll work in (whether it’s in an interview or just using a site like Codewars or HackerRank) have examples or test cases already written for you. Even so, writing out your own examples can help you cement your understanding of the problem.

Start with a simple example or two of possible inputs and outputs. Let's return to our addition function.

Let’s call our function “add.”

What’s an example input? Example input might be:

// add(2, 3)

What is the output to this? To write the example output, we can write:

// add(2, 3) ---> 5

This indicates that our function will take in an input of 2 and 3 and return 5 as its output.

Create complex examples.

By walking through more complex examples, you can take the time to look for edge cases you might need to account for.

For example, what should we do if our inputs are strings instead of numbers? What if we have as input two strings, for example, add('a', 'b')?

Your interviewer might possibly tell you to return an error message if there are any inputs that are not numbers. If so, you can add a code comment to handle this case if it helps you remember you need to do this.

Your interviewer might also tell you to assume that your inputs will always be numbers, in which case you don’t need to write any extra code to handle this particular input edge case.

If you don’t have an interviewer and you’re just solving this problem, the problem might say what happens when you enter invalid inputs.

For example, some problems will say, “If there are zero inputs, return undefined.” For cases like this, you can optionally write a comment.

// check if there are no inputs.

// If no inputs, return undefined.

For our purposes, we’ll assume that our inputs will always be numbers. But generally, it’s good to think about edge cases.

Computer science professor Evans says to write what developers call defensive code. Think about what could go wrong and how your code could defend against possible errors.  

Before we move on to step 2, let’s summarize step 1, understand the problem:

-Read through the problem.

-What are the inputs?

-What are the outputs?

Create simple examples, then create more complex ones.

2. Devise a plan for solving the problem.

Next, devise a plan for how you’ll solve the problem. As you devise a plan, write it out in pseudocode.

Pseudocode is a plain language description of the steps in an algorithm. In other words, your pseudocode is your step-by-step plan for how to solve the problem.

Write out the steps you need to take to solve the problem. For a more complicated problem, you’d have more steps. For this problem, you could write:

// Create a sum variable.

Add the first input to the second input using the addition operator .

// Store value of both inputs into sum variable.

// Return as output the sum variable. Now you have your step-by-step plan to solve the problem. For more complex problems, professor Evans notes, “Consider systematically how a human solves the problem.” That is, forget about how your code might solve the problem for a moment, and think about how you would solve it as a human. This can help you see the steps more clearly.

3. Carry out the plan (Solve the problem!)

Hand, Rubik, Cube, Puzzle, Game, Rubik Cube

The next step in the problem-solving strategy is to solve the problem. Using your pseudocode as your guide, write out your actual code.

Professor Evans suggests focusing on a simple, mechanical solution. The easier and simpler your solution is, the more likely you can program it correctly.

Taking our pseudocode, we could now write this:

Professor Evans adds, remember not to prematurely optimize. That is, you might be tempted to start saying, “Wait, I’m doing this and it’s going to be inefficient code!”

First, just get out your simple, mechanical solution.

What if you can’t solve the entire problem? What if there's a part of it you still don't know how to solve?

Colt Steele gives great advice here: If you can’t solve part of the problem, ignore that hard part that’s tripping you up. Instead, focus on everything else that you can start writing.

Temporarily ignore that difficult part of the problem you don’t quite understand and write out the other parts. Once this is done, come back to the harder part.

This allows you to get at least some of the problem finished. And often, you’ll realize how to tackle that harder part of the problem once you come back to it.

Step 4: Look back over what you've done.

Once your solution is working, take the time to reflect on it and figure out how to make improvements. This might be the time you refactor your solution into a more efficient one.

As you look at your work, here are some questions Colt Steele suggests you ask yourself to figure out how you can improve your solution:

  • Can you derive the result differently? What other approaches are there that are viable?
  • Can you understand it at a glance? Does it make sense?
  • Can you use the result or method for some other problem?
  • Can you improve the performance of your solution?
  • Can you think of other ways to refactor?
  • How have other people solved this problem?

One way we might refactor our problem to make our code more concise: removing our variable and using an implicit return:

With step 4, your problem might never feel finished. Even great developers still write code that they later look at and want to change. These are guiding questions that can help you.

If you still have time in an interview, you can go through this step and make your solution better. If you are coding on your own, take the time to go over these steps.

When I’m practicing coding on my own, I almost always look at the solutions out there that are more elegant or effective than what I’ve come up with.

Wrapping Up

In this post, we’ve gone over the four-step problem-solving strategy for solving coding problems.

Let's review them here:

  • Step 1: understand the problem.
  • Step 2: create a step-by-step plan for how you’ll solve it .
  • Step 3: carry out the plan and write the actual code.
  • Step 4: look back and possibly refactor your solution if it could be better.

Practicing this problem-solving method has immensely helped me in my technical interviews and in my job as a developer. If you don't feel confident when it comes to solving coding problems, just remember that problem-solving is a skill that anyone can get better at with time and practice.

If you enjoyed this post, join my coding club , where we tackle coding challenges together every Sunday and support each other as we learn new technologies.

If you have feedback or questions on this post, feel free to tweet me @madisonkanna ..

Read more posts .

If you read this far, thank the author to show them you care. Say Thanks

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

  • Data Science
  • Courses 2 Offers Active

Featured Sprints

Get the Reddit app

The subreddit covers various game development aspects, including programming, design, writing, art, game jams, postmortems, and marketing. It serves as a hub for game creators to discuss and share their insights, experiences, and expertise in the industry.

Why am I so bad at programming?

I've been coding for nearly a year (self-taught), but I feel like I haven't made any progress. I've done Python, Java, MySQL, and now I'm trying Unity out with C#. I've been using Unity since December 2020, but I have not completed a single game. I really want to make a cool and simple top-down game but I keep stumbling on problems. I couldn't even figure out how to make a player move without Google because I'm so dumb!!

Now, I'm stuck on a shooting bug. I want to make a player fire a projectile by setting the projectile's rigidbody velocity towards the crosshair. But I don't even know how to make that work. I've been working with Unity for a few months now and I've barely made progress. On YouTube, I always see people creating such cool freaking games two months into Unity and they're all better than me. I just feel so unmotivated right now. Why am I so bad? What am I doing wrong? Am I moving too fast? If so, why are there so many other people who move faster than me, and yet they're doing fine? Why??? I really like Computer Science but I lack the problem solving and mathematical knowledge. I can't even solve simple interview questions on LeetCode, like TwoSum. Sighhh. Sorry if my question is bad or I asked it wrongly.

By continuing, you agree to our User Agreement and acknowledge that you understand the Privacy Policy .

Enter the 6-digit code from your authenticator app

You’ve set up two-factor authentication for this account.

Enter a 6-digit backup code

Create your username and password.

Reddit is anonymous, so your username is what you’ll go by here. Choose wisely—because once you get a name, you can’t change it.

Reset your password

Enter your email address or username and we’ll send you a link to reset your password

Check your inbox

An email with a link to reset your password was sent to the email address associated with your account

Choose a Reddit account to continue

IMAGES

  1. Six steps to solving a programming problem infographic

    bad at problem solving programming

  2. 6 Ways to Improve Your Programming Problem Solving

    bad at problem solving programming

  3. programming steps to solve problems

    bad at problem solving programming

  4. Problem Solving and Python Programming

    bad at problem solving programming

  5. Problem Solving In Programming

    bad at problem solving programming

  6. Problem Solving in Programming

    bad at problem solving programming

COMMENTS

  1. Does being bad at solving programming problems means not being ...

    Programming encompasses various skills, including problem-solving, coding efficiency, and collaboration. A well-rounded programmer excels in multiple areas, not solely in problem-solving prowess. 2. Collaboration and Communication: Programming is often a collaborative effort within a team or across departments.

  2. Im a programmer and i am bad at problem solving

    A good programmer spends considerable time thinking about the problem and potential solutions before even starting to devise an algorithm. Just starting to hack in the first solution will lead only to consistent failure. Learn to plan. Learn to think problems through before even going anywhere near a computer. Nvidia1060croatia.

  3. Good at problem solving, but bad at coding. What can I do to ...

    Edit: I think my problem is how I write my pseudocode as well. I think I need to start writing more in detail and then implementing my code. The issue above still stands, but I thought I might need to say this as well. Also, I am using Java. Edit 2: Thank you @ everyone who tried to help me solve this.

  4. How to Get Better at Solving Programming Problems

    However, I need to be able to solve problems of all types. So I'm using a variety of platforms and resources to get practice. Here are some examples: LeetCode. Interview Cake. Cracking the Coding Interview by Gayle Laakmann McDowell. Exercism. Python Workout by Reuven Lerner. Weekly Python Exercise by Reuven Lerner.

  5. Realised that I am very very very bad problem solver

    Solving interview-style problems is a skill that can be learned. It takes some exercising to get used to it. If you practice it enough, you will recognize patterns which will help you to solve most problems. However, interview-style problems are nothing like actual day-to-day programming problems. They require you to use as many existing ...

  6. Programming is Really Hard

    Programming is Really Hard - But Don't Give Up. Learning to do something new is hard. Whether it's a physical feat like reaching a new best lift or a mental challenge like learning a new language - both entail months of work, multiple setbacks, and hundreds of hours of time put in. And then you still might just be at an intermediate level.

  7. 10 Common Obstacles of Those Struggling to Learn Code

    2. You want to learn too fast. Being motivated to learn how to code will help you get through the rough spots, but you can also take it too far. When you're learning to code, you have to crawl before you can walk. Remember — you'll get there, but you need to start with the basics and build your skills.

  8. Problem-Solving. How to Boost Your Ability to Solve Programming Tasks

    Post updated on April, 15th, 2024 The ability to tackle complex programming problems and solve them by finding non-obvious, witty or simply functional solutions quick enough is one of the core skills for any software developer, and it is often used to evaluate a programmer's professional level and capabilities. The approach and problem solving skills are what distinguishes a Senior coder ...

  9. I Can't Use Logic In Programming. What Should I Do?

    4. Work on different types of problems: Try to solve a variety of problem types, such as algorithms, data structures, and mathematical puzzles. This will help you to develop a broad range of problem-solving skills. 5. Read and Learn: Read books, articles, and documentation on logic and problem-solving. This will help you to learn new techniques ...

  10. How to think like a programmer

    Simplest means you know the answer (or are closer to that answer). After that, simplest means this sub-problem being solved doesn't depend on others being solved. Once you solved every sub-problem, connect the dots. Connecting all your "sub-solutions" will give you the solution to the original problem. Congratulations!

  11. 8 Signs You Aren't Meant to Be a Programmer

    The reality: some people just hate coding. If you're unsure whether you're meant to be a programmer, here are some signs that may indicate a bad fit. 1. You Lack Experimental Creativity. Despite its foundation in logic, programming is very much a creative art. A new program is like a blank canvas. Your paintbrushes and palette of colors are ...

  12. Hands-on Tutorial: How To Improve Your Problem-Solving Skills As A

    Programming is ultimately problem-solving. We only apply the programming language to express how we've thought about a problem and the approach we're using to solve it. The worst thing you could do is to start chipping away at the problem once it's presented. This is where most newbie programmers get stuck and give up.

  13. How to Solve Coding Problems with a Simple Four Step Method

    In this post, we've gone over the four-step problem-solving strategy for solving coding problems. Let's review them here: Step 1: understand the problem. Step 2: create a step-by-step plan for how you'll solve it. Step 3: carry out the plan and write the actual code.

  14. 7 Common Mistakes That Beginners Should Avoid While ...

    Explain what solution you have tried to solve the problem and what was the outcome of it. Explain exactly what you think should be happening. Explain why you think it should be working differently. 6. Not Paying Attention to Change the Bad/Spaghetti Code. Your code is similar to the exercise you do in your gym or a daily workout plan.

  15. How to think like a programmer

    Problem-solving skills are almost unanimously the most important qualification that employers look for….more than programming languages proficiency, debugging, and system design.

  16. How To Approach A Coding Problem

    These steps you need to follow while solving a problem: - Understand the question, read it 2-3 times. - Take an estimate of the required complexity. - find, edge cases based on the constraints. - find a brute-force solution. ensure it will pass. - Optimize code, ensure, and repeat this step. - Dry-run your solution (pen& paper) on ...

  17. 7 Key Signs of a Bad Programmer: How to Spot Incompetence in ...

    Lack of Problem-Solving Skills: At its core, programming is about problem-solving. A bad programmer may lack the ability to analyze complex issues, approach problem-solving systematically, or ...

  18. Online Coding Practice Problems & Challenges

    Welcome to Practice! Practice over 5000+ problems and challenges in coding languages like Python, Java, JavaScript, C++, SQL and HTML. Start with beginner friendly challenges and solve hard problems as you become better. Use these practice problems and challenges to prove your coding skills. Old practice page Recent Contest Problems.

  19. What are some tips to become a better problem solver for ...

    Teach yourself C in 21 days, the problem with these higher level languages is the level of abstraction is really bad for problem solving. On Amazon you can score it for 22 bucks. There is also the C programming language, very informative, but the exercises are harder than Dark Souls to a newbie.

  20. The 10 Signs of a Bad Programmer: How to Spot Coding ...

    Disorganized code is challenging to read and maintain. Signs of poor code organization include inconsistent naming conventions, excessive duplication, and a lack of clear structure in the codebase ...

  21. Does being bad at solving programming problems means not being ...

    Solving puzzles != real programming. Very few skills will translate over to the real world. Competitive puzzling is a hobby and practicing is the best way to get better. Most top solvers have been solving puzzles for years. I don't do it competitively but I love to solve the problems.

  22. Practice

    Platform to practice programming problems. Solve company interview questions and improve your coding intellect

  23. Problem-solving? No, problem-opening! A method to reframe and teach

    Starting from the recognition of the limits of today's common essentialist and axiological understandings of data and ethics, in this article we make the case for an ecosystemic understanding of data ethics (for the city) that accounts for the inherent value-laden entanglements and unintended (both positive and negative) consequences of the development, implementation, and use of data-driven ...

  24. Why am I so bad at programming? : r/gamedev

    Problem solving is a skill that people develop (pardon the pun) over time. e.g. If you practice solving math problems you get better at solving math problems. Programming is no different. What makes game development so challenging is that there are many areas to specialize in: Graphics, Physics, Networking, UI, Audio, etc. And I haven't even ...