HCL Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 2 vote

ptr->next->next = ptr->next->next->next

- Anonymous August 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

you just leaked the memory of the 5th node

- uruk_hai August 31, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The above is the correct solution, there is no need to move from your current pointer.

The only problem is the memory management. If you are in C++, then you just left that memory block allocated and have no way to reference it for the delete function to clean it up. If you are using Java, then the de-referencing will mark the 4th node for garbage collection.

This would be a very excellent call out to demonstrate your understanding of appropriate memory management in your given language.

- masterjaso August 31, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@masterjaso: @uruk_hai is correct.He just leaked the memory of the 5 node basically making it a dangling pointer.

- aka September 01, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't think the method before is correct , because the method didn't free the memory !

- liupeng September 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ptr->next->next->next^=ptr->next->next;
free(ptr->next->next);
ptr->next->next^=ptr->next->next->next

- liupeng September 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please explain the use of XOR (^) operator.

- Mr.Black September 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

could you please explain the Xor logic.
thanks
sanjay

- sanjay September 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Once you do a free, ptr->next->next->next can be junk. So wrong solution.

- Anonymous September 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, convoluted thinking.

Equivalent code without the convoluted XOR is

free(ptr->next->next);
ptr->next->next = ptr->next->next->next;

- Anonymous September 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What about:

delete(++++ptr----);

- Jimo September 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This assumes that the linked list nodes are contiguous and it also does not repair the linked list when the node is deleted.

- paul.nikonowicz September 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

// TODO: Handle next's == NULL
ptr->next = ptr->next->next->next;
delete ptr->next->next;

- Anonymous September 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

whoops just realized i scrogged line 2 with line 1's assignment

- Anonymous September 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Idiotic question for an interview. (Probably) Good puzzle though.

- Anonymous September 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ptr->next->next = ptr->next->next->next;
ptr->next->next-> = NULL;
delete ptr->next->next;

- Anonymous September 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

second line should be removed

- curious September 12, 2013 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More