Cracking The Coding Interview 6th Edition
The question is return the kth to last element of a singly linked list. All the proposed solutions are pretty complex, and I don't know why my solution is invalid. Could someone please let me know why?
- Cracking The Coding Interview 7th Edition Pdf
- Cracking The Coding Interview 6th Edition Filetype Epub
Now in the 6th edition, the book gives you the interview preparation you need to get the top software developer jobs. This is a deeply technical book and focuses. Cracking the Coding Interview, 6th Edition is here to help you through this process, teaching you what you need to know and enabling you to perform at your very best. I’ve coached and interviewed hundreds of software engineers. The result is this book. Cracking the Coding Interview 6th Ed. Contribute to careercup/CtCI-6th-Edition development by creating an account on GitHub.
mkobit3 Answers
A singly linked list would not have both next
and previous
. You have a doubly linked list, which clearly makes this problem easier.
I don't have a copy of that book, so I don't know what complicated solutions might be found in it, but the following two-finger solution seems pretty simple to me, and is not that different from yours aside from using a singly-linked list: Fifa 10 setup.exe download.
riciriciThe first solution in the book says:
Solution #1: If linked list size is known
If the size of the linked list is known, then the kth to last element is the (length - k)th element. We can just iterate through the linked list to find this element. Because this solution is so trivial, we can almost be sure that this is not what the interviewer intended.
Cracking The Coding Interview 7th Edition Pdf
But we can easily find the size of the linked list by one pass! So modifying the OP's question, I ask what is wrong with the following answer?
We use two pointers. Use one to find the size of the linked list, and use the other one to go (size - k) steps.
(Implementation in Python)
LoMaPhLoMaPh