Interview Question: Reversing an Immutable List in #java
▻https://hackernoon.com/interview-question-reversing-an-immutable-list-in-java-57a891a521c5?sour
For a recent series of Java interviews, I prepared a question on how to reverse an immutable list. I figured out that the problem was not that straightforward for most of the candidates. Hence, I have decided to share it.ProblemWe have to implement the following interface to reverse an input list:▻https://medium.com/media/8c9e3b49ba38aac19d4e94c850d03d75/hrefAs an example of the expected result:Input: 1, 2, 3Output: 3, 2, 1The only constraint is that the input list is immutable.The current implementation is the following:▻https://medium.com/media/5aeb2214df7d93bd01a33959350c42e1/hrefThis solution will produce the expected result. Yet, from a performance perspective, there are few problems. Can you spot them?Would you have implemented it in a different way?We consider accessing a given index (...)
#algorithms #immutable-list #functional-programming #programming