educative.io

Space complexity of n-queens

The proposed solution builds an array results with every solution, each of O(n) size. The stated space complexity is O(n), but would this results array exceed that and reach O(nk) space, where k is the number of solutions? Normally we exclude our output from the space complexity, but in this case our output is the number of solutions, and the results array is auxiliary and would therefore qualify for space complexity analysis. If we replace the results array with a counter, could we reduce the space comp to O(n)?


Course: Grokking Coding Interview Patterns in Python - AI-Powered Learning for Developers
Lesson: https://www.educative.io/courses/grokking-coding-interview-patterns-python/solution-n-queens