188 days ago · Tech · hide · Fediverse post

The challenge Given a slice of positive integers, return the value with the most digits. If two or more values share the highest digit count, return the first one in the slice. Examples: findLongest([]int{1, 10, 100}) // → 100 findLongest([]int{9000, 8, 800}) // → 9000 findLongest([]int{8, 900, 500}) // → 900 This Codewars-style puzzle is asked in Go interviews and screens for understanding of slices, ties, and avoiding allocations. Solution 1: count digits with integer division The most idiomatic Go version — no strconv allocation:

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town