DEV Community

Cover image for How to answer programming challenges
Shanice
Shanice

Posted on

How to answer programming challenges

When tackling a problem, many of us like to go straight into working toward a solution. This may not be the best approach. Just like when we had to write an outline before we wrote our essays, we must also outline our solution to each coding challenge. Let's take a look at 5 steps we can take to prepare for solving a challenge.

Sample Coding Challenge:

I need to know how long each student's name is so that I can know how much space I will need to reserve on my board for each name. Write a function that takes in a student name and returns how long each name is. I will need the result as a number.

Step 1: Rewrite the problem in your own words.

For this challenge, I would write something like:
Return the length of a string

Step 2: Recognize and note whether or not there are any parameters

For this challenge, I would write something like:
String name

What I'm saying here is that the function will take in a string and the string will be a name.

Step 3: Recognize and note what needs to happen to the result.

For this challenge, I would write something like:
Return an integer/number

Step 4: Write some pseudocode

For this challenge, I would write something like:
take input from function
count the characters in input
display the count

Writing out the pseudocode gives you a chance to work through the logic of the problem in a nontechnical way.

Step 5: Write out an example

For this challenge, I would write something like:

function findNameLength(name){
    let count //variable to hold count of characters
    name.length //string property to find length of strings
    return integer/length
}
Enter fullscreen mode Exit fullscreen mode

Every person's problem solving processes are different, so you might include more or less in these steps.

Before you tackle your next challenge, give these steps a try. If you have steps that aren't listed above, list them below :)

Have a great day!

Top comments (0)