Does speed determine my success as a programmer?

Hello I recently finished a problem that took me around 8 hours to finish. I broke the problem down before even coding and had the correct idea but implementing some features took a lot of time debugging and in many cases resorting to trial and error. I really want to improve my problem solving abilities but also want to get a real judgement on whether this is considered slow and unprofessional or if is normal for even experience folks to sometimes get trap in a problem.

The problem was:
read the str parameter being passed, which will represent the movements made in a 5x5 grid of cells starting from the top left position. The characters in the input string will be entirely composed of: r, l, u, d, ?. Each of the characters stand for the direction to take within the grid, for example: r = right, l = left, u = up, d = down. Your goal is to determine what characters the question marks should be in order for a path to be created to go from the top left of the grid all the way to the bottom right without touching previously traveled on cells in the grid.

To make matters worst, I analyzed another users code after I was done and he had done it and 1/3 of the amount of lines it took me. Also curious to know what is the expected time limit range for a professional programmer to complete this problem? Thanks

Last edited on
A programmer might need more information than that. Give us an example, someone may be able estimate the time from there.
For example: if str is "r?d?drdd" then your program should output the final correct string that will allow a path to be formed from the top left of a 5x5 grid to the bottom right. For this input, your program should therefore return the string rrdrdrdd. There will only ever be one correct path and there will always be at least one question mark within the input string.
So what is '5x5 grid of cells'?
This is a two-dimensional array. What you give me is "r?d?drdd", which is technically an one-dimensional array.
Don't worry about speed for now. Sure, when you get a tough interview question later on, it will be nice if you can give a great solution in a reasonable amount of time. However, for learning, the important thing for you to do is think of the problem in depth, look at it from different angles, think about different approaches or different existing algorithms and data structures that might help, etc.

And you should realize that these types of problem can be solved almost directly with existing programming techniques. So of course, other users may come up with some creative and novel way to solve it, but chances are, those with the best solutions have just come across similar problems and have learned which tools to use.

In my opinion, it's good to get some practice in both: trying to solve problems from scratch, and recognizing and applying the right tools to solve a problem. If you try to do it from scratch, of course it may take you longer and your solution might be much less than perfect, but it's still a great exercise. But in the real world it's good to make your life easier by using existing solutions.

Last edited on
So what is '5x5 grid of cells'?
This is a two-dimensional array. What you give me is "r?d?drdd", which is technically an one-dimensional array.

The grid is not part of the input but rather the test bed, the problem is you are giving a string that will represent the directions, right, left, etc. You have to figure out what direction the ? marks characters need to be for the grid to travel from the top left to the bottom right so for example if you find the case for this than your grid is.

1 1 1 0 0
0 0 1 1 0
0 0 0 1 1
0 0 0 0 1
0 0 0 0 1

The 1 represent the the cells you have traveled to, Keep in mind since we start at the top left the first cell is 1, so when you move right it would be the next cell in the first row. Hopefully the explanation is not confusing and you get the idea.
Last edited on
It is not an assignment for a beginner. It is not that too advanced though, someone like me can solve it within 3 hours or less.

Did you solve it in an efficient way?
Last edited on
> Does speed determine my success as a programmer?

No. With experience, one would automatically reach an acceptable speed.
Right now, it is far more important to learn to program using idiomatic C++.

For a beginner, working from first principles, taking eight hours to solve this problem completely is not excessive.

> is it normal for even experienced folks to sometimes get trapped in a problem?

Yes. Fortunately, all serious programming involves many programmers working in tandem; so we seek (and get) assistance when (ideally before) we get trapped.

Never design alone if you can avoid it! Don't start coding before you have tried out your ideas by explaining them to someone. ...

When you get stuck implementing a program, look up from the keyboard. Think about the problem itself rather than your incomplete solution. Talk with someone: explain what you want to do and why it doesn't work. It's amazing how often you find the solution just by carefully explaining the problem to someone. Don't debug (find program errors) alone if you don't have to.

- Stroustrup in 'Programming: Principles and Practice using C++'

Did you solve it in an efficient way?

This is the process I used to solve it. Like i mentioned before i had the solution in my head after a few minutes. I can also showcase the code for further input.

Check when there are ? marks
If found set up a move option that will try out the different movements that can be done
Make sure you only try the movements that follow the rule meaning no out of boundary or trace back
Keep track of the index for the grid and string
When you try a movement direction remember to update the grid
Keep looping through the string
If you come across another ? mark, do the same step
You will maybe need an array of string to keep track of the move options
Also an array of integers to keep track of the indexes
Continue this progress and also update when there are no question marks
When you come across an error, trace back on the index and now check for another move option
Update the grid from that point
If you have checked all the options of that ? mark and there where more previous ? marks ie( ???rlu)
Return to the previous ? mark and check the move options there
Keep looping the string
Again repeat the process of checking for errors
If no errors where giving along the way and we finish the path, but did not reach the goal
Repeat the same progress of tracing back to the previous ? mark

Thanks for the other replys
Topic archived. No new replies allowed.