Bear Bibeault wrote:Doesn't look like a Servlets issue to me. I'll move this along to the Beginning Java forum...
Stefan Evans wrote:First questions
- where are your test cases? How would you test this code? Thats a big part (or probably the larger part) of answering the question.
- I'm not a big fan of "static" I would probably have instantiated some objects to solve this problem.
- your 'equalize' method seems to do work that according to the spec is not needed. Maybe I'm making an assumption, but the question seemed to indicate you could expect a rectangular array. Checking and 'fixing' it to be rectangular seems to be extra unnecessary work I would mark you down on.
You call the method: AllWebLeads.searchSequence(i, j, -1, 1);
What does this -1 for angle mean? It is not documented.
I would suggest using an enumerated type for the angle to make it more readable.
Use JavaDoc for documenting your methods
Why does the method searchSequence return a value? Do you ever use it?
Using "Global variables" gets huge negative points from me.
I would suggest some JUnit test cases be written :-)
Ernest Friedman-Hill wrote:There is a method of 60 lines and one of 100 lines in the code; anything more than 10 lines is to be avoided, and methods of just a few lines are best. 100 lines is a huge red mark.
Vipin Anand wrote:I mean the stack operations involved in function calls could be an overhead here.
Bear Bibeault wrote:
Vipin Anand wrote:I mean the stack operations involved in function calls could be an overhead here.
That's like worrying if you have a fever while standing on the surface of the sun.
Besides always worry about code clarity first, then worry about performance if and only if you have a demonstrable performance issue.
Bear Bibeault wrote:You might want to look up the term premature optimization.
angle = -1 implies ...[snip]
Equalize method does not make an array rectangular. It basically solves a problem of unequal rows within the array.
For e.g. input array[] = {{1,0,1},{0,-1}}. Will output {{1,0,1},{0,-1,0}} so a 0 is appended at {0,-1} to make sure my program does not crash when I am traversing the array.
AllWebLeads.searchSequence(i, j, -1, 1); it does return the 'count' variable to check whether its equal to the expected length or not (its a recursive function
Stefan Evans wrote:Feedback on your test class
Why are the examples that they provided in the question not in your test cases? Those should be the first ones in.
Rather than one humongous test, each test case should be in a separate, well named method.
That way you can say at any point "x out of y test cases are working"
And you can also pinpoint exactly which ones you are having trouble with.
Currently all you can say is "the unit test fails somewhere"
It would have been nice to lay out your tests as a 2d array for easier reading, rather than all in one line.
Vipin Anand wrote:Too bad I missed out a good opportunity (rare one for an international student like me) in spite of nailing the problem but not in a right way.
SCJA 6 (Studying for SCJP 6)
Jared Malcolm wrote:
Vipin Anand wrote:Too bad I missed out a good opportunity (rare one for an international student like me) in spite of nailing the problem but not in a right way.
It's always a long shot (but you have nothing to lose). Take the suggestions provided here and redo your work and submit again. Just mention to the HR person that you got some suggestions from fellow coders and implemented them on your own and without help. This in my mind shows that you can follow a standard if one is provided for you and that you really want the position....whats the worst thing they will say?
Your code worked correct? Do it another way and see if they like it better (if they will accept it).
I'am a Chinese.I like Java.Hello.
Luigi Plinge wrote:Code seems way too verbose for what is required, hence unreadable and unmaintainable. I put this together in a few minutes:
If you want to improve your coding I would thoroughly recommend doing a bunch of TopCoder practice competitions. The problems are very similar to this one (in fact I wouldn't be surprised if this were "borrowed" from TopCoder). It's great practice and you can see how everyone else tackled this problem, which is good for showing how you can write your code more efficiently.
It means our mission is in jeapordy! Quick, read this tiny ad!
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
|