IP Address to CIDR Blocks
Given a starting IPv4 address startIp and a positive integer count, return the minimum set of CIDR blocks that exactly covers the count consecutive IPv4 addresses starting at startIp.
Each CIDR block must be written in the form a.b.c.d/prefix. The returned blocks must cover the range exactly and use the minimum possible number of blocks.
You may assume the input is a valid IPv4 address and that the range stays within the IPv4 space.
Complete the function ipRangeToCidrBlocks in the editor below.
ipRangeToCidrBlocks has the following parameters:
String startIp: the first IPv4 address in the rangelong count: the number of consecutive IPv4 addresses to cover
Returns
String[]: the minimum CIDR cover for the range.
1Example 1
A single IPv4 address is represented by a /32 CIDR block.
2Example 2
The range from 0.0.0.0 through 0.0.0.255 is exactly one /24 block.
Constraints
Limits and guarantees your solution can rely on.
1 <= count <= 2^32startIpis a valid IPv4 address.- The answer must cover exactly the requested range using the minimum number of blocks.