This one tripped me up more than it should have.
First, clarify the iterator's internal representation and the expected behavior at boundaries. Then, design prev() by decrementing the address and handling wrap-around symmetrically to next(), ensuring that prev() followed by next() returns to the original position. Finally, discuss trade-offs such as using integer arithmetic versus string manipulation and potential edge cases.
Pro tip: Emphasize that the iterator's state should be a single integer, and both next() and prev() should update it atomically to avoid inconsistencies. Mention that testing with boundary values (0.0.0.0 and 255.255.255.255) is crucial.
Review the given next() method to see how it converts between string and integer representations and handles wrap-around. Identify the internal state variable and any assumptions.
Determine that prev() should return the previous IP address in sequence, wrapping from 0.0.0.0 to 255.255.255.255. Ensure that calling prev() after next() (or vice versa) returns to the same address.
Decrement the internal integer state by 1, applying modulo 2^32 to handle wrap-around. Convert the result back to the dotted-decimal string format.
Test that prev() followed by next() returns the original address, and that boundary cases (0.0.0.0 and 255.255.255.255) behave correctly. Consider thread-safety if needed.
Compare integer-based implementation with string manipulation, highlighting efficiency and simplicity. Mention potential issues with concurrent access and how to address them.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.