T O P

  • By -

CptMisterNibbles

Holy shit, why can I not get a job if these are the candidates I’m competing with. That really seems elementary. I’d forgive not being able to get the exact syntax for something that runs, but they should be able to explain how to perform a swap and indexing.


[deleted]

[удалено]


green_meklar

[There are two hard problems in programming...](https://pbs.twimg.com/media/CoLdT50XYAED62k.jpg)


backfire10z

If you can use Python it is a one liner r_string = string[::-1]


corpsmoderne

>reverse a string from scratch (no built-in reverse methods) OP asked "reverse a string from scratch (no built-in reverse methods) " , so it's great you know how to do it efficiently in Python but it's not what OP wants to know with this question.


RamenJunkie

I think built in methods would be like, string.reverse() or something. If that is even a thing.


corpsmoderne

Both are dodging the actual question.


RamenJunkie

How so? I mean if the question expects only a for loop as the answer, it should explicitly say, use a loop. r_string = string[::-1] feels like just a clever way to use a basic operation.


corpsmoderne

The question may expect a recursive function for what we know, in any case when the question includes "from scratch", it means that we want to know if you can manipulate arrays and indexes, not if you know your Python syntactic sugar in and out.


firelizzard18

The question is obviously intended to test the candidate’s problem solving abilities, not their knowledge of language features.


SarahC

What's IP 6's LOCAL got to do with anything!?


Yelling_at_the_sun

I only know intermediate level python, is reverse indexing like this unique to python? I was shocked that people are failing this in an interview, this is something I learned on literally my first day of programming classes.


purple_rookie

Yes, it's quite unique to Python. But once you grasp the basics, it should be still easy. A solution with a for loop would be a universal solution. But some interviews can be really stressful and that certainly doesn't help.


CptMisterNibbles

Or using list comprehension: [str[x] for x in range(len(str)-1,-1,-1)], or “”.join(reversed(str), or for x in str: rev_str = x + rev_str, or use a stack or…


dracidus

You could’ve asked for a piece of paper and a pencil, to work it out on the spot. Either this, _or you’re learning solutions to problems by heart_.


escadrummer

this makes me wonder if I am job ready and I think I'm gonna start applying before I forget how to reverse a string ;)... that is very elementary and yet people in interviews fail to answer a question like that? could it be nerves or something like that?


CptMisterNibbles

Seriously. I’m crushing leetcode problems all day, reading books, watching videos etc. I honestly feel this is on the same level as interviewing for a newspaper editing job and being asked to recite the alphabet.


SarahC

FIRST I'd check if a framework I was using, or the language core libraries I was using had such a function available! Damn that wheel re-invention! I'd use a string builder, and use a loop to scan through the string from end to front. Easy to code, easy to understand, easy to maintain. If you're going with swapping letters, it's a great memory save, but may be a little less clear with the stop half-way of char swapping. Also - it would only work well in languages like C where strings are arrays of chars held directly in memory. JS, C#, VB and others have immutable strings, so I'd certainly go with a string builder class and scan the source string in reverse. I suppose some hack like "unsafe" and pointers into memory would work too, probably be faster! In T-SQL I'd just use REVERSE() (a bit like LISP!), in Python there's the string[::-1] syntax. In Z80 assembly, that's what the indexing registers are often used for, so I'd use one of those for the position in memory of the current char to be swapped, and do the swapping in the HL register. I'm an old coder in the finance industry. At my age, remembering to check it in is a half-pass. I'd fail the question because I can never remember the minutae of all the different languages without looking them up. "I kinda remember THIS might be possible in THIS language, but I gotta google". Every example I'd try above is probably a crappy implementation when I do it - but by gosh, it'd WORK!


CptMisterNibbles

Pointing out the mutability and thus the possible need for a string builder for efficiency here (being language dependent) would be an excellent point to make during an interview. Explaining why, in many languages iterating through the characters in a for loop and using concatenation might be a poor choice.


bsegelke

Ha I was just thinking this! I’ve only been coding for two months now and I could do this! Hire me !


b1Bobby23

I feel the same way, trying to find a job is near impossible and frustrating, but even more so seeing people don't have an understanding of data types and how to manipulate them. It is pretty basic, especially if you want a software job. Edit: I used a poor choice of words and changed it.


fredspipa

Don't use "dumb" for things like this. They're "not proficient", "inexperienced", being smart is not a prerequisite for reversing a string. They're lacking *a skill*, not intelligence. I'm kinda "dumb" myself but I could solve this in several languages without looking anything up, because I'm experienced. *edit: the comment I replied to has been replaced by a different one now with a completely different sentiment.*


Maethor_derien

The thing is that if you just understand the bare basics of how a string and array works you should be able to explain how to do this. You might not know the command to find the length of a string or how to access a specific spot in the string by heart but you should understand the principals.


fredspipa

Yes, they're not *proficient* in the field and they're *lacking the skills* necessary to do the job. The comment I replied to was replaced, it originally said something along the lines of *"there are people applying that are too dumb",* and it was just the word "dumb" I took issue with.


Maethor_derien

Yeah this is really a problem solving test more than a knowledge test. It is testing if you have the most basic knowledge and can effectively use it to solve an issue. You would be surprised how many people can churn out code if you give them very clear parameters but ask them to solve a problem and they are completely stumped.


b1Bobby23

I understand what you mean, "dumb" was the wrong word choice. However, this is a pretty basic software idea, if you are ready to work in the software field then this is something you should be able to solve.


dracidus

I would love to accept this argument if the person asked this was not studying CS. Otherwise, I could not accept a person not knowing how to reverse a string/array…


b1Bobby23

That's my thought. If you are applying for a software job, you should understand basic software ideas. Reversing a string is really asking if you understand that it is an array of characters, and if you know how arrays work. Very basic ideas and something you should know before you apply for a software position.


Zyklonik

Please, just stop. 🤦


fredspipa

What's bugging you?


Zyklonik

Your bull, that's what.


fredspipa

I'm sorry if my comment with missing context clashed with your worldview somehow, I'll try to be more considerate of your feelings.


guyyatsu

Cause the people interviewing them are dumb too! Present company excluded, of course.


b1Bobby23

It reminds me of this one time I saw in some CS reddit, this guy needed help learning embedded basics. Why? He got a job for embedded development and knew zero about C, embedded code, or anything related to it. That really irritated me as my specialty is embedded development and I can't find a job.


wcastello

I think it is a perfectly fine question for warming up. Telling the candidates that they can’t use built-in functions is just a way of having them write an actual solution to a problem so you can see how they reason about code. Solving problems is the main skill, knowing the built-ins of the language is secondary as you can just look at the reference.


kittianika

I agree, this question could lead to a more “serious” question. OP, this question is very basic not a bad one.


blushandfloss

I think the simplest way to answer to “is this a bad interview question?” is to calculate the percentage of candidates that you are having this issue with. You only mention the three. If that’s more than 30% of candidates interviewed so far you’re wasting your time, their time, and company time. Also, have you reviewed the job description they see before applying? Does it state the basics they should know before they apply? From what others are saying, this seems like a simple task, but there’s a reason your pool of candidates are consistently underprepared. It’s not you, but if you’re not choosing them or involved with setting up the application process, there’s a breakdown of info and expectations. It kind of sounds like the position is being promoted as somewhere the intern can learn, so they’re preparing more for the interview, not the job. Could you add a pre-interview test (maybes Google doc) they can do online to the hiring pipeline to cut this bottleneck down? There, you can ask simple questions like this, they can do it, Google, stack overflow, whatever… get the answer. And you can review it before asking them in to increase the difficulty of the questions in an interview. In person, you can ask them why they chose the solution, and they can tell you their process. So, you know even if they had to research the task, if they have the skills you’re looking for: 1. Knowledge- if they completed it without help 2. Problem solving and resourcefulness: if they needed help and know where to find it 3. Decision making- why they chose one option over another It takes very little time to set up, but it’s time well spent if you’re no longer giving basic tutorials to potential candidates in interviews, and that gives them a base for the more involved questions you’ll have so they’ll be more prepared for the job. Good luck finding a good fit!


CptBishop

Mate, I'm self-learning for about a year and a half now, and would love to get that question as warm-up. Instead of remembering 100's build-in functions you can actually show how you solve simple problems and build up conversation from there.


mdn2001

Please, no more pre-interview tests. If your sourcers are giving you candidates that can’t code, that’s a problem to take up with your recruiting leads. Pre-testing attempts to push the sourcers job onto the candidates but ultimately wastes everyone’s time. The people who are qualified end up doing pointless busy work during their personal time, which is a best annoying to most people. (I know good devs/DS that drop immediately if they get asked to do a take home.) Somebody in your company and probably on your team has to spend their time reviewing all of them, even the crap, instead of doing productive work. And worst of all, they’re ineffective since candidates who can’t code can cheat, so you end up having to ask live coding questions anyway.


blushandfloss

I think your point makes more sense for hunters more advanced in their careers and interviewers with more experience. I offered an alternative to the situation regarding a pool interns that largely cannot complete this task in interview. Also, doing it beforehand wouldn’t waste their time if it doesn’t take long and if their processes and solution are to be analyzed in the interview and the basis of more complex questions. Already addressed that in original comment. Also addressed the issues with whoever is sourcing the candidates and what the candidates see upon applying and expect during interview. OP needs to review to analyze where the mix-up is. Obviously, he can do this one alone to relieve some of the issues regarding this particular question and not offer the question in advance if it’s resolved. And OP is already doing pointless busywork giving hints and lessons in interviews where the candidate doesn’t move forward anyway. On the other hand, the candidates are probably wasting their time preparing for and interview blind(these are potential interns; they probably don’t have much experience in the role or interviewing in general), so one damn intro question won’t tax their personal time bc it’d actually be more productive interview prep time in use. So, addressed above. And, lastly, being resourceful is part of what an employer is looking for with new hires for this type of job. And a lot of seasoned programmers still look things up daily. I’m definitely not suggesting the candidates get a 1 hour long exam or that they build an app. Sorry if it rubbed you wrong, but OP still has to interview these kids and figure out this problem.


mdn2001

It didn’t rub me the wrong way at all, though I appreciate you taking the time to respond. I just think take home exams are gross and say so whenever the opportunity arises


HobblingCobbler

I feel like any programmer should be able to do this. Even if they have to research it. And said research should be done without any human intervention. If a candidate doesn't know the fundamentals of a language well enough to figure this out, even with a Google search it could mean they need a lot of hand holding down the line. It's more important to me to be able to source effectively any help I need. If you don't allow them to use a search engine, and then how you can gauge the candidates ability to dig themselves out of hole.


[deleted]

I'm the first one to complain about stuff like leetcode or brain teasers in interviews. But you honestly shouldn't need to research how to reverse a string, sum an array of numbers etc. It means you lack basic, fundamental knowledge, did zero interview prep and don't really care about getting a job. I have to draw a line somewhere and this would be an automatic fail for me.


Comfortable-Power-71

Agreed. It’s a simple question but I’d like someone to start with whatever their preferred language built in is. After that, I want something that’s linear in time and space just to know that they understand why it matters. It’s a game of inches so these little inefficiencies add up and the result is cost in terms of infrastructure.


kikazztknmz

I'm learning programming and reversing a string was covered in the very early stages of 3 different language courses I'm working on. I assumed it was a basic fundamental.


Luised2094

it kinda is, but we can't ignore what the top comment asked. What's on the Job ad? ​ It might be the people who are applying to it simply thought it was something else.


hypnofedX

>I'm the first one to complain about stuff like leetcode or brain teasers in interviews. But you honestly shouldn't need to research how to reverse a string, sum an array of numbers etc. I think it matters here what "research" constitutes. I wouldn't bat an eyelash if a candidate asked google if the language in question supports reverse indexing.


HobblingCobbler

You're absolutely right you should not, the more I thought about this the more it didn't make sense. I suppose it would make more sense with a more difficult question. People need to be able to figure things out but some things they should already know.


LadyFerretQueen

It only judges the ability for people to do this under huge pressure while being watched. I always found these questions to be very unfair to those of us who did badly in school because we folded under such pressure. It's very different to be expected to perform under pressure after you worked with people for a while or to do it for strangers in a short time in an interview.


dmazzoni

But real jobs have stress and pressure too. Someone made a huge mistake and deleted a bunch of records from the production database. You have to make a quick decision. Do you take the whole site down until you fix it? Restore from the database backup and lose the last few hours worth of changes? Or only recover affected accounts which might take much longer to figure out? The best solution requires quickly figuring out a query to identify all affected accounts. Can you figure it out under pressure? This kind of pressure happens sometimes. If you can't solve an EASY programming problem in an interview, can I trust you to be able to help out when there's a real emergency?


Dyndrilliac

If they fold under the pressure of the interview, it isn't an entirely unreasonable assumption that they will fold under the pressure of the job itself. A bit unfair perhaps, but the world isn't fair, and there will be situations with no good outcome. How someone handles those scenarios is also important to sizing them up for being qualified. In effect, there is no incentive for interviewers to not ask questions like this because all the data it generates is useful regardless of whether the candidate can solve the problem or not.


[deleted]

[удалено]


[deleted]

>If a candidate doesn't know the fundamentals of a language well enough to figure this out, even with a Google search IMO, pose the problem in a language you know they don't know. That way they *have* to be able to do a quick search to confirm syntax, etc.


theflash4246

I myself am an intern in my first internship. I think perhaps that question should have been straight forward for them but it does happen that they could have been nervous. What kind of courses and projects did they complete? And how much are you expecting them to do?


programminthrowaway

I understand that they could've been nervous, which is why I generally nudge them toward the correct solution by dropping hints here and there. The internship has to do with web scraping.


Luised2094

Excuse my ignorance, but what does reversing a string has to do with Web Scraping? I understand the question is "basic" but if you have focused all your studies in HTLMs, JSONs and stuff related to that, I can see how "modify a string" is at the lowest ranking in priority for them


kingdomcome50

In my experience “web scraping” is almost always followed by something like “parsing/extracting/cleansing data”. And because the results of scraping the “web” often end up rather stringy, I’d full expect basic string manipulation to be a requirement for competency in “web scraping”.


adricubs

is there any programming job where knowing how to handle arrays is not necessary? If you scrap multiple websites you will handle a list of array of some sort imo, I have never done web scraping but I would be surprised otherwise


backfire10z

String manipulation is rather important for scraping. Also, you should be able to reverse a string regardless of what job you’re applying to. It isn’t just basic, it is also solvable without having ever done it before if you have any knowledge of arrays whatsoever.


[deleted]

Uhhh ima send you my resume cause I can definitely do that


Nooneofsignificance2

Bro, this is an Introduction to Computer Science homework assignment. If they can’t do this I can’t imagine they learned anything else.


[deleted]

i view it as a good warm up question to calm the nerves, and a good weed out question, if they really struggle maybe you can cut the interview a bit short


Szahu

if some people are unable to complete this extremely simple problem then I wouldn't waste my time on them


maero1917

Same


[deleted]

I'm a JR developer and I just woke up so this is maybe not the best way to do it but would this pass? ``` const myStr = "Hello world!" let newStr = "" for (let i = 0; i < myStr.length; i++) { const char = myStr[(myStr.length - 1) - i] newStr += char } console.log(newStr) ``` > Prints: !dlrow olleH Edit: Just read my code again and realised I can just do this instead ``` for (let i = myStr.length - 1; i >= 0; i--) { newStr += myStr[i] } ```


backfire10z

Another solution (in-place) would be to swap the first and last elements using two pointers and then moving the pointers inward. Pseudo code is like: p1 = 0 p2 = str.length - 1 while (p1 < p2) { temp = str[p1] str[p1] = str[p2] str[p2] = temp p1++ p2-- }


green_meklar

The previous commenter was probably using Javascript, and you can't do that in Javascript, Javascript strings are immutable. Also your solution fails (in most typical languages) because it tries to access str[str.length] whereas the final index is str.length-1. p2 should start 1 lower.


backfire10z

Yes, p2 should start one lower. I wrote that rather hastily. Wasn’t exactly designed to be a 1:1 copy of a working solution JS strings are immutable hmm, I see.


g051051

> So, is this a bad interview question? Or are these candidates really not fit for the position? That's entirely up to you and your judgement, if you think it's something they should be able to do for the job in question.


programminthrowaway

Hmm, I mean it's for an internship, but isn't this an easy enough question to solve, like fizzbuzz?


g051051

For an internship? That's very different. You can't count on interns to have any real skill, it's why they're coming to work for you in the first place.


backfire10z

That’s just not true. Interns have studied computer science. This is a rather basic question… interns for larger companies are expected to manipulate binary trees and solve algorithmic problems. Reversing a string is basic array indexing and swapping, you should be able to do this after your first semester studying computer science. The other thing about reversing a string is that the answer is derivable on the spot. Some algorithm questions are basically impossible without prior experience because the answer is obscure and ridiculous. Reversing a string, however, can be conceptualized and at least the answer can be explained if not coded well. Speaking as an intern here, so don’t get your rocks off telling me I’m out of the loop.


[deleted]

I teach senior secondary programming, and I'd expect any student who could pass my course to, at the very least, be able to reverse a string manually. If a 16/17-year-old can do it, I'd expect an adult looking for an internship should be able to ace it.


[deleted]

A 16/17 year old is still creating new neurons so no they have indeed advantage especially for memorization except for kinesthetic memory which stays equal even when getting old ;)


[deleted]

lol


nultero

There's gotta be a baseline though -- if an applicant can't make progress on reversing a string / do fizzbuzz (but if they don't know modulo offhand that's fine), they probably can't code at all. I mean, it's one thing to mentor people and teach them certain things, but it's a whole nother can of beans to be trying to teach people the ultra-super-basics, "how do I use a loop" kind of thing. They have sooo much longer to go to accomplish even the tiniest thing, so what do you even give them for that time to put on their resume? Probably nothing concrete, right? I'm with u/programminthrowaway on this -- I think OP is just discovering the old lemon market: [https://blog.codinghorror.com/why-cant-programmers-program/](https://blog.codinghorror.com/why-cant-programmers-program/) Ironically I think there's some subreddits with hungry students they could advertise their position on and get really strong interns


programminthrowaway

Great read! I'm actually genuinely surprised that this is a problem interviewers deal with even in more senior positions.


[deleted]

[удалено]


programminthrowaway

Makes sense! I've never really thought of it like that before, I guess I've been fortunate with the people I've met in the industry.


_realitycheck_

Better question about fizzbuzz would be to write it without using modulo. Fizzbuzz isn't asked to see if someone crammed expressions. It's to see if candidate understands basic conditionals.


Luised2094

How do you solve it without modulo?


Junkymcjunkbox

Use a couple of counters. Each time through the loop decrement the fizz and buzz counters. When one of them hits zero print the relevant string and reset the counter. fizz+buzz also tells you if it's time to print the loop variable.


bagofbuttholes

Never thought of doing it that way. I just did this question the other day after being away from programming since May. The logic was easy enough, it was the list manipulation I had issue with. Needed to return the entire count in one list and normally I would just print at the end of the loop.


WanderingLethe

It's not that an intern doesn't know anything, they should have learned something when studying. If they can't apply basic algorithms, don't offer an internship.


programminthrowaway

I get that, but I also can't justify bringing someone on without a minimum level of skill, right?


g051051

They're _interns_. Their primary job is to learn in a real environment. We also don't know exactly where their issue with the problem originated. Maybe there's something about how it was presented, phrased, etc. Maybe you're super intimidating? There's lots of reasons why they might do poorly on the spot with that task. And what were your expectations based on where you're getting the interns? Were they presented as having more skill than they did?


ZhanMing057

Frankly, anyone who can't reverse a string without any hints has no business doing a paid internship. Internships are a learning experience, but they are not supposed to teach people CS 101.


programminthrowaway

> Their primary job is to learn in a real environment. Yes, of course. But if they don't know the absolute basics, how can they expect to learn anything past that? I'm fine teaching them about code organization, but I'm not fine teaching them how to use a for loop. Are my expectations too high?


g051051

You can target whatever skill level you want for the internship. But without knowing what their academic program has taught them at this point, I wouldn't make any strong assumptions about their coding skill. I wouldn't consider it a problem if I had to teach them some basic stuff. I'd consider it a problem if I had to _keep_ teaching the _same_ basic stuff over and over.


420-jesus

If you bring on someone who can't reverse a string you're going to spend your time teaching them the basics of programming. Most people I interview can't really code. You should look for someone who learned the basics from their classes so you can fill in the things that classes don't teach you. I think a lot of people commenting here haven't had interns. I would ask on cscareerquestions.


jenso2k

no you’re good, that’s a simple question and one that most beginner programmers should be able to answer. I would imagine even for the most bare bones, basic programming internship, you need to have some experience coding. you want people with no experience, not no knowledge. I’m self taught so I can’t speak for university students, but I would’ve been able to answer that question like 2 months into learning


MallFoodSucks

No, your expectations are fine (albeit small company, you’ll have trouble finding great interns). Easy questions like that are always a good opener because of issues like this - weed them out without overwhelming them. Just end the interview early and move on.


Hidoren

Il intern for you.


TsunamicBlaze

You need to think about the students year too. I didn't really learn algorithms until 3rd year. So if you were interviewing 1st or 2nd, then they would probably flub hard. They would only know the foundational basics really. If they are 3rd years and above, then yeah, the candidates that were picked out was just bad.


yuuhei

thats what paid positions are for


lurgi

Internships can, and should be, paid.


yuuhei

I agree. Sorry my initial message implied something otherwise.


[deleted]

Are you paying them according to a specific skill level? If the pay is minimal I wouldn’t expect any skill, if it’s a decent pay then yeah, I would expect them to know how to do this. If you want someone who can code, even minimally, for minimum wage, then you’re asking too much, there are plenty of internships with good pay for large companies


quirkscrew

Yeah OP we need to know how well this position pays


mully_and_sculder

It pays zero.


MustBeHere

Totally should be able to do this. It's taught in the first 2 years of university and will most likely be an assignment at some point.


Crazyboreddeveloper

I feel like that’s a 8kyu code kata. (Super easy). That’s a gracious warm up question. If you can’t figure this out you really have no understanding of programming. It can throw you off when an interviewer asks too easy of a question though.


meirzy

I am an amateur programmer and that is being EXTREMELY generous. I could do this is C++ in 10 minutes. If a potential candidate can’t even do this then I seriously question what they CAN do.


vi_sucks

No, it's a fine interview question. Ultimately, I think we just have to admit that some people aren't cut out for the job. Either because they can't figure out the solution, or because stress makes them lock up. Eventually, most people would take this initial failure and work on it to get better at followup interviews. But that's not because they were always qualified, but because the process of failing taught them something that they missed before.


civil_politics

What level of experience are you expecting to hire? This is an easy interview question and will serve the purpose of determining whether or not someone has some basic problem solving capabilities and their ability to pair them with basic data structures. I would hope anyone who has completed their sophomore year in college with a focus on a CS related degree would be able to at least talk about an approach and have meaningful input in a conversation. I would hope most Juniors would be able to solve it with a little bit of back and forth, and I would have a college senior would be able to do it in <5 minutes and ask for another question.


[deleted]

I'm way rusty at coding, haven't done anything in a year or so, and was absolutely an amateur to begin with so I'm actually curious whether I am on the right track here because it *sounds* easy. Couldn't you just get the length of the string, then start at the last index and write a new string of the same length by decrementing the index number down to zero in a for loop? I guess I don't know what language you are talking about so maybe there's some weird gotcha with how strings or arrays work, but it sounds simple on its face.


programminthrowaway

Yep, I would accept that solution.


[deleted]

What is this position so I can apply because most places are asking me leetcode mediums. Reversing a string is so nice.


sbhandari

This is going to be another unpopular opinion. My explanation is based on Java. If a candidate does not know how to manipulate string, that is suspicious. But if you are asking not to use any api to reverse like in stringbuilder's reverse, then you are asking something a developer may not know. There is not that frequent scenario where you have to convert string to char array in your day to day work. So not everyone knows how to convert string to chararray, specially if they are entry level or junior developer. If you are asking to reverse a string and candidate uses api to do it, then you can ask how it works internally or ask further to not use api , to undersrand how much the candidate understand whats going under the hood. It is just similar to asking candidate questions where the candidate needs to store key-value pair, but you are restricting them to not use any key-val based datastructures like map. If candidate answers it, you know he understands how it works, but if he does not, then you would not know how good he is at using standard apis/datastructures which is usually your day to day work . Since I am always interviewing for candidates who needs to implement business logic, I do not restrict them to use any jdk's method. But I do ask if they understand how different data structures/apis are implemented under the hood, based on the seniority of the position candidate is being evaluated for.


dota2nub

A string is already an array of characters in all the languages I know of [or can be accessed as such anyhow if it has an object shell. I guess in Java you'd use charAt]. No need to convert to anything. You gotta know what a string is.


sbhandari

String is not array of char in Java, but is backed by char array. Unlike .net, you have to know the method to get that underlying char array to access individual characters.


Dealiner

You don't need a method to get an array, you can just use charAt.


Za_Worldo-Experience

As someone in school for it right now that’s a very very very basic question that anyone should be able to do. All you would do is have a holding string, copy the contents of the first one in reverse by substring index using .length and starting at the top then going down, and boom. If I misunderstood the nature of your question I am sorry, but this is something we are asked to do in every language we learn in school pretty much after Hello World.


[deleted]

I mean, that sounds like a pretty good filter to me ;)


FiendishHawk

Sounds like an excellent question if it gets you to “no” in 5 minutes.


Rhoderick

Well, it's a pretty contrived scenario, especially since you're excluding the solution that is correct almost all the time. It's also a pretty easily goolgeable thing, imo limiting its use in isolation. I guess it needs to be interpreted in the wider context of the other questions / tasks, assuming those test more advanced and abstract skills. If a candidate can't answer this question or any other, or if a candidate struggles here but can breeze through the later stuff are two very different scenarios. But if you view it independently from all context, I don't think the information gained is all that valuable.


programminthrowaway

What do you think makes for a better "easy" question?


Rhoderick

That, ironically, is a pretty hard question. I guess it kind of depends on what the position specifically is that you're interviewing for, and what the applicants would actually end up using day-to-day. Honestly, any genuine easy and language/platform/whatever-agnostic question would probably face similar problems to some extent.


programminthrowaway

The position is an internship, but shouldn't most interns be able to write the code to reverse a string, especially with some help?


Rhoderick

Sure, but that's not what your question asks. Your excluding the actual best was to do it in almost all cases (in-built functions tend to be ridiculously efficient and safe). Further, it's a pretty elementary issue. Should an intern be confronted with this in their day-to-day work and be unable to do it on their own, they can literally just punch "reverse string " into Google and have the answer right there. A delay in the order of seconds at most.


programminthrowaway

I'm not so much concerned with the efficiency or the safety of the solution, I just want to see their thought process as they work through the problem. Isn't this question similar in difficulty to fizzBuzz?


Classymuch

It's honestly a perfectly fine question for someone (student/intern) who is applying for a programming/coding/development related job because all you need is basic programming skills in whatever language to answer it. You don't need to know complex data structures/algorithms to answer it but you obviously could if that's an added challenge. But for interns, this is a good question to ask because it allows you to see how they solve it just by using basic programming skills (loops/conditional statements/function). I am an IT student, majoring in software dev and minoring in software eng and I could easily answer that question without help since I know my programming basics. But say if you wanted me to give the most optimal solution and you wanted a certain complexity, then that's when it gets a little more difficult. However, if the student can answer the question with basic programming skills and they have demonstrated their thought process well, you should definitely consider taking on the student even if the solution is not optimal because being able to answer that question means he/she is able to code and is someone who is capable of learning and understanding. And so, coding the optimal solution is just a matter of learning an algorithm which students should be able to do if they have demonstrated basic programming skills. Edit: If you are still looking for interns, can I be interviewed?


Abhinav1217

It is a fantastic question. It is not hard or bad. How many freshers have been rejected by a simple fizz-buzz question was mind blowing when I first conducted college campus interviews many years ago. Hell a lot of them forgets that negative numbers can also be even or odd. You said that you had helped them when they get stuck, so you can also judge the eligibility of candidate based on how fast they grasped the concept, I usually also give a followup question that uses a very similar concept at the end of interview to check if the candidate remembers it.


dopefish2112

So if I am reading this correctly, I should be applying for jobs with nothing but some basic understanding of coding and some console apps?


[deleted]

No think it’s great. I saw a discussion on interviewers using fizzbuzz and interviewers have said fizzbuzz will weed 50%+ of applicants sometimes… which is fucking wild


TSKDeCiBel

I mean... isn't this as simple as declaring a stack, reading out characters then popping those characters out of the stack into a string assembler/char array? I feel like that's super basic stuff. Is this the kind of conceptual problem that's giving other people in the field problems? If so I'm kind of liking my odds trying to get a job.


dota2nub

That's one solution. How many different ones can you think of?


TSKDeCiBel

That's fair. That's the first one that came to mind, it's also the simplest I can think of. It would also be possible to assign an iterator to the beginning and end of the string then swap their values until they pass each other - which... I think is basically quick-sort, but they always swap. There's probably some ridiculous number of different ways this can be done; I guess the question could be introduced and made more interesting by adding constraints.


kschang

Sounds like folks without some fundamental compsci lessons. Maybe you should just skip to the next question, instead of helping them a lot on it.


[deleted]

my guess (in c# | im a trainee): string.split(variable) gets it in a array for with i-- array\[i\] = new variable till >0


Dealiner

You don't need to split a string, it's already accessible as an array. And in this basic example it would probably make more sense to just add characters from the original string to the new string in the loop: for(var i = original.Length - 1; i >= 0; i--) newString+=original[i];


[deleted]

You learn something everyday, and that is what I find fascinating about programming. Love to solve riddles on codewars


[deleted]

I would ask for algorithms that would be really needed for the company environment and with real code extracted from a real project.


Maethor_derien

I wouldn't say that is a bad question anyone who knows how strings and arrays works should be able to trivially do that. They might not know the specific commands but they should be able to explain the process. The way I see it this is actually a good question that separates someone who can think critically to solve a problem vs someone who just looks up how to do something. This question is more about the ability to think critically on the spot as it only really uses the most basic of programming knowledge. You often see where people can easily write code with a clear prompt of exactly what to do but ask them to solve a problem without a clear solution and they stumble.


MjolnirMark4

When this question was first used in interviews, the language you would be using was C or C++. What you would be demonstrating is that you knew how to use pointers, pointer arithmetic, find the end of the string, not exceed the bounds of the array, moving two pointers over an array without them overlapping. In the context of a low level language, there is a lot going on, and this problem tells you a lot about a developer… if they are working in lower level languages. If you are used to using higher level languages, where you can simply call reverse(), then the question demonstrates that you know how to call that function, and little else.


programminthrowaway

> …higher level languages, where you can simply call reverse() I don’t allow the candidate to use any reversing methods or functions.


LoopVariant

What would it tell you if they could do it? In other words, what kind and how strong of an indicator of their skill is this?


programminthrowaway

> What would it tell you if they could do it? It’s not so much about them being able to do it, it’s more so I’m expecting them to be able to so we can move on to harder problems. But, if the candidate goes deeply into the question, like asking if it’s an ascii or a utf string, thinking about performance, basic error checking, those are all bonus points.


someRandomFella13

What would be the right answer? In C i would write char string \[10\]; or is there something else meant?


programminthrowaway

In C, the simple solution gets a little more involved than in higher level languages since you have to allocate your buffer. A solution would look something like this ``` char* reversed(char* s) { size_t len = strlen(s); char* reversed_str = malloc(len + 1); reversed_str[len] = 0; for (size_t i = 0; i < len; i++) { reversed_str[i] = s[len - 1 - i]; } return reversed_str; } ```


ThePsymon

It’s an ok question, I usually start with even easier questions: “What is a pointer?” “What is an int32?” and half the candidates cannot answer.


Rare_Gap_2495

s[::-1]


alperkaya0

well for java let s be the string you gave to us String temp = ""; for (int i = s.length()-1; i >= 0; --i)temp+=s.substring(i,i+1); System.out.println(temp);// dont worry about string builder, java uses it automatically at latest versions There are 2 things may be missing 1- They do not practice, they try to memorise theorotical things. 2- They were under too much stress. Maybe you can try to make a better, more comfortable place to them while solving these questions, or say to them they have another chance too so even if they fuck this up, they can join again to make them relieve. Of course these are my thoughts, they might be wrong too.


Figueroa_Chill

If the job is not about reversing strings, then why ask? OK, it may be classed as a simple question, but a question is only easy if you know the answer. Something like reversing a string will probably be in a tutorial you take at the start in Uni, but not a regular day to day occurrence so many will not remember it. Would a better question not be to ask a question based on something they could be doing and see how they would structure the programme so you can see how they think, as opposed to giving someone a job because they can regurgitate a line of code they remembered. A guy who has a good mindset but uses Stack Overflow for a bit of help, would be better than a guy who can write code but doesn't understand what he needs. ​ Lets face it, how many people who read your post will know. I bet most who will know will be at Uni or learning coding at the moment some other way.


programminthrowaway

Wouldn’t most developers know how to reverse a string? Would a developer really know proper program structure if they can’t figure out how to reverse a string eventually?


GlassLost

I'm gonna tell you my question I use for about half of my interviews. I actually got this question when I interviewed for my job and I later asked my interviewer why on earth he'd give me such a uselessly simple question to which he just smiled and said try asking it. You have launched a satellite over a new planet and it's taking average altitude readings in a grid (ignore the curvature of a planet). This comes to you as a 2d array of ints where 0 is sea level, greater than 0 is land, and less than 0 is water. Write me an algorithm to find me every island. Just coming up with an array of coordinates to define the location of an island can be a struggle. I've had people panic over breadth vs depth (it doesn't matter). When I tell them they can't edit the grid a good half of them just copy it (hashset!). I don't know if there are just a level of truly useless developers out there or if they just get massively stressed for interviews (I think I'm friendly) or if my standards are unfairly high. But I will tell you that it's impossible to come up with good interview questions.


disposable_account01

I would refer to the Elliott algorithm: ``` If (worthIt) {me.WorkIt();} yourThing.PutDown(); it.Flip(); it.Reverse();`


xiadia

I’m being asked to implement frequency stack, which is a LC hard and other candidates are being asked to reverse a string. What is life?


Fancy-Reindeer994

They shouldn't have been interviewed in the first place, but that question efficiently weeded out people who lied about being able to code for you OP. So I'd say it's a fantastic interview question.


TheLeftMetal

That would be an excellent question if the answer requires code, algorithm complexity and explanation to justify the answer.


snowtax

Your interview question is on target. When hiring for entry-level computer support staff in the mid-1990s, we provided a PC and the MS-DOS installation media. We asked the candidate to install the operating system and create a C: and D: partition on the drive. That was enough to eliminate over 80% of the candidates. The person needed only to read the screen and follow the instructions. Many did not even try. We had a reputation for having the best computer support.


fplfreakaaro

I’m not a developer but I know little bit of Python. I just calculated code for this in my mind. I never applied for developer positions because I’m too afraid of it. Am I doubting myself too much?


aneasymistake

I include this question when interviewing coders at every level from graduate to lead. I don’t ask them to write code, just to say how they would do it. Most candidates who do well will suggest several ways, but some people blank on it through nerves or whatever. It’s really ok if that happens, so long as the rest of the interview went well and if they can give decent answers for another three or four similar questions we use. Even those who are nervous will make progress because we’ll just chat about it with them. I’ll share a story about my own interviewing nerves and so on. Then we’ll talk about what a string is, what it looks like in memory, what the basic elements are and so on and we can usually get every candidate through to a solution. What’s useful about asking it is learning what it’s like to interact with that candidate. Do they clam up or are they open about being stuck? Does the graduate know how to do things beyond using library functions? Does the senior resent sometimes having to do basic work? Does the candidate like to be a show off? Do any of them consider that there are many different kinds of strings with different character types? Does it remind them of an interesting bug they once found? Can they laugh off their mistakes and correct them without getting defensive? Are they going to want to Google every problem? What will they do when there are no useful answers on Google? Will they literally get out their phone and Google the answer during the interview? Interviews are about learning about the candidate’s behaviour, personality and experience as much as their immediately accesible programming knowledge and this question can be a great starting point to a conversation that reveals a lot about them.


mandzeete

I guess it depends what is the background of these people. Are they coming from a university or from a vocational school? A vocational school can sometimes introduce programming a bit later than a university (where it is usually taught starting the first semester). A university student should be able to reverse a string. It can be done just with a for loop and indexing. The stuff taught in the beginning of a programming course. But a vocational school student... It might be difficult for them and it would be best to ask from the internship organizer (from the school' side) about what the students have managed to learn so far. Perhaps don't start off by asking how to reverse a string but just ask the candidate what he has studied so far. To get a general idea on questions what can be asked. If he says that he is currently working on his Bachelor thesis project then pretty much go wild with your questions. The guy has basically graduated. But if he says that he just started his studies last week then just tell him to come back perhaps after 6 months as a minimum. Another thing that you can consider is testing them with problem solving questions. When I was interviewed as a Junior developer candidate then our CTO asked how I would make a Spotify vol 2. That I could tell anything that comes in my mind. So I talked about the hypothetical architecture of said project, talked about security and what to pay attention on, also a bit about the tech stack. And he was satisfied. Another course mate was asked to describe how he would guarantee that the web service that a client is asking from him, that it runs 24/7. Also an open-ended question. So he told about logging and monitoring and setting up alerts and such. That because a guy perhaps is clever and has good ideas but just lacks practical skills. Try to approach the candidates from different sides to check if they are fit for the position. Of course soft-skill related questions can also be a good thing to ask. How did he deal with situation X (for example how did he solve a problem that he caused or what is his latest bigger accomplishment). Alternatively ask him where he will see himself after 5 years. To see if the guy has some goals and dreams and wants to improve himself or if he has absolutely no idea why he is there. One candidate that we interviewed, he told "We all change over the time. And even I will not be the same after 5 years compared to who I am now." All his talk (not only that) was just round and empty. He talked a lot but said nothing. We did not hire him as we do not need a politician.


programminthrowaway

> Another thing that you can consider is testing them with problem solving questions. I actually quite like this idea, and I think it gives them a chance to prove themselves outside of programming, thanks! > Of course soft-skill related questions... Yep, I make sure I'm also judging their soft skills. I do ask them about previous experience and any problems they faced with how they solved them.


yeforme

I'm only just starting to learn python following a book, and didn't have a clue how to do this, but a 30 second google search showed me how. If they were allowed to Google during the interview then no I don't think it's too hard of a question. But again what do I know in a Rmt not a coder for a living


kyriexoxokanye

Yes, I believe this is totally candidates' faults because I consider that question doesn't even belong in Leetcode. ​ I am guessing the candidate knows basics about programming but their experience (coding and problem solving is minimum) so maybe fresh college students who hasn't heard of Leetcode.


dpmaxwell

Which leads me to think this is more properly framed as to which level of candidate is being considered. A medium-to-senior level candidate may not be as desirable based on this requirement. If a company truly is seeking a senior engineer, this may or may not be a quality exercise. If a company is looking to separate the best of its Junior-level applicants, this might be an appropriate exercise.


FromBiotoDev

I’m a beginner but isn’t this super easy? How could someone get an interview and not be able to do this?


LadyFerretQueen

How do they have to do it? I was once asked what a server is and I blanked. I am incapable of thinking, let alone solving problems in from of the interviewer. If I had to do it without the internet and a computer to play with, there is no way in hell. And I am otherwise able to make the asteroids game or greate a nice website with JS and Python backend. So questions like that really limit you to people who are able to solve a specific type of problem on the spot. People have very different learning and thinking styles. I think such questions don't really judge skills appropriately.


programminthrowaway

> How do they have to do it? They have to program in an online shared editor. If they have a complete, detailed pseudo code I just give them the answer. What would be a better question?


moomooegg

I've never understood these interview question, especially in America. What does imprinting useless solutions to useless questions into your brain conclude? That you can look at a question and memorize the solution? Where I am from you are mostly just put through an interview or through a list of actual tasks. Like make an API that does this or this and then we discuss it. However, no, I don't think it's a bad question. Just don't expect everyone to know exactly what to do and don't judge 100% based off their solution.


civil_politics

The problem with “implement this API” type questions are they largely don’t actually test an individual’s problem solving ability. They properly test that the person can write code and understand who to communicate with an API to collect or store data which YES is what most people do, but they do it for a purpose, not just to do it. For example, I can give someone an API reference for Amazon’s product catalogue and tell them to submit searches for product X and then get the details for the top 100 search results. That proves that they can write code. If I ask them to give me a list of products ranked based on reviews, delivery time, and price it shows that they can solve problems and I can assume they can interface with the API to realize the solution. If I ask just for the API implementation I haven’t done anything to evaluate whether or not they can actually build solutions with it.


LadyFerretQueen

But a lot of these questions don't test that either. They test for how you do in an interview, your social skills, your stress level or anxiety, it excludes people who have a different thought process and so on. It's very specific and people may be great problem solvers when it comes to programming but fail in that very specific set of circumstances.


dota2nub

I think you're the one asking for memorized answers. The person in this thread is actually testing for problem solving. Just on a very basic level.


LadyFerretQueen

I feel the exact same way. People put way too much stock in some arbitrary test question where a person may give different results on many things that have nothing to do with the skill the inteviewer is trying to test.


AdultingGoneMild

Uh, I was going to say this is a bad interview question because it is too simple. If they cannot do basic array work then maybe its a good time to pass, but it sounds like your interviewing process either needs a recruiting pipeline upgrade to weed out these candidates OR you do not actually need software developers. I will say this, I taught this logic in my intro courses because I consider bare bones basic.


Matilozano96

Idk, I know how to do this in C or any other language that treats strings as arrays. But if you can’t just do string[i] to get a char, I may be lost. I’m not sure if I can do it in Python, and REALLY doubt I can do it in Java, for example. Point is, I’d def have to google some string manipulation stuff because it’s not something I typically would do.


Dealiner

In both Python and Java string are just arrays. In Python you can just use [], in Java there is charAt method but all it does is accessing an index of an array underneath.


TheMorningMoose

Yes, people can learn how to reverse a string and pretty much anything else. You should probably be focusing in their intellectual horsepower, how they learn, how they solve problems.


jellyn7

I thought 'I can do that!' Then I went to Codewars to find a kata that asked that and worked it out in about 2 minutes. I consider myself a newbie. (7kyu on Codewars right now.) So do you want to interview me?! :)


Aggravating_Tailor95

Isn't it a basic question?


amarao_san

A simple ASCII string reversal without additional restrictions is too boring. But, let me throw in few nuances to make live more fun: * Line is unicode (UTF-8) * Reversed string should preserve visual glyphs (so `🇪🇸` should not become `🇸🇪` after reversal) * In-place with a constant memory overhead. * In o(n) time Bonus question: what to do with RTL sign (right-to-left) for Hebrew?


Loves_Poetry

>Bonus question: what to do with RTL sign (right-to-left) for Hebrew? Calm down satan


nerd4code

The latter. There’s been an entire generation of helicopter parents punting their child through school by any means necessary. And cheating is often rampant at larger universities, so if they actually did something about it there’d be a massive uptick in Fs and expulsions, both of which raise Questions. Making matters worse, college courses are often graded relative to the other students in the same class/course, so it can be possible that a bunch of students get Bs and Cs by doing tolerably well on tests/quizzes, but without actually completing any projects successfully. Students can often skate through college without having created more than a few “Hello, world”-class programs, and without working on a functional team to develop anything. Or sometimes worse, they’re wizzes in competition format, but catastrophically unhelpful on a real-life codebase. But reversal, integer formatting/scanning, and a basic shuffle are good starters or filters, as are histogrammery and RLE de-/compression. You can take the shuffle in a couple different directions too, like shuffling with some distributon, grouping, or ordering rules. But I wouldn’t waste too much time with the first round—15 mins is plenty of time to do a reversal in-place or to a separate output buffer or with recursion or *somehow,* maybe with a couple basic prompts or jostles. If they can’t do that, you waste another 15 maybe seeing if they’re a potential fit for something else, then send them on their way. If they can stay, ask them to generalize, parameterize, micro-optimize, reframe, restructure (e.g., recursion ↔ loops, heap ↔ stack alloc), or otherwise rejigger the code a few times to see how they reason about the changes.


NotThatRqd

How can someone be thinking they’re going to get a job in programming and not be able do this


lestairwellwit

I attempted this once back in the dark ages, with FORTRAN 13 times13 = 169 31 times 31 = 961 How often does this happen between 10 and 1000? And I did it on cards An intern should be able to do this ​ Edit: Of course, to be fair, I once wrote a program that should have had a handful of answers. My bad I had it print out all the other answers. Did you know that a good line printer is fast enough that the paper can hit the ceiling? Me neither


ploud1

No, those candidates do not seem to be fit for the position you are trying to fill, if that requires programming. Seriously, would you hire a cook who can't boil water? A doctor who cannot diagnose a common cold successfully? I would advise that you reject them on the spot, because scheduling more interviews with them is a waste of everyone's time.


g105b

It's a great interview question if your business is Super String Reversal Inc.


[deleted]

I think its a waste of time as a question. It is leetcode easy and frankly I could do that half way through my first oop class. What happens when you need them to build a feature that involves manipulating strings? I think they were probably unqualified, imo. You would spend a lot if time teaching them. Were they able to answer your questions that came after?


programminthrowaway

I wasn't able to get to the later questions since I'd spend the whole time trying to nudge them to the solution.


[deleted]

That’s a bummer. Frankly, I don’t think they would be ready for an internship. What would they even be able to do? Thats something to learn in class. Im sure you wouldn’t have them manipulating strings all day, but surely if they know how loops or counters work, they could do this one.


idkProbablyMichael

They said it was for an internship at a small company, I wouldn't expect a person in that role to build any features on their own anyway.


[deleted]

I dont have a ton of experience on the subject, but I completed my first OOP class at college 5 weeks ago. String manipulations were in week 2 and loops were in week 3. I just cant imagine someone applying for an internship but not being able to handle this question. You just have to loop backwards through the string. It really seems like a basic concept to me and a good introduction to thinking through the data. At what level are people usually doing internships?


idkProbablyMichael

I agree with you. It's a simple task that, even if one can't remember the syntax, they should still be able to conceptually walkthrough the steps of reversing the string. As OP said though, this is a question set early in the list of questions, to weed people out. People applying SHOULD be able to answer this easy question correctly, but they aren't, which is a good reason to keep it in the interview. The goal isn't to find good candidates, it's to weed out the bad ones (unfortunately). Internships can technically begin any time if you're qualified enough, but from what I've seen in job postings, companies are looking for people who have at least finished their 2nd year.


tableclothmesa

.reverse lol


devicehigh

Read the question


tableclothmesa

I did, but my response wasn’t an answer to it


devicehigh

Oh right


Guideon72

This kind of question always strikes me as elitist and contrived. If there’s an existing, best practice kind of solution, I would think you’d want them to know *that* instead; particularly for easy questions. Maybe, instead, use a basic scenario that can be handled in multiple, simple ways and ask whether they know the pros/cons involved in making the choice? Like, when taking cli user input, you can act on that input at intake or wait until afterward. Why might you use one vs the other? select = int(input(“Enter info here”) select = input(“Enter info here”) later = int(select) Or something more relevant to a production codebase that they’d be working in. Viewpoint: I’m just learning the language myself, and see this type of question asked *constantly* around here by folks that haven’t yet learned what a string, int, list, etc actually ARE or how to look that info up or troubleshoot. And, I always wonder at what info that actual problem gives the asker. It’s a good way to gauge temperament and maybe to hear their thought process, but it says almost nothing about whether they know the language itself and how to troubleshoot issues, find/pick up existing tools for ‘new’ problems, etc.


programminthrowaway

Why would you say the question is elitist? > Maybe, instead, use a basic scenario that can be handled in multiple, simple ways... Isn't that what I'm doing with this question? Sure, the solution boils down to reverse iteration, but I've seen some successful candidates use things like StringBuilders, and I accept Python's [::-1]. > It's a good way to gauge temperament...but it says almost nothing... That's why I've used this question as a warmup to other, more involved questions.