In this example, I would start with the FP solution because that's how I happen to think. Probably familiarity bias, but I find the cognitive load much lower.
If performance becomes a problem (it might, after all there are several more passes than strictly necessary), have tests in place and refactor to an optimised imperative version.
If performance becomes a problem (it might, after all there are several more passes than strictly necessary), have tests in place and refactor to an optimised imperative version.