DEV Community

Cover image for Pseudocode Like a Badass: Breaking Down Problems and Figuring Out What They’re Asking For
The Holistic Technologist 👩🏻‍💻
The Holistic Technologist 👩🏻‍💻

Posted on • Edited on

Pseudocode Like a Badass: Breaking Down Problems and Figuring Out What They’re Asking For

Hello beautiful people!

In this post I’ll share some tips on breaking down coding challenges using pseudocode*. It also includes a video of me working through a newbie-friendly coding challenge on Codewars!

As someone who has worked with over 100 emerging software engineers, one of the common blockers I’ve seen is that folks get paralyzed when initially presented with a coding challenge or project. They believe that they don’t know how to solve the problem or the task feels too big. I remind them that they don’t have to climb the whole mountain, just try to take the next step.

My approach to strengthening this skill is centered around communication. Language is not only a way to express what we think or feel, but also can be a tool for shaping the way we relate to what we’re doing and to develop patterns in our learning. Asking yourself an excessive amount of questions can help you get better at asking the right questions, to lead to the right answers.

Image description

I highly recommend TALKING OUT LOUD through this process- whether its to yourself, rubber duck, or another dev. Programming is very similar to learning a new language. It’s one thing to study but fluency comes from having conversations, exchanging ideas, and figuring out how to communicate our ideas better.

Pseudocode is a plain description of the steps in a coding problem or algorithm.

Using P.R.E.P to Dissect Coding Challenges

The objectives of pseudocode are: to get your mind to think about a problem in layman’s terms, lay a foundation to build your code on, and get past the initial fear of starting. I ask myself questions and write down every single thought or idea I have relating to the problem- to begin with what I know. Take what resonates. 😃

Note: Examples will be in Javascript

📍 One method we introduce to our students at Resilient Coders is: P.R.E.P, which stands for Parameters, Return, Examples, and Pseudocode.

Below is a set of questions I’ll start with when solving a coding challenge:

Parameters: What are the parameters of the function?

  • What data type(s) are they?
  • What are the constraints?
  • How will I be working with those parameters / what do I need to do with them?
  • if numbers: will most likely have to do some kind of operation
  • if arrays: loop through them
  • if objects: work with key:value pairs or its properties
  • I sometimes will think about edge cases here as well such as empty parameters, special characters, etc.

Return: What will the function return?

  • Will I mutate the parameter and return it or return a something new?
  • 💡 use clues from the problem i.e ‘return a new array of even numbers’
  • it may be helpful to store the return in a new variable

Examples: Understanding the expected return

  • Coding challenges will often provide an example but it would be helpful to create 2-3 examples of your own to think through the parameters and returns.

Image description

Pseudocode: Steps to code

  • This is where I’ll try to create a step by step guide to solve the problem, starting with what I know.
  1. Write a function
  2. Declare a variable
  3. Loop through the array
  4. If the element is... (write conditional statements)
  5. Return x variable
  • Look for action words in the the problem to break up the sentences and use that as your guide. i.e “take the array”, “if it is”, “then do this” = 3 smaller steps to take rather than ONE big step
  • Look for keywords in the problem to give you clues on what methods to use i.e “filter” or “new array” to me indicate I may have to use Array.filter() or Array.map(), respectively

side plug: check out my array methods cheatsheet!

From there, it’s a process of asking “what’s next?” over and over again. After this step, what do you want to happen? It’s not important how many steps there are left or if the steps aren’t linear. We’re trying to create a blueprint and get as specific as possible. The more you can clearly communicate your issue or blocker, hopefully it will be easier to Google or ask for help when you’re stuck!

Pseudocode in Action

📍 Here is a video of how I use P.R.E.P to solve this codewar: Complete the function that takes a list of numbers (nums), as the only argument to the function. Take each number in the list and square it if it is even, or square root the number if it is odd. Take this new list and return the sum of it, rounded to two decimal places.

Closing

While I don’t believe that coding challenges during technical interviews are reflective of what someone has to offer in a SWE role, I do think they’re helpful while learning how to code and implementing larger concepts.

Sometimes the next steps won’t make sense or come to you until you start writing code- and that’s just part of the process! As you continue to practice breaking down problems, I hope you’ll find the questions and systems that work best for you.

Tune in next time for tips on architecting single projects and applications!

Happy coding 👾

Ellie

Top comments (0)