Tough Coding Interview? PEDAC is the way to go

The problem solving tool you should know

Andrea Young
The Marcy Lab School
3 min readDec 15, 2020

--

For all of my coders in the world, may I introduce to you another way of problem-solving: PEDAC. It can save you time on a problem and broaden your way of thinking.

How many times have you skimmed through a problem and started coding before really understanding the question? For very easy problems that might work. But, for the bigger problems, it will be hard on your brain to keep everything together. This is where PEDAC comes in handy, it helps keep you organized and focused by breaking the problem down into steps: Process, Examples, Data (structure), Algorithm, and Code.

Processing the Problem

First, you have to understand what the problem is asking you to do. NO CODING IS NECESSARY. Rephrase the problem in your own words. You can write it down on a piece of paper, whiteboard, notepad, or whatever works best for you. It is also best to identify the inputs and the outputs of the problem.

Let's try using PEDAC for this problem:

// Write a function that reverses a string passed into it.
function solution(str){

}

Think of the best way you would explain this problem to somebody else.

Ask yourself:

What is a string? What am I inputting? What am I outputting? What am I reversing? Any rules?

Examples and Test Cases

Now that you have a complete understanding of the problem, try to come up with some examples. Testing edge cases are also very important. It would be a real bummer if your code isn’t working because of an edge case you bypassed. Like, what happens when no string is passed in? What about capitals and punctuation? Ask your interviewer about things like this.

‘me’ => ‘em’
‘Hello’ => ‘olleH’
‘ ‘ => ‘ ‘

Data structure

There are usually numerous ways a problem can be solved. This step helps you by selecting what you think is the best data structures for your algorithm. Think of how and what you will use to implement data.

store the substrings in a variable called: newStr

Focus on what makes the most sense for you. Sometimes less isn’t always the best. You can always refactor your solution later.

Algorithm

Your algorithm is your key to success. Not having an algorithm is like not having a blueprint of a building you are constructing. This step is definitely not one to rush. Algorithms can be tricky to create, remember to look back at your examples and data structure if you get stuck.

create an empty str variable called newStr
loop through the str starting at its length -1
increment by counting down
at every index set it equal to the str variable
return the str

Code

Last but not least, the moment you have been waiting for!

Writing code should be a breeze. You made sure you thoroughly understood the problem, made test cases, figured out what data structures to use, and came up with an algorithm.

This may have taken a little longer than expected, but it was definitely worth it!

--

--