For an example I have below mentioned input and output for function reverseWords()
It's a simple example but this will help me understand. How I will write a function which is In O(1) space for below request ?
// var input = ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r'];
// Output(same array): ['o', 'l', 'l', 'e', 'H', ' ', 'r', 'o', 'w']
// In O(1) space complexity
function reverseWords(input) {
}
reverseWords(input);
How I will write a function which is In O(1) space ? For example -
function reverseString(str) {
return str.split('').reverse().join('');;
}
reverseString("hello world");
Is this In O(1) Space complexity ? I have referred this What is O(1) space complexity? but still having doubt in terms of understanding in practical way of javascript.