Nerd
BAN USER- 2of 2 votes
AnswersIterate over a singly linked list backwards. Call print on each node.
Example: The list A->B->C should print as
"C B A"class Node { public Node next; public String value; }
There are 4 solutions
- Nerd in Europe
1) recursive
2) iterative with O(n) memory
3) iterative with O(1) memory and O(n²) runtime
4) iterative with O(1) memory and O(n) runtime (for this solution the initial list may be modified)
Explain all 4 solutions and write the code for solutions 3 and 4| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding - 1of 1 vote
AnswersYou are given an array of integers.
- Nerd in Europe
Write an algorithm that brings all nonzero elements to the left of the array, and returns the number of nonzero elements.
The algorithm should operate in place, i.e. shouldn't create a new array.
The order of the nonzero elements does not matter. The numbers that remain in the right portion of the array can be anything.
Example:
given the array [ 1, 0, 2, 0, 0, 3, 4 ],
a possible answer is [ 4, 1, 3, 2, ?, ?, ? ], 4 non-zero elements, where "?" can be any number.
Code should have good complexity and minimize the number of writes to the array.| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding
Reprichardcstrong, Accountant at AppPerfect
I am a modern magician, except I transform complicated technical ideas into user-friendly images before the eyes of your company ...
Repchristinetcollazoc, Software Analyst
I am a pediatric nurse.I administer directly procedures and medicines to children according to prescribed I also continually assess ...
Repwilliamchansen95, Computer Scientist at 247quickbookshelp
I am working as a manager in Lionel Kiddie City company. I really enjoy my job. I like to play ...