• + 1 comment

    Complexity analysis does not care about the constant factors. It cares only about how time and space grows as you increase variables like n and d.

    Arguably, all of the variables are bounded by constants in the problem statement, so all solutions are O(1) time and O(1) space.

    If variables are unbounded, with large d, your solution would need more auxiliary space for your queue, whereas mine would not.