What do you think? Should I hire him?
What do you think? Should I hire him?
this looks like something you could find on stackoverflow
Given the task, that's expected.
No, this is absolutely awful.
Yeah, sure. At least he knows how to use statics. This is probably about as good as you're going to get for a java programmer.
i mean i don't want to be a dick but this is just basic java. there's seriously nothing innovative about this. if you're looking for someone that just knows java, yea go ahead i guess. You're asking Sup Forums for business decisions so don't expect too much
>that terrible tabbing and not putting curly braces on their own line
I wouldn't
how would you write it better?
>method is called reverseString
>doesnt reverse the string
wow
yes i would, this code is fine
there are two ways of putting curly braces, it makes no difference while the program executes, unless you're autistic and you need another space for a curly bracket or to increase the number size of your code to look as if you put in more work go for it i guess
+statics
+correct regex
-improper array declaration
-looping over the wrong value
It doesn't count against him, but I would have liked to see a test and a StringBuilder. There's pressure to hire him just to secure that part of the budget, but I'm not happy about it.
Isn't that output variable an array instead of string as requested? (I dont code java)
The declaration for output is wrong and this will not compile.
>-looping over the wrong value
please explain
I would not hire him and by him I mean OP. This is clearly some shit homework.
all this aside, the code is garbage, he splits into an array are you kidding me? this is some entry level shit at best.
How to do it correctly:
set the output string length to be same as input string.
initialize a char pointer to the last char of the input string,
if last char is space then dec pointer until you hit a none-space char, otherwise dec until you hit space.
great, here's your first char word or spaces only word, memcopy that to the start of the output string.
etc...
next time do your own homework kiddo.
the fuck is a char pointer in java
he wants to reverse the string, but hes taking the 0th value of the split array, that being the first word of original string
s ="this is a test".split(" ")
print(" ".join([s[x] for x in range(len(s)-1 ,-1 ,-1 )]))
i dont know op. I didnt see the way he planned out the code, the way he wrote it, how much time he took, etc. An interview test isnt about the final product, its about how they get that final product. or at least it should be.
>java
delete your entire company
Integer underflow once i hits 0
noob
print("test"[::-1])
Op here. This is what I would expect from an entry level dev. I put the test in the same file for ease of screenshotting. This took me about ten minutes, in-between bites of my lunch.
>int i = input.length() - 1
1. Length is a field, not a method
2. You want it to be splitArray.length anyway
You'd be surprised what we have to start with to weed out candidates.
Also, your proposed solution is really more complex than we need. Remember, developer time is more expensive than CPU time.
When can you start?
>Should I hire him?
Depend on experience.
Bachelor degree? Why not for some babysitted position where you can teach him real java.
Master degree? No.
Experience java dev? Fuck no.
The code is something a first-year would do, he clearly doesn't know java.
Also this Give us more code and the time he spent to do it.
oh wow java, you are fucked with that shit.
in any normal language a char pointer is a typed pointer that points to a character.
I guess the java thing would be to have a char variable instead of a pointer and hope that the compiler handles that like a pointer, LOL. Fucking pleb language.
def reverse_string(s):
return ' '.join(reversed(s.split()))
>>Multi-billion dollar companies use Java
>some NEET on Sup Forums "dElEtE yOuR eNtIrE CoMpAnY"
wouldnt the words be backwards eith that method.
for instance, the first word in the output would be txet instead of text?
Wrong.
According to your solution the output is
'tset a si siht'
nice spongebob meme!
reverse_string = lambda s: ' '.join(reversed(s.split()))
I too watch Rick and Morty
it's not complex. It's only complex to you because you write in java and all you know is higher level abstract functions you call from your standard libraries.
This doesn't solve the problem.
We always get one candidate that tries to show off. They take 40+ minutes, don't write any tests, and never get it correct.
According to the recruiter he's a Full stack developer with 4+ years experience with the same consulting company. Experience with cloud computing, microservices, spring boot, angular 1.5, and creating apis.
This is all the Java we asked him to write. It took about 15 minutes.
no, you are recording the start char and end char position of a word using pointer arithmetic and once you have a full word you do a single memory copy operation. there is no character reverse going on.
The code is perfectly fine.
What are you sperging about?
>He should have used epic one liners instead
A language to test OOP proficiency: Java
A language to test ability to fuck around with string manipulation: anything but Java
Yes, yes. StringBuilder autism and knowing that String is immutable in Java. But if this is for a Java developer position you'll want to make sure they can actually grok the SOLID principles, because you're using fucking Java.
In any case
>instantiating a string array then immediately discarding it
>bad indent
>leaves trailing whitespace
9/10, you've found your average senior java dev
" ".join ((raw_input()).split (" ")[-1::-1]
Muh python
Just hire me remote for like 90k. More if you're going to make me suffer through some spring bullshit.
Whoops forgot a parenthesis. You know where to add it.
Look, his solution works, so it's fine.
You can bet your ass it won't make a change in Java.
It would be a whole lot different if you were hiring a C++ developer.
doesn't work
It's not supposed to be complex. It's supposed to be clean and correct. If you have access to high-level constructs, use them.
Which code is perfectly fine?
That string array never even gets instantiated, because it doesn't even compile.
>Which code is perfectly fine?
The OP picture.
Nope. It is not. Try to compile it.
Looks like legacy code to me.
Also depends what's important to you.
Do you want a readable code, or best performance?
One too many left parathesis
Are most interview questions this simple?
It probably wouldn't if you tried to compile python code in java.
" ".join ((raw_input()).split (" ")[-1::-1])
Werks on my machine.
){
eww
Are you trolling? You have to tell me if you are. It's the law.
Assuming you fix the type issues, what is the output for a single word? What should it be?
Readable code > performance in 99% of cases.
Delete your entire company
his curly braces are mismatched and he has his return value tabbed wrong
I'll bite.
First, if I were being interviewed I'd ask what the default behavior for white spaces should be.
Second, if we're speaking of being effective and implementing an actual solution to the problem - use of string builder - instead of only showing the correct way to solve it (which imho should always be the case on entry level interviews), I would expect someone to present a faster and more memory effective way of doing things than just splitting string to array on space character. No idea how split is implemented in java, maybe it's on equal with processing string one character at time, maybe it's not. Probably it's not. Additionally, adding " " at the very end of sentence and then trimming it is most definitely more cpu and memory intensive than writing a ternary operator.
Third, whereas unit tests are generally a good thing as they eliminate most of the stupid errors, those are the last thing I'd write on an interview. Unless, obviously, I'd be explicitly told to write them.
Simple, write it in any other language. Java is shit.
Anyways, OP - if that was an interview for entry level job (I assume it was), hire him. He doesn't seem brained, he just seems to barely know good coding practices and java standard library. Give him several months and a good supervisor and he'll be better than average pajeet.
>muh muh code readability is what matter
>meanwhile in another thread
>that's it I'm done, is shiet Sup Forums what should I use?
I hope you're not that kind of person...
Eearly optimization IS the problem, caring about performance should be a given for any competent developer on this planet.
Lowering the entrance barrier is a problem, we end up with shitty devs with 4 years of experience and can't use fucking StringBuilder.
This "it's fine as long as it compils" mentality must dies.
pleb cumming thru
public static String reverseString(String input) {
String output = "";
ArrayList arr = new ArrayList();
for (String lel : input.split("\\s+"))
arr.add(lel);
for (int i = arr.size()-1; i>=0 ; i--)
output += arr.get(i) + " ";
return output;
}
rate
i spit on python 2 users
Checked.
no nullpointerexception
no stringbuilder
no trimming of the last space
first-year_CS/20
You are right in almost every way. Interviewers love unit tests, and we lose our shit when we see them. They are also a good way to document your assumptions about how whitespace should work. It shows that you can be given an underspecified problem and still make progress on it.
The follow up questions are
1. Runtime complexity
2. Space complexity.
3. We're deploying your new Enterprise String Word Reverser, and we expect strings to be no more than a gigabyte in size? How much RAM should you request on the server order form?
So, pretty much any solution is fine as long as it uses less than 4x the input memory. The candidates know this at the start.
Have you ever worked with legacy code? Have you ever found a nasty hack that took you an hour to understand, but saves like a second of computation time over a long-running batch process? It happens all the time. You could print this word order reversal thing onto an asic chip for ~*maximum performance*~, but you're fucked as soon as your client decides they don't actually want the order of words reversed, they just want a palindrome generator or something.
It is dying, cloud computing is putting fixed costs on computation and helping companies to find the right balance between "CPU time" and "developer time"
Its not happening here clearly. After you all are finished with java, I guess python is next
print ' '.join(s.spit()[::-1])
Put some braces on those for loops and call hr.
Can anyone tell me is this better or not
>Create pointer variables for every letter after \n and create an array of pointers.
>reverse the pointer array.
>concat everything .
function reverseString(str) {
return str.length
> reverseString("this is a test") 'tset a si siht'
fuck off cuckold
If "early optimization" means "well-considered scalable design", I agree.
If it means "let's start with pointer arithmetic because I need this fizzbuzz to be fast", I disagree.
>Have you ever worked with legacy code?
Mostly c-ansi
>Have you ever found a nasty hack that took you an hour to understand, but saves like a second of computation time over a long-running batch process?
I care more about cache-misses and misused memory which are real problem for alot more companies than faster computing.
>maximum performance
We have powerful tool, use them. It's not like StringBuilder is complex or something...
Like using ArrayList for FIFO, it works but it's plain retarded.
>It is dying, cloud computing is putting fixed costs on computation and helping companies to find the right balance between "CPU time" and "developer time"
yeah, because cloud computing is magic and you don't need actual developers to, you know, develop these systems...
I meant whitespace not \n
Write it. You have ten minutes.
Don't flame me or my language of choice
# 9.000000000000002e-06
proc reverseRegex(s: string): string = s.splitWhitespace.foldl(b & " " & a, "").strip
# 3.999999999999989e-06
proc reverseOnWord(s: string): string =
result = newString s.len
var
start = s.high
n = 0
for i in countdown(s.high, 0):
if s[i] in Whitespace:
for c in i + 1..start:
result[n] = s[c]
inc n
start = i - 1
result[n] = s[i]
inc n
elif i == 0:
for c in i..start:
result[n] = s[c]
inc n
don't do it user, he'll put too many curly braces in all your projects and ruin them every time, his code otherwise looks fine but if he's going to make the simplest mistakes that can ruin large projects instantly, its not worth the extra time it will take to fix them, no matter how trivial it is to find and fix, that's still time unnecessarily spent, and it'll add up
are you retarded? or did you just memorize how to type up a for loop and forget how they work? i.e. for loops don't have to start at i=0 and in fact this one doesn't
Cache misses aren't a real problem here. We mostly deal with stuff like, some new data provider decides to use 4 character country codes when everyone else uses the ISO standard, so we have to change to seamlessly support both. In cases like this, it's much more important to be able to say what kind of code you're looking at, and not so much how it fits in your L2 cache or whatever.
This is what I mean when I say readability is more important. Does that make sense?
pascal?
nim
first time trying java
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
class Main {
public static void main(String[] args) {
System.out.println(reverse("this is a test"));
}
public static String reverse(String s) {
List l = Arrays.asList(s.split(" "));
Collections.reverse(l);
return String.join(" ", l);
}
}
first of all, checked
second of all, don't listen to this guy fuck those gay braces, back up your for loop body onto the same line as the for statement, then call hr
you're writing Java so thats probably the best you're going to get
Java engineer skill distribution has basically 0 std deviation
Let me know when you graduate, you parrot.
say brother, is that based nim?
hell yes, brother
reverse(null)
I often say that a lot of job employers test for the wrong shit. To be quite honest, as a coder myself, I know I'm 99% better than any person you will pick off the street cause I'm interested in obscure shit than whatever pejeet or some out of college coder can pull off. You'll be 10 times better with someone who has code sense and can probably give you a better product, too.
I dropped out of high school and manage hordes of programmers like you.
>Does that make sense?
of course that's not gonna make sense to someone like that. Developers like him are the reason the Linux kernel is a bloated unportable clusterfuck that can't even compile without legacy gnu bloat. Ignore him.
you'll get something like this
char[] charArray = strings.toCharArray();
char[] outputString = charArray.clone(); // so the have the same size
for (int i = charArray.length - 1, j = 0; i >= 0; --i, ++j) {
outputString[j] = charArray[i];
}
>reverse the pointer array.
>concat everything .
It's not enough to preserve the letter order within a word.
You have to consider words as entities within the sentence else you won't be able to get the good result.
the goal is to actually write the reverse method.
>Linux kernel is a bloated unportable clusterfuck t
Doesn't Linux give support to hundreds of architectures ?
>2018
>Java Array can't reverse itself
Kek
>not switching to Scala
It's like you want to live in the past grandpa
>missing the point this hard
kys
Should it return null if given null? Then null propagation?
Should it throw NullPointerException? It already does
this is better if he was doing it in c#
public static string reverseWord(string s) {
string ret = "";
Regex reg = new Regex(@"\b\w+\b", RegexOptions.None);
MatchCollection mc = reg.Matches(s, 0);
for(int i = 0; i
>Simple, write it in any other language. Java is shit.
That's not how the real world works
Returning null would be preferred. Returning an empty string is also okay.
You can use more than 3 characters to name a variable.
>regex
why
>using 3
Yikes
Does this work?
reverseString :: String -> String
reverseString = unwords . reverse . words
This looks horrible