Is this address complete enough to ship
The checkout refuses street-level addresses without a door number. A record has the street name and a number field that may be empty.
- A street that is empty or whitespace is invalid regardless of the number.
- A number of zero or less also makes the address invalid.
- Both present means it is valid.
addressValid(street: string, doorNumber: int) → bool
C++ needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
bool addressValid(std::string street, int doorNumber) {
}
Worked examples
| Call | Result |
|---|---|
addressValid(std::string("Bagdat Cad no 12"), 12) | true |
addressValid(std::string(" "), 5) | false |
addressValid(std::string("Kumsal Sok"), 0) | false |
addressValid(std::string(""), 12) | false |
Hint
Trim the street, then check the number.
Reference solution in C++
bool addressValid(std::string street, int doorNumber) {
return !street.empty() && street.find_first_not_of(" \t\n\r") != std::string::npos && doorNumber > 0;
}