Hacker News new | past | comments | ask | show | jobs | submit login

Every variant is fine. It's really the kind of thing you do for the most basic possible filter. The point isn't so much what they do, as whether they're able to produce any working code more advanced than Hello World.

But it's also then possible to make use of "one step up" by asking people for variations and seeing whether they can talk about tradeoffs (still at a very basic level, but still).

E.g. in a higher level language, if asked to reverse the order of the words you often get variations of split on space, reverse the resulting array, join. In which case you have an opening to ask them if they can do it lower level, in minimal space.

In which case, the "typical" solution becomes to reverse the string in place, then iterate and find the start of each word, and reverse that in place. Both reverse operations need at most two pointers and a temporary, and can be done with the same function if you take in a start and end pointer.

If you have that helper to reverse a given character range in place, reversing the order of the characters within each word without reversing the word order is just the same thing without reversing the whole string first.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: