IPv4 Address Classification
Learn this problemProblem statement
Given a string address, determine its class as an IPv4 address.
A valid address for this exercise has exactly four dot-separated parts. Every part must contain one to three decimal digits and have a numeric value from 0 through 255, inclusive. Leading zeros are allowed.
After validating all four parts, classify the address by the first part:
- Return
1for values from1through126. - Return
2for values from128through191. - Return
3for values from192through223. - Return
4for values from224through239. - Return
5for values from240through255.
The first-part values 0 and 127 are reserved in this exercise. Return -1 for either reserved value or for any invalid address.
Function
classifyIpAddress(address: String) → intExamples
Example 1
address = "10.20.30.40"return = 1All four parts are valid, and the first part, 10, is in the range for class 1.
Example 2
address = "192.168.1.1"return = 3The first part is 192, so the valid address belongs to class 3.
Example 3
address = "127.0.0.1"return = -1Although every part is numeric and within the octet range, 127 is a reserved first-part value in this exercise.
Example 4
address = "10.20.300.40"return = -1The third part is greater than 255, so the address is invalid.
Constraints
1 <= address.length <= 100addresscontains ASCII characters.
More Rippling problems
- Cyber Beacon DetectionOA · Seen Aug 2026
- TV Shows Produced During a PeriodOA · Seen Aug 2026
- Filter and Sort Scheduled TasksONSITE INTERVIEW · Seen Jul 2026
- Stateful Log Transform and SearchPHONE SCREEN · Seen Jul 2026
- Delivery Cost TrackerPHONE SCREEN · Seen Jul 2026
- Corporate Card Expense RulesPHONE SCREEN · Seen Jun 2026
- Camel CardsPHONE SCREEN · Seen May 2026
- Article Vote TrackerPHONE SCREEN · Seen May 2026