Restore IP Addresses
Problem Statement
You are given a string s of digits. Insert dots into s to make valid IPv4 addresses. A valid address has exactly four parts. Each part is a number from 0 to 255, and it cannot have a leading zero: 01 is not allowed, but 0 is. You may not reorder or remove any digits. Return every address you can make, in any order.
A string s of digits.
A list of every valid address. Each address is the digits of s with three dots inserted.
Both splits give four parts with values from 0 to 255 and no leading zeros: 255 | 255 | 11 | 135 and 255 | 255 | 111 | 35.
Every part is a single zero. A single zero is allowed, so there is one address.
Five splits work. For example, 1 | 0 | 10 | 23 is valid, and so is 1 | 0 | 102 | 3, because 102 is at most 255.
- • 1 ≤ s.length ≤ 20
- • `s` consists of digits only.
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Try all three-cut positions and check the four parts of each split
Place one part at a time (1 to 3 digits); prune when the digits left cannot fill the parts left
Choose three cut positions a < b < c. They split s into four parts: s[0..a), s[a..b), s[b..c) and s[c..]. Try every split into four parts, and keep the ones where all four parts are valid.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Backtracking translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.