What is Your Approach to Solving Problems With Code?
Anita Olsen

Anita Olsen @anitaolsen

About: Greetings! I am a retired hard of hearing hobbyist coder 😊 I am into learning new things, finance, reading, writing and playing video games.

Location:
Norway
Joined:
Oct 27, 2023

What is Your Approach to Solving Problems With Code?

Publish Date: Jun 3
35 37

I do my best to remember what I have learned, to think outside the box, to be creative and break the code into smaller parts when necessary, but it is not always easy to do so.

CodeCombat sometimes asks me to complete a level with x line of code. For example: "Use 8 lines of code" and another which offers a greater reward with "Use 4 lines of code". I usually manage to complete the level with the lowest maximum line of code and sometimes even less than that which makes me feel great!

Problem-solving is one of the most important skills a programmer should have as programming is about problem-solving as well as writing lines of code. There is more than one way to solve problems and I wonder what other people's approaches to problem solving are.

Do you have a particular approach to problem solving? Do you have a step method or something which you follow? What is your approach to solving problems with code?

Comments 37 total

  • Ben Link
    Ben LinkJun 3, 2025

    I tend to find that if a Developer is going to go "off the reservation" they'll do it in chasing that bit of optimization that gets us from 6 lines to 5 or whatever... so I try to stay focused on the words "Solving Problems" rather than "with Code".

    First iteration: Solve the problem.

    Second: Clean up egregious stuff.

    Try to stop there unless new information comes to light or unless the system is life-and-death - because otherwise, you can spend a lifetime tweaking something - the returns diminish rapidly.

  • Ben Halpern
    Ben HalpernJun 3, 2025

    A key for me is reduction of variables. So like removing lines of code debugging etc.

    I think this applies to general problem solving. Figure out what you don't have to worry about first.

  • Mohamed Ashiq Sultan
    Mohamed Ashiq SultanJun 3, 2025

    This may not work for coding challenges and Im not sure why number of lines matter. But below is what I follow for real time problems

    1. Never start to solve the problem directly from code.
    2. Have a pen and paper, visualize what exactly you are trying to solve. Think twice, code once
  • Ayesha Tariq
    Ayesha TariqJun 3, 2025

    I totally agree. Problem-solving is the real core of programming. My usual approach is to break the problem into smaller chunks, write down what I think should happen step by step, and only then start coding. I also try to rewrite the problem in plain language before jumping into syntax.

    Funny enough, I sometimes take short breaks when stuck, like browsing random things to reset my brain. The other day I ended up scrolling through the kfc menu while debugging a tricky function 😅. It worked, though the solution clicked right after!

  • Reid Burton
    Reid BurtonJun 3, 2025

    I just readthedocs.Io

  • Nathan Tarbert
    Nathan TarbertJun 3, 2025

    Honestly, trimming code down always feels so good for me too - feels like cracking a puzzle.

  • Paulo BO
    Paulo BOJun 3, 2025
    1. Entender el problema a fondo Leer atentamente la descripción.

    Pedir ejemplos concretos o el error exacto.

    Aclarar el contexto (lenguaje, entorno, versiones, qué se espera vs qué pasa).

    1. Reproducir el problema Intentar replicar el error o comportamiento problemático.

    Esto puede incluir copiar código, datos o condiciones.

    1. Analizar el código Revisar lógica, sintaxis, uso de librerías.

    Comprobar si hay errores comunes (variables no inicializadas, mala indentación, problemas de tipos, etc.).

    1. Buscar mensajes de error o logs
      Revisar outputs, mensajes en consola, trazas de error para pistas.

    2. Probar soluciones aisladas
      Simplificar el código a un ejemplo mínimo que reproduzca el problema.

    Aplicar cambios pequeños y evaluar su impacto.

    1. Consultar documentación y recursos Revisar documentación oficial, foros, Stack Overflow, etc.

    Asegurar que las soluciones propuestas sean actuales y relevantes.

    1. Explicar y comunicar Describir la causa raíz del problema.

    Proponer soluciones claras y detalladas.

    Incluir ejemplos o fragmentos corregidos.

  • Nevo David
    Nevo DavidJun 3, 2025

    Pretty cool seeing you trim the code like that, feels nice when it clicks. For me, most of the time it’s just chipping away even when it’s slow, and every now and then it adds up.

  • Dotallio
    DotallioJun 4, 2025

    I like to sketch out the smallest possible solution first, then layer improvements. Do you find the code length challenges change the way you think about problems?

    • Anita Olsen
      Anita OlsenJun 5, 2025

      Aha, I see. Hm, perhaps. It certainly forces you to become more creative!

  • SamuraiX[13~]
    SamuraiX[13~]Jun 4, 2025

    I always choice the first and simplest solution that comes to my mind and make it better later only if needed or if I have extra time

  • Luis Faria
    Luis FariaJun 4, 2025

    Really loved reading all the different takes here!

    For me, it’s all about progressive breakdown. I usually start high-level (what’s the actual outcome?) then gradually break it into smaller chunks that I can test fast.

    Totally agree with the idea of solving the problem first, then worrying about polishing or line counts later. That mindset helped me ship real features in the wild where messy > perfect if it moves the needle, haha

    That said, trimming lines on platforms like CodeCombat still feels like solving a puzzle on expert mode. Super satisfying when you crack it!!

  • Deividas Strole
    Deividas StroleJun 4, 2025

    My approach to solving problems with code starts with understanding the why—what exactly needs to be solved and who it impacts. I break the problem down into smaller, manageable parts, then plan a solution before touching any code. I usually write pseudocode or draw diagrams to map things out, then start building iteratively—testing and refining as I go. I also try to keep things simple and readable, because future me (or someone else) will thank me later. And when I get stuck, I ask questions, read docs, or look for patterns in how others have solved similar issues. Problem-solving with code is as much about mindset as it is about syntax.

  • Ankit Rattan
    Ankit RattanJun 4, 2025

    I usually start by breaking the problem into smaller, manageable parts to clearly understand what’s being asked. Once I’ve grasped the requirements, I try to relate it to any standard approach or technique I’ve learned—either from coursework or practice. I actively solve daily problems, like LeetCode’s Problem of the Day (POTD), and regularly follow structured problem-solving sheets like Striver’s, which also include detailed solution approaches. This routine helps me recognize patterns more quickly and apply the most efficient solutions. Hope this works!
    Just break the problem into smaller problem -- (just like tagline of recursion 😅)

  • Rose Media House
    Rose Media HouseJun 4, 2025

    Back in the day, I used to do codeforces. good times.

    • Anita Olsen
      Anita OlsenJun 4, 2025

      Oh wow, that sounded like an awesome one!

      • Rose Media House
        Rose Media HouseJun 4, 2025

        Yes, although I was not very good at solving. My highest rating was 1150, which was considered mid.

  • A. Moreno
    A. MorenoJun 5, 2025

    In my experience, the simpler a solution is, the better it works. After that, I just try to go with the flow of the code and try to optimize it at the very end if it is needed.

  • csm
    csmJun 5, 2025

    A good teacher on youtube once said:

    1. Understand the problem
    2. Think of a solution
    3. Implement that solution with brute force method. That is, just get a working prototype.
    4. Then look at your code again, see where you can optimise.

    This approach really worked for me!

  • Block Experts
    Block ExpertsJun 5, 2025

    The first thing i start with is removing any duplicated code and export them in separate functions, then make components as less dependent as possible.

  • Dinh Hoang Duy
    Dinh Hoang DuyJun 5, 2025

    I think it's always a trade-off between writing concise code and keeping it readable and maintainable. I usually aim for clarity first, then try to simplify without losing meaning.

  • Philemon Adaghe
    Philemon AdagheJun 6, 2025

    I use print/debug statements if needed to trace logic.

  • astro
    astroJun 6, 2025

    For my experience it depends on what you work. If you try with coding challenge is understand the proble, write a brute solution and then improve the solution. Instead if you talk of developing a code or an app or website, only studying and practice.

  • Peter Vivo
    Peter VivoJun 6, 2025

    My first step to solve a problem, is setup the state structure which collect a necessary data from input and good enough to represent the goal data.
    After that step I just need to make two method:

    • convert input to state.
    • find out the result by use state

    This method work even complex problem, when state are some stream.

  • I AM ALEX
    I AM ALEXJun 8, 2025

    🎁 $15 Crypto Airdrop on duckybsc.xyz — Claim before June 11!

    duckybsc.xyz

  • Vincent Tommi
    Vincent TommiJun 8, 2025

    I have just read some great insights.

  • pope ✪
    pope ✪Jun 8, 2025

    I have learnt the hard way that diving headfirst into code is a bad idea.
    My process is simple.

    1. Understanding the problem - You can research with google or AI, YOUR CHOICE.
    2. Plan the solution -You could use diagrams or just write out the steps you think are needed in plain English.
    3. Turn your plan into something that looks like code but with 0 syntax errors, pseudo code.
    4. From there, you are free to use any programming language you want to build whatever it is you are building.

    This reduces time spent figuring out how stuff work when writing the actual code.

  • Frances
    FrancesJun 8, 2025

    cookie clickerhas revolutionized the idle gaming genre since its creation in 2013. This deceptively simple yet incredibly engaging game has captured the hearts of millions of players worldwide, turning a basic concept into a global phenomenon.

  • Meenakshi Agarwal
    Meenakshi AgarwalJun 8, 2025

    Nice thoughts! I also break problems into small steps and test as I go. One thing that helps me is pretending I'm explaining the problem to someone else—it often gives me new ideas. Shorter code is cool, but clear code that solves the problem is even better.

  • Thaísa Vieira
    Thaísa VieiraJun 9, 2025

    Usually I like to stop and think if I did understand the problem and what it's asking me to do, paper and pen are always close to taking some notes and breaking the problem into smaller parts. If I get stuck, I ask myself, Is it a logical or language problem that sticks me.

Add comment