• Ever wanted an RSS feed of all your favorite gaming news sites? Go check out our new Gaming Headlines feed! Read more about it here.
  • We have made minor adjustments to how the search bar works on ResetEra. You can read about the changes here.

Maple

Member
Oct 27, 2017
11,732
I started learning how to code last August, and after reading some books and watching Youtube videos feel that I have made some OK progress. I'm using Java, and am comfortable with functions, variables, conditional statements, arrays, 2D arrays, some basic I/O, and even a little recursion.

I'm enjoying and thought that if I maybe keep at it, I can perhaps switch careers and get into software development. So I went on Leetcode to look up some problems to start practicing.

I've gone through dozens of "easy" problems so far, and to be honest...I don't even understand what half of these are asking. Some examples:
Is it bad that I'm familiar with the aforementioned concepts, and have utilized them in basic little programs I've written, but can't even understand what easy Leetcode problems are asking? I've read that you don't need a CS or engineering degree to become a good programmer, but after looking at some of these problems, I feel like I need a math degree to even know where to start to solve some of these.
 

Red

Member
Oct 26, 2017
11,698
The first one just wants you to reverse the sequence of numbers. The second is pretty well explained and I am not sure how it could be more concisely reworded.

You are probably overthinking it.

No one is going to be giving you problems like this on the job and your success here isn't likely to make or break your career. Get some projects under your belt and keep applying for work.
 

SweetNicole

The Old Guard
Member
Oct 24, 2017
6,542
Assuming for reverse integer problem that you're not handling overflow, all you need to know for reverse integer is how to do modulo. Alternatively, you could do some string manipulation which is also fairly easy to do with built in string functions.

Count and say it helps if you literally say it out loud.
 

Felt

The Fallen
Oct 27, 2017
3,210
Just take an algorithms and data structures course on Coursera. The logic is language-agnostic, but that is where these kinds of problems come from, which are common interview questions in some fields like fin-tech.

fakeedit; not these starting ones you posted, but the more challenging ones
 
OP
OP
Maple

Maple

Member
Oct 27, 2017
11,732
No one is going to be giving you problems like this on the job and your success here isn't likely to make or break your career. Get some projects under your belt and keep applying for work.

Are problems like this not representative of what professional software developers work on?
 

Red

Member
Oct 26, 2017
11,698
Just take an algorithms and data structures course on Coursera. The logic is language-agnostic, but that is where these kinds of problems come from, which are common interview questions in some fields like fin-tech.

fakeedit; not these starting ones you posted, but the more challenging ones
In addition to Coursera, there are other valuable resources available for self-teaching. Codecademy, Udemy, Udacity, EdX, Khan Academy, etc. If you haven't checked these out, do.
Are problems like this not representative of what professional software developers work on?
I can't imagine anyone who isn't working on a coding practice course would ever have to write or test that code.

That's not to say it isn't useful to practice coding puzzles. I learned the basics of PHP by leveling up in Codewars when I first started working front end. It got me a long way.
 
Last edited:

FreezePeach

Banned
Oct 25, 2017
12,811
Are problems like this not representative of what professional software developers work on?
Many of these things are simply ways to showcase how to use a language to solve something rather than practical stuff on the job. You'll probably just be taking over someone elses code on an actual job before writing your own.
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,191
Very quick and dirty approach to the first problem - use a StringBuilder - which can do cool stuff with Strings. But, you'll have to cast the argument as a String and then with that, you can cast it back as Integer. You should do some checks on the argument for it to actually be an integer.

Java:
public static int reverse(int x) {
        StringBuilder builder = new StringBuilder(Integer.toString(x)).reverse();
        return Integer.parseInt(builder.toString());
    }
 

Subutai

Metal Face DOOM
Member
Oct 25, 2017
937
Off-topic, but since this is a coding thread (Sorry for hijacking the thread, I'll delete this if you want me to):

As someone completely new to programming, would it be better to start with JavaScript or Python 3? More so, what would help me more in job opportunities?

Again, sorry for using this thread for this question. I didn't want to clutter EtcetEra with a new topic for this simple question.
 

Vanillalite

Banned
Oct 25, 2017
7,709
Off-topic, but since this is a coding thread (Sorry for hijacking the thread, I'll delete this if you want me to):

As someone completely new to programming, would it be better to start with JavaScript or Python 3? More so, what would help me more in job opportunities?

Again, sorry for using this thread for this question. I didn't want to clutter EtcetEra with a new topic for this simple question.

Take the advice above and learn the logic first. Focus more on basic coding logic skills vs focusing on a specific language.

Learn things like data types, loops, conditionals, arrays etc...
 

SweetNicole

The Old Guard
Member
Oct 24, 2017
6,542
Very quick and dirty approach to the first problem - use a StringBuilder - which can do cool stuff with Strings. But, you'll have to cast the argument as a String and then with that, you can cast it back as Integer. You should do some checks on the argument for it to actually be an integer.

Java:
public static int reverse(int x) {
        StringBuilder builder = new StringBuilder(Integer.toString(x)).reverse();
        return Integer.parseInt(builder.toString());
    }

That's only if they allow you to cast. If you can't, this would be the better way, although it doesn't account for overflow.

Java:
class Solution {
    public int reverse(int x) {       
           int reverse_number = 0;
           (while x > 0) {
                    reverse_number = reverse_number*10 + x%10;
                    num = num/10;
            }
          return reverse_number;
    }
}

im a developer and these are dumb

Yeah, they are.
 

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
Not even close, this is wankery

I worked on a game where levels were defined in chunks that were groups of blocks of level segments in patterns, where using certain flags in the chunk definitions, blocks could be flipped or mirrored. Blocks in a chunk were 1byte signifiers in an order, so to flip the chunk, It was essentially exactly like the first problem posted. Rearranging the order of a string of bytes.
 

Deleted member 33887

User requested account closure
Banned
Nov 20, 2017
2,109
I feel like the reverse integer problem should be fairly easy given what you know. The count and say problem is some ridiculously specific problem. It doesn't look that challenging, but I also wouldn't want to bother writing a solution to it, because I can't imagine a practical use for it. Especially since they could have worded it so much more clearly by giving you one more example (it would be 100% clear what they were asking if they gave the read off for 1211).

That website looks like a worse version of Hacker Rank to me.
 
Last edited:

johan

Member
Oct 29, 2017
1,554
For what it's worth: I'm a professional Unity developer and I have never heard of Leetcode. Also in my day to day work I rarely encounter those kinds of wacky problems. Also I went to art school, lol

There's an argument to be made that the type of work I do is not programming but is scripting, but whatever

Don't worry about weird (but fun!) programming puzzles
 

Owl

Member
Oct 25, 2017
10,140
California
The only time these questions are important is that many software companies ask these kinds of questions in their interviews. Most of the Leetcode question aren't things you would normally encounter on a normal software engineer job.
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,191
That's only if they allow you to cast. If you can't, this would be the better way, although it doesn't account for overflow.

Java:
class Solution {
    public int reverse(int x) {      
           int reverse_number = 0;
           (while x > 0) {
                    reverse_number = reverse_number*10 + x%10;
                    num = num/10;
            }
          return reverse_number;
    }
}



Yeah, they are.
You're very right. I forgot about the limitations of these online code compilers. Your solution is nice.
 
Oct 25, 2017
20,229
I really really hate how much leetcode has fucked up the perception of programming.

Like this OP is showing and how they're getting frustrated. So much of these problems come with experience and extensive knowledge of concepts.
 
Oct 25, 2017
4,801
New York City
It's not likely you'd use code like this in the real world. But there are some applications where you will need to figure out how to manipulate data in such a way.

What I do to figure out problems like this is to do the problem myself with my own brain, thinking out each and every step I'm doing to get to the end result. Once I have that figured out, I translate it to code. This takes practice, but it's very important as that's basically what programming fundamentally is.

Very quick and dirty approach to the first problem - use a StringBuilder - which can do cool stuff with Strings. But, you'll have to cast the argument as a String and then with that, you can cast it back as Integer. You should do some checks on the argument for it to actually be an integer.

Java:
public static int reverse(int x) {
        StringBuilder builder = new StringBuilder(Integer.toString(x)).reverse();
        return Integer.parseInt(builder.toString());
    }
Unfortunately this wouldn't account for the negative number unless there's something I don't know about int parsing. But it's definitely pretty close to what is needed.
 

hasan114

Banned
Oct 30, 2017
130
I saw one of the developers at work had a "how to convert a string to substring injava" opened on stackoverflow and I laughed.

Ive been learning to code myself for the past 3 months and thought initially all devs know everythijg there is to know when in reality its browsing through stackoverflow half the time until maybe you have plenty of experience actually coding.
 
Oct 25, 2017
20,229
I saw one of the developers at work had a "how to convert a string to substring injava" opened on stackoverflow and I laughed.

Ive been learning to code myself for the past 3 months and thought initially all devs know everythijg there is to know when in reality its browsing through stackoverflow half the time until maybe you have plenty of experience actually coding.

There's so many internal libraries and 3rd party libraries that knowing it all form knowledge is impossible. It's no different then how people pulled books off shelves 20 years ago and it's insane when people shit on Google/SO

Knowing the terminology, concepts and end goal can get you very far
 

Doom_Bringer

Banned
Oct 31, 2017
3,181
For what it's worth: I'm a professional Unity developer and I have never heard of Leetcode. Also in my day to day work I rarely encounter those kinds of wacky problems. Also I went to art school, lol

There's an argument to be made that the type of work I do is not programming but is scripting, but whatever

Don't worry about weird (but fun!) programming puzzles

THIS!!! During my second year, our .NET C# professor asked us to write a genetic algorithm from scratch. He was doing his masters and giving his assignments to us. Only one or two exceptional guys managed to solve it.

I suggest building an app or a game of some kind. If you build something, you will understand more concepts and you can chain things together (oop, programming logic, design etc)
 

Modest Mauser

Member
Jan 12, 2018
210
I feel like saying you won't have to write code like this in a real position is missing the point, these exercises are more about developing general problem solving skills and implementing solutions rather than dealing with specific situations.
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,191
It's not likely you'd use code like this in the real world. But there are some applications where you will need to figure out how to manipulate data in such a way.

What I do to figure out problems like this is to do the problem myself with my own brain, thinking out each and every step I'm doing to get to the end result. Once I have that figured out, I translate it to code. This takes practice, but it's very important as that's basically what programming fundamentally is.


Unfortunately this wouldn't account for the negative number unless there's something I don't know about int parsing. But it's definitely pretty close to what is needed.
Hm, yeah. If I thought about it more, I would have a better solution.

First thought would be to do an initial check on the integer and flag if it's negative. If so, multiply the result by -1
 
Oct 25, 2017
20,229
I feel like saying you won't have to write code like this in a real position is missing the point, these exercises are more about developing general problem solving skills and implementing solutions rather than dealing with specific situations.

But these are now used as barriers of entry for developers and the new bar. It's bullshit
 

hasan114

Banned
Oct 30, 2017
130
There's so many internal libraries and 3rd party libraries that knowing it all form knowledge is impossible. It's no different then how people pulled books off shelves 20 years ago and it's insane when people shit on Google/SO

Knowing the terminology, concepts and end goal can get you very far
Oh far from shitting on SO or Google I was more surprised at hiw wrong I was thinking you can "master" programming. Its similar to thinking every mative speaker of English knows every word there is i. The dictorionary. It was more about how our concept of programming is naive when starting out.
 

the_korben

Member
Oct 27, 2017
81
While these problems are certainly neat and somewhat interesting (and it certainly doesn't hurt to at least think about what it is they want you to solve), let me just summarize what this kind of stuff really is: it's just interview-question-level bullshit, don't be intimidated. In "real life" nobody will ever need solutions to problems like this. The real problems are usually much more complex, higher level (programming-wise) or they've already been solved by some mathematicians or engineers in your company.

I've got a PhD in astrophysics and after leaving academia I have been working as a scientific programmer, inventing algorithms and new approaches to solving various complex problems related to machine learning, probabilistic analyses and all the rest of it. At the same time, I've also had to implement simple services, work with databases, implement REST-interfaces, XML-interfaces, all that boring stuff. And I had colleagues with all kind of levels of education and various backgrounds. My bosses never had any problems with people who simply knew how to get shit done. Not everybody has to be Alan Turing.

If you are having fun learning how to code, you're already there 99 percent of the way. About that remaining 1 %: I can tell you that in absolutely 100% of my time in many years of professional experience, I have never ever had to work out some kind of super-magic formula to solve a weird riddle that I didn't understand unless I had worked out the problem to begin with. And that makes all the difference.

Just keep learning, just keep coding, keep coming up with examples of problems you would like to solve. Don't worry about this bullshit.
 

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
But these are now used as barriers of entry for developers and the new bar. It's bullshit

They've always been used this way, this isn't a new thing, really.

Dxj80j_X0AA3gko.jpg:large
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,191
Honestly, the first question is very fair for practical, every day coding. You can never assume the data you will be working with is correctly formatted.
 

Ferrio

Member
Oct 25, 2017
18,072
These are classic intro programming type stuff. Programming is problem solving and being able to identify the problem and have a solution is the first step.

Saying this is useless is saying learning math is useless just because you don't use the high level stuff everyday of your life.
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,191
They're coming back though. Reddit is peppered with people talking about how they're now studying for jobs

There's other ways of validation of someone's knowledge of programming then throwing CS algorithms at them. It's 100% a form of classism.
I interviewed last week for a position (which I got) and the questions I was asked was to describe a certain design pattern and to find as many solutions possible for sorting an array - when that can be reduced to a single line of code.
 
Oct 25, 2017
20,229
I interviewed last week for a position (which I got) and the questions I was asked was to describe a certain design pattern and to find as many solutions possible for sorting an array - when that can be reduced to a single line of code.

I interviewed for a SDET/QA automation role and was asked to write a function taking in a 2d array and find all rectangles representated by 0s. I almost said "what the fuck" out loud on the call.

Another was a bit more common around string manipulation and I didn't finish it but I talked my way through a huge portion of it. Thankfully I somehow did enough to not bomb.

Leetcode forums are degenerated to pissing competition of one line code solving. Give me 5-10 lines of clearer logic any day
 

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
But these are now used as barriers of entry for developers and the new bar. It's bullshit

Presumably, the written test isn't the only thing that will disqualify you. That's typically why you have a face to face interview as well, and can explain your answers.

FWIW I typically do better in face to face interviews than written exams.
 

johan

Member
Oct 29, 2017
1,554
THIS!!! During my second year, our .NET C# professor asked us to write a genetic algorithm from scratch. He was doing his masters and giving his assignments to us. Only one or two exceptional guys managed to solve it.

I suggest building an app or a game of some kind. If you build something, you will understand more concepts and you can chain things together (oop, programming logic, design etc)

This is how I've learned about 99% of my skills. I just made something I wanted to make, ran into problems (of my own making, usually), and solved those problems (or not). I was never good at learning from theoretical situations from a book or something.
 
Oct 25, 2017
20,229
Presumably, the written test isn't the only thing that will disqualify you. That's typically why you have a face to face interview as well, and can explain your answers.

FWIW I typically do better in face to face interviews than written exams.

Most companies do phone screen, technical assessment and then onsite. Many have moved to things like hackerpad or karat for technical assessments
 

boontobias

Avenger
Apr 14, 2018
9,539
These interview questionaroonies are bs. Practice code with projects instead. I try to avoid coding challenges in real life.
 

Doom_Bringer

Banned
Oct 31, 2017
3,181
This is how I've learned about 99% of my skills. I just made something I wanted to make, ran into problems (of my own making, usually), and solved those problems (or not). I was never good at learning from theoretical situations from a book or something.

Yea this is truly the best way to become a top notch programmer. I hope you are listening OP
 

Deleted member 40797

User requested account closure
Banned
Mar 8, 2018
1,008
While I understand your frustration and have reservations about platforms like LeetCode, these seem like perfectly reasonable programming problems. The first question tests your knowledge of basic arithmetic (see SweetNicole's solution). The second is essentially a glorified string processing problem, unless there's a nifty solution to finding the nth term of Conway's sequence that I'm unaware of. I would recommend taking a data structures and algorithms class.
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,191
I interviewed for a SDET/QA automation role and was asked to write a function taking in a 2d array and find all rectangles representated by 0s. I almost said "what the fuck" out loud on the call.

Another was a bit more common around string manipulation and I didn't finish it but I talked my way through a huge portion of it. Thankfully I somehow did enough to not bomb.

Leetcode forums are degenerated to pissing competition of one line code solving. Give me 5-10 lines of clearer logic any day
Well, I am just saying, no one really ever implements their own iteration of a selection sort or merge sort when there's built in methods to do these operations. I agree - it's better to know how to do the longer way to make sure you understand what the built-in operation is doing.

Also, that 2D array question sounds nuts. I can't stand 2D arrays.
 
Oct 25, 2017
20,229
Well, I am just saying, no one really ever implements their own iteration of a selection sort or merge sort when there's built in methods to do these operations. I agree - it's better to know how to do the longer way to make sure you understand what the built-in operation is doing.

Also, that 2D array question sounds nuts. I can't stand 2D arrays.

yeah, I told other people about the 2d array and they were all speechless at that being asked to an SDET/Automation person.
 

Rayman not Ray

Self-requested ban
Banned
Feb 27, 2018
1,486
I honestly feel pretty conflicted. I agree with the critique that these kinds of coding interviews are flawed. But is it classism? Not so sure. You can buy that cracking the coding interview book and study for the interview. It may be annoying but I'm not sure it's gatekeeping.

But to me the much more interesting coding interview questions are design based one. Where it's an open ended question where the goal is to see how an engineer tries to take a real world problem and map it onto a design architecture.

And when you're interviewing an entry level person, you can't really ask questions like that, as they just don't have the experience. I feel like the algorithms questions could be a useful stand-in if and only if the interviewer doesn't care about the solution, and is focused on process. But most engineers don't actually know how to interview people, and so the system of bad interviewing is perpetuated.

Sigh. I don't know.
 

mnemonicj

Member
Oct 27, 2017
2,649
Honduras
If you're doing the algorithm section, then this is basically what all Computer Science majors are about.
Problem solving is what programming really is about.

But that doesn't mean you can't learn, most of the people that solve those problems have had previous training with formal mathematics.
Keep at it, try taking an algorithms course, and you'll get there.
 

Spinluck

▲ Legend ▲
Avenger
Oct 26, 2017
28,480
Chicago
Take the advice above and learn the logic first. Focus more on basic coding logic skills vs focusing on a specific language.

Learn things like data types, loops, conditionals, arrays etc...

I am starting at the very root level for this. Would ASM be viable to help understand the syntax and things like that?
 

Arebours

Member
Oct 27, 2017
2,656
It's strange that people are so against these exercises. Will you run into them on a real job? No but just grinding your problem solving skills is valuable, and I've actually written "real" code that isn't so far away from these problems. You'll learn how to choose data structures and algorithms. That's a big part of what makes a good programmer. Speaking of good programmers, just take it slowly op. Six months is nothing, but you'll get there if you keep at it.
 
OP
OP
Maple

Maple

Member
Oct 27, 2017
11,732
It's strange that people are so against these exercises. Will you run into them on a real job? No but just grinding your problem solving skills is valuable, and I've actually written "real" code that isn't so far away from these problems. You'll learn how to choose data structures and algorithms. That's a big part of what makes a good programmer. Speaking of good programmers, just take it slowly op. Six months is nothing, but you'll get there if you keep at it.

Do I just need to go and spend some time studying algorithms and data structures before I come back to these types of problems? Are those the main subjects on which problems like these are based?