a linked list is given, and a only pointer to a node is given which need to be deleted. it is singly linked list. you dnt have accees to any other pointer like head or what. you only have that node pointer in ur hand. thanks.

Swap the data with the next node and then delete that node. This trick is obviously incomplete and its suitability depends on the design of the list, but if you're working with unreasonable requirements, you often have no choice but to enforce unreasonable limitations on the solution.

yes, i have already implemented this case, but problem arises when the node given to us is last node in the linked list. then ? thanks sir.

You say "a linked list is given", and a "pointer to a node which is to be deleted". Do you actually mean this; that you get the list in some way, AND the node to be deleted?

If you have nothing but the node to be deleted, and it's the last one (by which I mean doesn't point at another node), you can delete it but the previous node will be left pointing at bad data and there's nothing you can do about it.

Sometimes, when people say "last" they actually mean the node that was added most recently, which will be pointing at the one added before that, and so on, so if that's what's meant here, you can simply delete it and ensure you give back a pointer to the one it was pointing at.

Edited 3 Years Ago by Moschops

but problem arises when the node given to us is last node in the linked list. then ?

That falls under my "you often have no choice but to enforce unreasonable limitations" clause. If your list doesn't have a sentinel tail node, you're SOL. Too bad, so sad, use a double linked list next time.

no, it was asked by Microsoft to my friend last month. it is exact copy of questions which he has aksed to him. he then said "what if i pass last node in the list to this function?". then he said it is impossible. although he is rejetced (dnt know why), but i was curious to know whetther his answer was correct or not. thanks!

no

No what? Just because it's an interview question doesn't change the answer. Without more information about the structure of the list, you cannot assume that the problem is solvable in a realistic way. Thus you're left with three options:

  1. Accept equally unrealistic restrictions on the solution.
  2. Ensure the structure of the list such that it's conducive to a realistic solution.
  3. Use a double linked list.

i was curious to know whetther his answer was correct or not

His answer was more incorrect than correct. The correct "answer" in an interview is to get more information. For example, "does this list use a sentinel tail node?". I'd probably also reject someone who jumped to the conclusion that it was impossible without trying to fully understand the problem. However, in some cases it is indeed impossible, but without being sure that you're looking at such a case, it's wrong to reach that conclusion.

Edited 3 Years Ago by deceptikon

want to distract myself from topic, i wana ask you, suppose i am giving an interview, and interviewer asks me a question which i already know very well, so what should i do ? should i fake it that i dont know OR should i say him that i know the answer already OR do what ? thanks. I really need your view point on this. thanks a lot sir. :-)

should i fake it that i dont know OR should i say him that i know the answer already OR do what ?

Interview questions generally adhere to one of two goals:

  1. Determine if the candidate is a good cultural fit for the company.
  2. Determine if the candidate is capable of doing the job.

In interviews I don't really care if you know the answer or not; I'm more interested in seeing how you reach an answer than what the answer is. So I'd suggest following the "show your work" rule. If you want to rattle off an answer, that's fine, but expect to be asked to explain any answer you give.

so, you mean i should fake it but i must be ready for explaining anything related to my answer ?right sir ?

secondly, if i dont know the answer or say i dnt have any idea related to that, then should i make vague guesses or just say them "sir, i have no idea!". what is preferable at that point of time ? thanks .

P.S i wish if Daniweb would come to our campus and you would take my interview. :p (haha)

Edited 3 Years Ago by nitin1

so, you mean i should fake it

It doesn't matter, do what you want.

but i must be ready for explaining anything related to my answer ?

Always.

if i dont know the answer or say i dnt have any idea related to that, then should i make vague guesses or just say them "sir, i have no idea!"

If you don't know the answer, try to figure it out. Or say you don't know and explain how you might go about finding the answer. Guessing won't make you look good in the eyes of the interviewer.

you have made diplomatic answer. if i try to fake it, then don't u think it will be good wheni start with basic solution and then pretend that i am approachinga good answer (which i already know) ?

secondly, what will you say about this type of question. like i am giving interview for RBS or say AMAZON, they ask me "what if you get an offer from google after joining here ?" . it is really a very difficult question to answer.

you have made diplomatic answer. if i try to fake it, then don't u think it will be good wheni start with basic solution and then pretend that i am approachinga good answer (which i already know) ?

Okay, I'll drop the diplomacy. If I discovered you doing something like this I'd end the interview immediately and tell you to piss off. Known liars get a no hire vote from me 100% of the time.

You should cultivate intellectual honesty. That'll win you more points than giving a good answer.

secondly, what will you say about this type of question. like i am giving interview for RBS or say AMAZON, they ask me "what if you get an offer from google after joining here ?" . it is really a very difficult question to answer.

I don't think that's a difficult question at all. Depending on your goals, be honest. Take NDA and non-compete agreements into consideration as well. If you'd rather work at Google, RBS or Amazon shouldn't be offended if your options change after you're hired. They may not like it, but they shouldn't fault you for keeping your options open and seeking the best possible job for your goals.

Keep in mind that an interview goes both ways. You're interviewing the company just like they're interviewing you. If they react poorly to an honest answer, that's indicative of a cultural mismatch. Despite all of the resources on how to nail the interview suggesting that you're trying to pass a mandatory test, you can walk away if you don't like what you see.

This article has been dead for over six months. Start a new discussion instead.