I am initializing my 2D array using the below snippet:
let arr = new Array(m).fill().map(() => new Array(n).fill(-1));
There are some other ways too to initialize it what I need help is in language like C++ there is a simpler way to initialize it using memset. How is time complexity and space complexity affected compared to C++ or Java when using this snippet?
In c++, with memset the time complexity is O(log n). however that if you're going to do any future modifications to the object, It would cost O(n).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With