IPv4 Address Classification
Updated
Problem 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 ASCII decimal digits and have a numeric value from 0 through 255, inclusive. Leading zeros are allowed.
After validating all four parts, classify by the first part:
- Return
1for0..127. - Return
2for128..191. - Return
3for192..223. - Return
4for224..239. - Return
5for240..255.
Return -1 for an invalid address. First-part values zero and 127 are valid members of class 1.
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 = 1The first part 127 is included in class 1, whose range is zero through 127.
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 Online Assessment questions
- Most Segments That Sort the ArrayOA · Seen Nov 2026
- Palindromic Paths to the RootOA · Seen Nov 2026
- Server InvestmentOA · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- REST API: Highest International StudentsOA · Seen Sep 2026
- Token ValidationOA · Seen Sep 2026
- Consistent LogsOA · Seen Sep 2026
- Costliest ChocolateOA · Seen Sep 2026
- Server ManagementOA · Seen Sep 2026
- Cyber Beacon DetectionOA · Seen Aug 2026
Similar questions at other companies
- Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
- Generate Table of ContentsJP Morgan Chase · OAJP Morgan Chase interview questions
- Incident MonitorStripe · OAStripe interview questions
- Correct Apartment Bedroom CountsRamp · OARamp interview questions
- Hidden ArtifactsIMC Trading · OAIMC Trading interview questions
- Build a Profile Sentence from CSVAirbnb · OAAirbnb interview questions
- Restricted Decimal Number ValidatorLinkedIn · PHONE SCREENLinkedIn interview questions
- Extensible Grep Line FilterBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Format CSV Rows as an ASCII TableAmazon · PHONE SCREEN
- Compare Calendar DatesWells Fargo · PHONE SCREENWells Fargo interview questions