Please verify if space complexity is O(n) where n is number of bits, and aux complexity is O(1), since no temporary space was needed. Whatever space was needed was used for return value not for temporary purpose. Rectify my understanding of space and aux complexity if wrong.
Wrong.
Let's use another example. Bubble-sort uses \$O(1)\$ auxiliary space complexity. Bubble-sort does an "in-place sort", it does not require additional space except for a single temp variable.
Auxiliary means "helper". In the case of your code, the "helper" is the return value. The auxiliary space complexity of your code is \$O(n)\$.
Also remember this line:
return sum.reverse().toString();
How could you possibly reverse a string without storing the string in the first place? The space required to store this String is \$O(n)\$
There is an article on Geeks for Geeks explaining this and a question on Stack Overflow about it question on Stack Overflow about it.
Auxiliary space ignores the size of the input, not the output.
Please verify if space complexity is O(n) where n is number of bits, and aux complexity is O(1), since no temporary space was needed. Whatever space was needed was used for return value not for temporary purpose. Rectify my understanding of space and aux complexity if wrong.
Wrong.
Let's use another example. Bubble-sort uses \$O(1)\$ auxiliary space complexity. Bubble-sort does an "in-place sort", it does not require additional space except for a single temp variable.
Auxiliary means "helper". In the case of your code, the "helper" is the return value. The auxiliary space complexity of your code is \$O(n)\$.
Also remember this line:
return sum.reverse().toString();
How could you possibly reverse a string without storing the string in the first place? The space required to store this String is \$O(n)\$
There is an article on Geeks for Geeks explaining this and a question on Stack Overflow about it.
Auxiliary space ignores the size of the input, not the output.
Please verify if space complexity is O(n) where n is number of bits, and aux complexity is O(1), since no temporary space was needed. Whatever space was needed was used for return value not for temporary purpose. Rectify my understanding of space and aux complexity if wrong.
Wrong.
Let's use another example. Bubble-sort uses \$O(1)\$ auxiliary space complexity. Bubble-sort does an "in-place sort", it does not require additional space except for a single temp variable.
Auxiliary means "helper". In the case of your code, the "helper" is the return value. The auxiliary space complexity of your code is \$O(n)\$.
Also remember this line:
return sum.reverse().toString();
How could you possibly reverse a string without storing the string in the first place? The space required to store this String is \$O(n)\$
There is an article on Geeks for Geeks explaining this and a question on Stack Overflow about it.
Auxiliary space ignores the size of the input, not the output.
Please verify if space complexity is O(n) where n is number of bits, and aux complexity is O(1), since no temporary space was needed. Whatever space was needed was used for return value not for temporary purpose. Rectify my understanding of space and aux complexity if wrong.
Wrong.
Let's use another example. Bubble-sort uses \$O(1)\$ auxiliary space complexity. Bubble-sort does an "in-place sort", it does not require additional space except for a single temp variable.
Auxiliary means "helper". In the case of your code, the "helper" is the return value. The auxiliary space complexity of your code is \$O(n)\$.
Also remember this line:
return sum.reverse().toString();
How could you possibly reverse a string without storing the string in the first place? The space required to store this String is \$O(n)\$
There is an article on Geeks for Geeks explaining this and a question on Stack Overflow about it.
Auxiliary space ignores the size of the input, not the output.
Please verify if space complexity is O(n) where n is number of bits, and aux complexity is O(1), since no temporary space was needed. Whatever space was needed was used for return value not for temporary purpose. Rectify my understanding of space and aux complexity if wrong.
Wrong.
Let's use another example. Bubble-sort uses \$O(1)\$ auxiliary space complexity. Bubble-sort does an "in-place sort", it does not require additional space except for a single temp variable.
Auxiliary means "helper". In the case of your code, the "helper" is the return value. The auxiliary space complexity of your code is \$O(n)\$.
Also remember this line:
return sum.reverse().toString();
How could you possibly reverse a string without storing the string in the first place? The space required to store this String is \$O(n)\$
There is an article on Geeks for Geeks explaining this.
Auxiliary space ignores the size of the input, not the output.
Please verify if space complexity is O(n) where n is number of bits, and aux complexity is O(1), since no temporary space was needed. Whatever space was needed was used for return value not for temporary purpose. Rectify my understanding of space and aux complexity if wrong.
Wrong.
Let's use another example. Bubble-sort uses \$O(1)\$ auxiliary space complexity. Bubble-sort does an "in-place sort", it does not require additional space except for a single temp variable.
Auxiliary means "helper". In the case of your code, the "helper" is the return value. The auxiliary space complexity of your code is \$O(n)\$.
Also remember this line:
return sum.reverse().toString();
How could you possibly reverse a string without storing the string in the first place? The space required to store this String is \$O(n)\$
There is an article on Geeks for Geeks explaining this and a question on Stack Overflow about it.
Auxiliary space ignores the size of the input, not the output.
Please verify if space complexity is O(n) where n is number of bits, and aux complexity is O(1), since no temporary space was needed. Whatever space was needed was used for return value not for temporary purpose. Rectify my understanding of space and aux complexity if wrong.
Wrong.
Let's use another example. Bubble-sort uses \$O(1)\$ auxiliary space complexity. Bubble-sort does an "in-place sort", it does not require additional space except for a single temp variable.
Auxiliary means "helper". In the case of your code, the "helper" is the return value. The auxiliary space complexity of your code is \$O(n)\$.
Also remember this line:
return sum.reverse().toString();
How could you possibly reverse a string without storing the string in the first place? The space required to store this String is \$O(n)\$
There is an article onarticle on Geeks for Geeks explaining this .
Auxiliary space ignores the size of the input, not the output.
Please verify if space complexity is O(n) where n is number of bits, and aux complexity is O(1), since no temporary space was needed. Whatever space was needed was used for return value not for temporary purpose. Rectify my understanding of space and aux complexity if wrong.
Wrong.
Let's use another example. Bubble-sort uses \$O(1)\$ auxiliary space complexity. Bubble-sort does an "in-place sort", it does not require additional space except for a single temp variable.
Auxiliary means "helper". In the case of your code, the "helper" is the return value. The auxiliary space complexity of your code is \$O(n)\$.
Also remember this line:
return sum.reverse().toString();
How could you possibly reverse a string without storing the string in the first place? The space required to store this String is \$O(n)\$
There is an article on Geeks for Geeks explaining this.
Please verify if space complexity is O(n) where n is number of bits, and aux complexity is O(1), since no temporary space was needed. Whatever space was needed was used for return value not for temporary purpose. Rectify my understanding of space and aux complexity if wrong.
Wrong.
Let's use another example. Bubble-sort uses \$O(1)\$ auxiliary space complexity. Bubble-sort does an "in-place sort", it does not require additional space except for a single temp variable.
Auxiliary means "helper". In the case of your code, the "helper" is the return value. The auxiliary space complexity of your code is \$O(n)\$.
Also remember this line:
return sum.reverse().toString();
How could you possibly reverse a string without storing the string in the first place? The space required to store this String is \$O(n)\$
There is an article on Geeks for Geeks explaining this .
Auxiliary space ignores the size of the input, not the output.