07/02/2022, 1:31 PM
In Kotlin how Immutable parameters affect space complexity if you have to copy the input every time to modify it? In Kotlin, function parameters are immutable, so you cannot modify the parameter in the code without making a copy first, does this affect space complexity, and does it prevent in-place modification, thus preventing it from having O(1) constant? What is the solution to this? fun replaceFirstElement(nums: IntArray, number: Int) { // not working nums[0] = number }