📎 Webclip
O(n) Solution to the Multiply Others Problem in F#
The problem is a Facebook interview classic: given an array, produce a new array where each position holds the product of every other element, without using division and in O(n) time. Yan Cui shares an F# implementation of a solution built on two auxiliary arrays.
Fichamento#
- One array accumulates products left to right, the other right to left. Position i in the first array holds the product of everything before it; position i in the second holds the product of everything after it.
- Multiplying the two arrays position by position gives the final answer, computed with one forward pass and one backward pass.
- The approach avoids division entirely and runs in O(n) time and O(n) space.
- Cui includes the full F# code, a GitHub-hosted snippet, and links to the original CareerCup question plus his own Project Euler and Advent of Code solutions in F#.
