Easy data structure and algorithm practice puzzle.
Given a CIDR prefix length from 0 to 32, return the subnet mask as four octets: /24 becomes [255, 255, 255, 0]. A mask is simply that many 1 bits followed by 0s, split into bytes, so each octet takes whatever is left of the budget up to eight. The one to get right is a length that lands mid-octet, where /12 gives 240 rather than 255 or 0.
Solve it three ways: snap the jigsaw pieces together, fill in the blanks, or type it from scratch against the tests. This one is free.
Browse all 536 puzzles