Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Java solution space complexity

Alex

Aug 8, 2023

The Java solution has a space complexity of O(N), not O(1), because toCharArray() allocates a new array: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html#toCharArray()

A solution using charAt() would have O(1) space complexity.

0

0

Comments
Comments

On this page

Problem Statement

Solution

Code

Time Complexity

Space Complexity

Conclusion