Are storing strings O(1) space? I am really confused about this since a mix of people saying its O(1) and O(n) at the same time.... Could someone help me on this one? I really need it for practicing for my interviews. Thank you!!
O(1) would make sense only for complexity and not space since the size of the memory allocated for a string depends on how big it is.
As for complexity:
Depending on how the language implements it (stack or heap) it would be O(1) for stack or non-deterministic for heap, because heap allocation is handled by the OS (but as a rule of thumb, its generally O(1) if the strings are not huge).
O(n) would be for space:
When you store a string, basically what you are doing is storing an array of characters.
This would be the size of the string, since it grows linearly with the size of the string (Every character = 1 byte in a ASCII(8-bit) string).