32

Reverse the given string without using inbuilt java methods... 😭😭😭😭

Every time you will get this question even when you have more than 6 yrs of experience 😡

Comments
  • 17
    I had this question once, although they didn't specify a language to use and didn't say no builtins, so... I used python.

    return string[::-1]

    This was for a Cloud DevOps job... Entry level, but still...
  • 6
    I don't think it's anything to do with the job, but problem solving and reversing a string is a pretty basic problem.
  • 4
    @SanitizedOutput you can't do something like this

    new StringBuffer("your string").reverse().toString();
  • 3
    This should work with java too
  • 4
    @SanitizedOutput that is exactly what I was thinking. How to I convert this string to an array of chars without any methods
  • 3
    @SanitizedOutput then .split(""), dont be a r
  • 1
    Always I will use this logic Hope this is acceptable...
  • 5
    @ashokramcse This will break characters that need more than 1 byte.
  • 5
    Push each character to a stack, pop them off into a new string. Reversed.
  • 6
    put a mirror in front of the screen
  • 0
    I ask this question too in interviews. For a couple of reasons: when someone applies for a senior C# position I expect to know the framework's built in reverse method. If he doesn't know that, then I expect him to know that, when concatenating strings, you should use a stringbuilder when you do more than 5 concats, and if the applicant says to have experience in TDD, I expect to see it developed using TDD. In addition, this is quite a basic task, and you don't need strong mathematical skills to create a proper algorithm, I prefer such a simple assignment over some simple assignment that requires a solid mathematical background, unless of course you apply for a job as 3D engine developer where you'd need math.
    Though the simple assignment you'd be surprised of all the different solutions people come up with! It gives a great opportunity for discussing why someone did it like that and gain some insights in someones way of thinking.
Add Comment