• Hey Guest. Check out your NeoGAF Wrapped 2025 results here!

My company is trying to hire competent developers

Status
Not open for further replies.
Haha, I remember that being a solution for an ACM teaser.

I still like the 5-cycle soltion the best :D

POPCNT EAX, EAX
NEG EAX
ADD EAX, 32

or similar if you assume 64-bit operand.

You can extend this to larger integers by doing popcnt in a loop
 
I'm not a software guy, but from experience doing FPGA development, it takes being in a special brain space to quickly and confidently solve logic puzzles. The longer you have been doing it, the longer your brain has been conditioned to do them.

Yep, it's a completely different way of thinking. It's not merely a language difference. But going from structural coding to parallel/cyclical coding with very limited capabilities.
 
Another fun question to ask: swap two integers without using a temporary variable.

And yeah any developer who can't reverse a string is approaching full retard.
 
Sharp said:
Another fun question to ask: swap two integers without using a temporary variable.
This is only possible if you ignore that you're storing 1 bit of information in the PC register. It is a temporary variable of sorts... Though one that you need anyway.
 
This thread reminds me of why I hate doing developer interviews. They just so often turn into a "solve this logic puzzle!" or "I want you to use this really esoteric function and tell me what it does!" Almost always it's just an opportunity for the interviewer to show how big his e-peen is.

Some of the best developers I know are terrible at logic puzzles and others don't know every single library out there. Really when you want a good developer you're looking for a good problem solver. When I interview devs I almost always get the feedback that my interviews are very out of the box. I'm more interested if they could figure a problem out than I am that they can rattle off some bit of code they'll never use. And in every interview I always pose a problem I know they can't fix just to see if they can figure out they can't fix it and how they react when they figure that out.

Really dev interviews show just how immature our field really is.
 
for mobile / web / backend and it's nearly impossible to find any that are currently looking for a job. We've been searching for a year for candidates that can reverse a string and do the fib sequence recursively and we'll only found three.

Any one else experiencing the same talent drought at their company?

My company, IAC, is based in NYC.


Join the club. I'm in Atlanta with similar problems. I've got almost 50 openings and having a hard time finding qualified talent. Because everyone thought the universe was being outsourced to India, there was a huge drop in Computer Science enrollment. Now there is a huge talent shortage and the "day tuk ur jebs" crowd is basic making it impossible to bring in talent as well.

As a result the companies that can are opening offices in other countries and the companies that can't - well they will be at a huge competitive disadvantage.
 
I always want to respond in these threads and say I know a ton of developers who are looking for work, but, well, I really don't. It's too easy to find a job as a dev.
 
Join the club. I'm in Atlanta with similar problems. I've got almost 50 openings and having a hard time finding qualified talent. Because everyone thought the universe was being outsourced to India, there was a huge drop in Computer Science enrollment. Now there is a huge talent shortage and the "day tuk ur jebs" crowd is basic making it impossible to bring in talent as well.

As a result the companies that can are opening offices in other countries and the companies that can't - well they will be at a huge competitive disadvantage.

On a good note it's cake to get a job if you graduate from GT with a CS degree these days. :P
 
All this talk of string reversal made me come up with an awesome interview question. I might even use it next time I interview someone.

Consider the following two functions:

Code:
void reverse1(char* str, int len)
{
     int mid = len/2;
     for (int i=0; i < mid; ++i)
          swap(str[i], str[len-i-1]);
}

void reverse2(char* str, int len)
{
     char* other = new char[len+1];
     other[len] = 0;
     for (int i=0; i < len; ++i)
          other[len-i-1] = str[i];
     memcpy(str, other, len);
     delete[] other;
}

1) Which is faster, and why? If your answer is "it depends", elaborate.
2) Whichever version you decide is faster, discuss some additional changes that might make it even faster.

Your first instinct may not be correct
 
Our company is currently looking for night dispatchers and because we are shorthanded we are on a shitty 6 on/4 off schedule, which wouldn't be bad except that we have to work 12 hours a night, and the work can get pretty stressful. I know the economy is pretty good around here right now, but it is hard to find anyone willing to work these hours and for the amount of pay. This area is very affordable though.
 
Ok so I've never come across recursion before, or if I did it was very briefly and I forgot it. So I've been looking it up to try and understand it and I think I'm starting to get a vague idea of it but it's still hazy in areas. I'm more trying to understand why anyone would need to use it.

As for the Fibonacci sequence I've never heard of it before, I'm not really a maths guy so I'm trying to get this but maybe I'm thinking about it wrong. From what I gather it is a sequence of numbers starting from 0 or 1 as the seed where the next number is always the sum of the previous two numbers.

So that much makes sense to me. But the formula listed for it is confusing me a little, I think I'm missing something...

Fn = Fn-1 + Fn-2

Seems to be the formula....ok so if I make n in this instance 13 (which is part of the sequence) let's see if this pans out... it should be that 5 + 8 = 13.

13 - 1 = 12
13 - 2 = 11

12 + 11 = 23 ...which is not even in the sequence...where am I going wrong here conceptually?

So maybe it is...

13 - 1 = 12
(n now becomes 12)
12 - 2 = 10

12 + 10 = 22, also not in the sequence...

So to me the only way this makes sense is if Fn refers to a Fibonacci number, in other words only to numbers in the sequence, and then the sequence is like an array in a way and saying Fn - 1 is the same as saying the previous number in the sequence that is a distance of 1 position away etc...

So 1 postion previous to 13 is 8 and 2 positions previous is 5, add them together and you get 13.

Is this the right way to think about it? It's the only thing that makes sense to me....I'm not really a maths guy...

Ok so I was looking at a tutorial on recursion and this was a solution given to the Fibonacci recurrence in Java

Code:
/**
     * Recursively calculate the kth Fibonacci number.
     *
     * @param k indicates which (positive) Fibonacci number to compute.
     * @return the kth Fibonacci number.
     */
    private static int fib(int k) {
 
        // Base Cases:
        //   If k == 0 then fib(k) = 0.
        //   If k == 1 then fib(k) = 1.
        if (k < 2) {
            return k;
        }
        // Recursive Case:
        //   If k >= 2 then fib(k) = fib(k-1) + fib(k-2).
        else {
            return fib(k-1) + fib(k-2);
        }
    }

Ok...so I understand that this method is calling itself inside the body of the method. But what is the purpose of the program? Do you give it a fib number and is it supposed to calculate all of the following fib numbers in the sequence until it becomes too big to store as an integer?? Also if the formula for Fibonacci numbers works the way I think it does in that it is supposed to only count numbers in the sequence then how does this code work if fib(k-1) + fib(k-2) is subtracting 1 or two from the VALUE of the fib number and not from it's position in the sequence???

Arrgh maybe I'm just thinking about this wrong...anyone clear this up?
 
Seems to be the formula....ok so if I make n in this instance 13 (which is part of the sequence) let's see if this pans out... it should be that 5 + 8 = 13.

13 - 1 = 12
13 - 2 = 11

Fn-1 + Fn-2 is more correctly written as

F(n-1) + F(n-2)

In other words: Whatever the function returned for the previous value of n plus whatever the function returned for the value of n before that.

In other words:

F(0) = 0
F(1) = 1 (these two are just by definition)
F(2) = F(2-1) + F(2-2) = F(1) + F(0) = 1 + 0 = 1
F(3) = F(3-1) + F(3-2) = F(2) + F(1) = 1 + 1 = 2

etc
 
All this talk of string reversal made me come up with an awesome interview question. I might even use it next time I interview someone.

Consider the following two functions:

Code:
void reverse1(char* str, int len)
{
     int mid = len/2;
     for (int i=0; i < mid; ++i)
          swap(str[i], str[len-i-1]);
}

void reverse2(char* str, int len)
{
     char* other = new char[len+1];
     other[len] = 0;
     for (int i=0; i < len; ++i)
          other[len-i-1] = str[i];
     memcpy(str, other, len);
     delete[] other;
}

1) Which is faster, and why? If your answer is "it depends", elaborate.
2) Whichever version you decide is faster, discuss some additional changes that might make it even faster.

Your first instinct may not be correct

At a glimpse I thought the second was faster just because I saw memcpy() and delete, not sure why that stood out to me in that way.
 
Ok so I've never come across recursion before, or if I did it was very briefly and I forgot it. So I've been looking it up to try and understand it and I think I'm starting to get a vague idea of it but it's still hazy in areas. I'm more trying to understand why anyone would need to use it.

Well, a recursive function is one that calls itself. The function has a standard case and any number of 'base' cases which are usually the final call to the recursive function.. i.e. where it stops. Why use it over a iterative function? It can be a hell of a lot more elegant despite the complexity to look at.

As for the Fibonacci sequence I've never heard of it before, I'm not really a maths guy so I'm trying to get this but maybe I'm thinking about it wrong. From what I gather it is a sequence of numbers starting from 0 or 1 as the seed where the next number is always the sum of the previous two numbers.

That's the correct definition.

Where you're screwing up that formula is.. it isn't calculating a number, it's making a recursive call to itself with those numbers as the arguments. IMO if you want to understand just put it in your compiler and step through it with your debugger.
 
All this talk of string reversal made me come up with an awesome interview question. I might even use it next time I interview someone.

Consider the following two functions:

Code:
void reverse1(char* str, int len)
{
     int mid = len/2;
     for (int i=0; i < mid; ++i)
          swap(str[i], str[len-i-1]);
}

void reverse2(char* str, int len)
{
     char* other = new char[len+1];
     other[len] = 0;
     for (int i=0; i < len; ++i)
          other[len-i-1] = str[i];
     memcpy(str, other, len);
     delete[] other;
}

1) Which is faster, and why? If your answer is "it depends", elaborate.
2) Whichever version you decide is faster, discuss some additional changes that might make it even faster.

Your first instinct may not be correct
in general, the first version should be faster. Normally, the function call will get optimized and turned into an inline statement. On certain systems, assuming it doesnt get optimized, the constant function calls can cause the performance to degenerate.

Now, the second version also has the problem of not being guaranteed to be portable (first can be compiled as a pure c program for embedded platforms without malloc. The second version has no such ability)

2) Well, to start with, you use memcpy with the size of the buffer. There's no need for an extra character to be malloc'd. There's more, but im on a cell phone at work so can't go into detail without a lot of typos.

Also, the second version's malloc/new could fail so that's a bit problematic as well.
 
in general, the first version should be faster. Normally, the function call will get optimized and turned into an inline statement. On certain systems, assuming it doesnt get optimized, the constant function calls can cause the performance to degenerate.

Now, the second version also has the problem of not being guaranteed to be portable (first can be compiled as a pure c program for embedded platforms without malloc. The second version has no such ability)

2) Well, to start with, you use memcpy with the size of the buffer. There's no need for an extra character to be malloc'd. There's more, but im on a cell phone at work so can't go into detail without a lot of typos.

Also, the second version's malloc/new could fail so that's a bit problematic as well.

To be honest that's a decent answer and you'd probably score full points, but
there's something about the way version 2 is written that, if you ignore the cost of the malloc, makes it blazing fast. Likewise, for the same reason that version 2 is ridiculously fast, version 1 is on the opposite extreme of terribleness. The correct answer is still "it depends", but I'll wait a little longer to see what people come up with.
 
Fn-1 + Fn-2 is more correctly written as

F(n-1) + F(n-2)

In other words: Whatever the function returned for the previous value of n plus whatever the function returned for the value of n before that.

In other words:

F(0) = 0
F(1) = 1 (these two are just by definition)
F(2) = F(2-1) + F(2-2) = F(1) + F(0) = 1 + 0 = 1
F(3) = F(3-1) + F(3-2) = F(2) + F(1) = 1 + 1 = 2

etc

Ahh...I think I'm starting to get it, that makes allot more sense I think...so then the next few would be....

F(4) = F(4-1) + F(4-2) = F(3) + F(2) = 2 + 1 = 3
F(5) = F(5-1) + F(5-2) = F(4) + F(3) = 3 + 2 = 5
F(6) = F(6-1) + F(6-2) = F(5) + F(4) = 5 + 3 = 8

etc...

I think I'm starting to get it, so to go back to my array analogy for a second although I know it is not perfect I think it is kind of like this....imagine that there is an array F[] of all the possible fib numbers already defined and created. Then I could say something like...

int n = 6; //Trying to find the fib number at the 6th position, or the 6th fib no in the sequence

F[n] = F[n-1] + F[n-2] //(F[6-1] + F[6-2] = F[5] + F[4] = 5 + 3 = 8)

Ok, so the purpose of creating a program then is to tell you what fib number lies at the position of a given integer in the sequence eg: If you entered 8 it would you give you the 8th fib number which would be 21.

Ok cool, thanks I think I get at least the fib numbers now and what people mean when they ask you to do it in programming, you've really helped me allot here thanks.
 
This thread reminds me of why I hate doing developer interviews. They just so often turn into a "solve this logic puzzle!" or "I want you to use this really esoteric function and tell me what it does!" Almost always it's just an opportunity for the interviewer to show how big his e-peen is.

Some of the best developers I know are terrible at logic puzzles and others don't know every single library out there. Really when you want a good developer you're looking for a good problem solver. When I interview devs I almost always get the feedback that my interviews are very out of the box. I'm more interested if they could figure a problem out than I am that they can rattle off some bit of code they'll never use. And in every interview I always pose a problem I know they can't fix just to see if they can figure out they can't fix it and how they react when they figure that out.

Really dev interviews show just how immature our field really is.
Hey everyone I spent days with the rest of the programming team thinking up some awesome interview questions that I'm going to spring on some applicant and only give them minutes to figure out. lololololol.

I've had other programmers I know tell me of their "really good" interview questions that they had found. Only to point out that they themselves couldn't have answered that question if someone had asked it to them a couple days earlier.
 
Hey everyone I spent days with the rest of the programming team thinking up some awesome interview questions that I'm going to spring on some applicant and only give them minutes to figure out. lololololol.

I've had other programmers I know tell me of their "really good" interview questions that they had found. Only to point out that they themselves couldn't have answered that question if someone had asked it to them a couple days earlier.

Except that, as has been discussed ad nauseum in this thread, the point of the question isn't to get the correct answer. You can get every answer correct on these logic puzzles and still fail the interview. Since, you know, that isn't the point.
 
I started learning Lisp this year as part of my freshman year in uni, and since I was bored tonight I decided to give it a try. This is what I came up with:

Code:
(defun fib-recur (number &optional (list '(0)))
  (if (= number 1)
      '(0)
    (let ((next-list (fib-recur (- number 1) list)))
      (cond
       ((endp (cdr next-list)) '(1 0))
       (t (cons (+ (car next-list) 
		   (cadr next-list))
		(fib-recur (- number 1) list)))))))

I tried the method some other guys posted but found that when I was running long sequences it was about three times as ineffective. Is there something wrong with my code below, or is the method I posted above that much more effective?

Code:
(defun fib-recur2 (number &optional (list '(0)))
  (cond
   ((= number 1) '(0))
   ((= number 2) '(1 0))
   (t (cons (+ (car (fib-recur2 (- number 1) list)) 
	       (car (fib-recur2 (- number 2) list)))
	    (fib-recur2 (- number 1))))))
 
I'm a first year CS student learning C++, and I'm trying to learn as much as I can. Tried out reversing a string in C++, and got it working tonight. (Wanted to try to make it work without using the reverse function...). Does this code look okay to you guys?

Code:
#include <iostream>
#include <string>
using namespace std;

int main () {
	string reversal;
	string newstring;
	cout << "Enter a string: ";
	getline(cin, reversal);
	for (int i = reversal.length() - 1; i >= 0; i--) {
			cout << reversal[i];
	}
	cout << endl;
	return 0;
}

Seems to reverse the string just fine. EDIT: Looking at it now, though, I realize that I didn't even use "newstring", since I ended up just printing out the reversed string, and not assigning it to the new string...

I'll give the fibonacci problem tomorrow I think.

The thing that scares me about interview questions like this is the fact that I can get it to work when I'm at home with a compiler, and I can go through bugs and fix my logic errors and everything. This for example, I ran into a few troubles just because I wasn't using the string class correctly. The actual algorithm was easy to come up with, but the figuring out how exactly to make it do it was a bit trickier.

How would you feel about an interviewee that got the basic algorithm down fine on paper, even if the actual program wouldn't compile/run due to some small logic or implementation mistake?

Either way, I've got a ton to learn, but I'm having fun with it.
 
I'm a first year CS student learning C++, and I'm trying to learn as much as I can. Tried out reversing a string in C++, and got it working tonight. (Wanted to try to make it work without using the reverse function...). Does this code look okay to you guys?

Code:
#include <iostream>
#include <string>
using namespace std;

int main () {
	string reversal;
	string newstring;
	cout << "Enter a string: ";
	getline(cin, reversal);
	for (int i = reversal.length() - 1; i >= 0; i--) {
			cout << reversal[i];
	}
	cout << endl;
	return 0;
}

Seems to reverse the string just fine. EDIT: Looking at it now, though, I realize that I didn't even use "newstring", since I ended up just printing out the reversed string, and not assigning it to the new string...

I'll give the fibonacci problem tomorrow I think.

Your solution is pretty good for being a first year student. In a real interview you would probably be asked to write a function that returns the reversed string, but it's possible you haven't even learned that stuff yet, and your answer is fine.

The thing that scares me about interview questions like this is the fact that I can get it to work when I'm at home with a compiler, and I can go through bugs and fix my logic errors and everything. This for example, I ran into a few troubles just because I wasn't using the string class correctly. The actual algorithm was easy to come up with, but the figuring out how exactly to make it do it was a bit trickier.
The point of interview questions is to gain insight into one's ability. If your answer to the question demonstrates your ability while not being 100% correct, then you probably did well on the interview.

It's also not as simple as just "did the guy do well on the interview?" It also comes down to how well other people did, and ultimately there are only a finite number of positions available. If I'm only hiring for one opening but two people are interviewing and both did pretty well on the interview and were generally likeable / socially appropriate for the work culture, then I'm going to have to start getting creative with the factors I start taking into consideration.
 
To be honest that's a decent answer and you'd probably score full points, but
there's something about the way version 2 is written that, if you ignore the cost of the malloc, makes it blazing fast. Likewise, for the same reason that version 2 is ridiculously fast, version 1 is on the opposite extreme of terribleness. The correct answer is still "it depends", but I'll wait a little longer to see what people come up with.
Do you mean that the second writes to a different place than it reads from? I'd expect that would result in better optimizations. Copying large blocks of data like that would probably be more optimized (though you'd do it twice), and you could be pretty sure you'd never stall the pipeline. I'm not entirely sure that would be the case, but it's my bet.

Though, I still think the first would probably be faster. Allocating that extra memory and doing two copies is not something I'd expect to be cheap. Profiling might be interesting.
 
All this talk of string reversal made me come up with an awesome interview question. I might even use it next time I interview someone.

Consider the following two functions:

Code:
void reverse1(char* str, int len)
{
     int mid = len/2;
     for (int i=0; i < mid; ++i)
          swap(str[i], str[len-i-1]);
}

void reverse2(char* str, int len)
{
     char* other = new char[len+1];
     other[len] = 0;
     for (int i=0; i < len; ++i)
          other[len-i-1] = str[i];
     memcpy(str, other, len);
     delete[] other;
}

1) Which is faster, and why? If your answer is "it depends", elaborate.
2) Whichever version you decide is faster, discuss some additional changes that might make it even faster.

Your first instinct may not be correct

Hmm... I'm thinking the 2nd one is faster because it encapsulates(sp?) the process whereas the 1st one your calling another swap function who knows how many times. I see you also allocating/deallocating dynamic memory in the 2nd one so after you make the memcpy you just return that memory to the system. Pretty cool. I like it.

Idk, how you make it faster. I'm too tired to think "see" clearly. lol. Also, the code like[ len-i-1] takes me awhile to see so I have to always work it out in my head with an example lol :(
 
Wow, I hope I never have to pass interviews like the OP. I had to google what this fib was and I thought 'reverse string' was some super special function (realized afterwards you just meant reversing a string..)

I'm a super fast learner and I've been called a genius several times, been hired at every place I've done work practice, but I would totally fail the OP's test. And tbh, I don't think it would be my fault. Half of my knowledge is Googling something and learning it in 5 seconds (this splits up the good from the bad, the bad just copy and hope it works) and putting it in practical use, not remembering every snippet of code I've written. I rather have team coders be able to answer "can you make this before the deadline" and simply answer yes, no or in my case "with plenty of time left".

Don't misuse the word "talent", which doesn't stand for "having a huge database in your head".
 
Because it's fun to show off your programming skillzzzz despite sacrificing performance and optimization and readability and upkeep!

It's a good answer. There are other good answers, but they're very few and far between these days.
 
It's a good answer. There are other good answers, but they're very few and far between these days.
Wait, that was a semi-serious question? Because my answer was kinda a semi-troll :P

A semi-serious answer would be to limit memory usage per user where the application doesn't require speed, usually in business systems with a ton of users (but times are changing, people want speed too!). Or for security reasons, programming is limited in fixed variables (but then I'd argue the one writing it is probably a part-time scripter, not a programmer who manages the application in it's whole), or for any other nonsense coding limitation where you're not allowed to create variables of your own. Though I think in all cases, this is a situation that a programmer shouldn't stumble upon where bypassing creating new temporary variable is a viable option.

Or maybe for when someone who doesn't know how to create a new variable, as some languages require you to initiate it first. Or has no access to that snippet of code to actually initiate it.

Still, it's a troll question, right? Right :O?
 
Wait, that was a semi-serious question? Because my answer was kinda a semi-troll :P

It was kind of serious, kind of semi-troll itself. If anyone's asking how to do something incredibly artificial and unnecessary, then the question of why they're asking that is important too. The best answer to the question "how would you swap two integer variables without using a temp variable" to my mind would be "I wouldn't, unless you have a situation that actually requires it."
 
Guys, an interview question is not like a quiz. You don't have a get it right, you just have to provide a good answer, and be confident enough.

I know someone who asked "Star Wars or Star Trek?" in an job interview...
btw, the only wrong answer to this question is being offended by it


It was kind of serious, kind of semi-troll itself. If anyone's asking how to do something incredibly artificial and unnecessary, then the question of why they're asking that is important too. The best answer to the question "how would you swap two integer variables without using a temp variable" to my mind would be "I wouldn't, unless you have a situation that actually requires it."

Exactly. And that would probably be the best answer.
 
It was kind of serious, kind of semi-troll itself. If anyone's asking how to do something incredibly artificial and unnecessary, then the question of why they're asking that is important too. The best answer to the question "how would you swap two integer variables without using a temp variable" to my mind would be "I wouldn't, unless you have a situation that actually requires it."
Ah, great post. That's what went through my mind reading the OP's post. Like why would you want the fib sequence or why would you want to reverse a string (amateur password protection perhaps?). I always thought that programming is completely different than mathematics in the sense that you're seeing everything from a practical + solution sense, not just for the sake of writing random code.
 
Your solution is pretty good for being a first year student. In a real interview you would probably be asked to write a function that returns the reversed string, but it's possible you haven't even learned that stuff yet, and your answer is fine.

Thanks, I've got a ton to learn (little overwhelming at times) but I feel like I'm making progress. I enjoy it as well. Anyway, yeah, that would make more sense to write it as a function, so I went ahead and did that this morning:

Code:
string reverseStr(string original) {
	string reversed;
	reversed = original; //Did this to initialize reversed with the same length
	int i = original.length() - 1;
	for (int j = 0; i >= 0; i--, j++) {
		reversed[j] = original[i];
	}
	return reversed;
}


The point of interview questions is to gain insight into one's ability. If your answer to the question demonstrates your ability while not being 100% correct, then you probably did well on the interview.

It's also not as simple as just "did the guy do well on the interview?" It also comes down to how well other people did, and ultimately there are only a finite number of positions available. If I'm only hiring for one opening but two people are interviewing and both did pretty well on the interview and were generally likeable / socially appropriate for the work culture, then I'm going to have to start getting creative with the factors I start taking into consideration.

That's good to know...thanks for the insight. I'm sure any programming interviews for me won't be for another few years down the road, but I'm trying to learn as much as I can in the interim.

Ah, great post. That's what went through my mind reading the OP's post. Like why would you want the fib sequence or why would you want to reverse a string (amateur password protection perhaps?). I always thought that programming is completely different than mathematics in the sense that you're seeing everything from a practical + solution sense, not just for the sake of writing random code.

I'm a beginner so take or leave this, but I think it has much less to do with ever having to actually use that particular problem, and much more to do with knowing how to solve a problem, and how to use skills that are applicable in other areas. For instance, I would assume I would probably never need to reverse a string in the real world. But I'm sure I WILL have to manipulate strings, and being able to reverse one shows that you have the underlying skill set necessary to do so.

I would also assume it's a chance to get a better idea of how their thought processes work, and their problem-solving skills.
 
Thanks, I've got a ton to learn (little overwhelming at times) but I feel like I'm making progress. I enjoy it as well. Anyway, yeah, that would make more sense to write it as a function, so I went ahead and did that this morning:

Code:
string reverseStr(string original) {
	string reversed;
	reversed = original; //Did this to initialize reversed with the same length
	int i = original.length() - 1;
	for (int j = 0; i >= 0; i--, j++) {
		reversed[j] = original[i];
	}
	return reversed;
}




That's good to know...thanks for the insight. I'm sure any programming interviews for me won't be for another few years down the road, but I'm trying to learn as much as I can in the interim.



I'm a beginner so take or leave this, but I think it has much less to do with ever having to actually use that particular problem, and much more to do with knowing how to solve a problem, and how to use skills that are applicable in other areas. For instance, I would assume I would probably never need to reverse a string in the real world. But I'm sure I WILL have to manipulate strings, and being able to reverse one shows that you have the underlying skill set necessary to do so.

I would also assume it's a chance to get a better idea of how their thought processes work, and their problem-solving skills.
Yes this is correct. Its weird that people don't understand this. I think when I start interviewing ill start asking candidates why they think I am asking these questions.
 
Yes this is correct. Its weird that people don't understand this. I think when I start interviewing ill start asking candidates why they think I am asking these questions.

Except, of course, that they don't necessarily test these skills in a way that actually works well. Especially when people (like the OP) are concerned about them getting the right answer. The best interviews I've attended have included simple real-world coding cases.
 
Status
Not open for further replies.
Top Bottom