Split the Array to Make Coprime Products
A hard-tier problem at 28% community acceptance, tagged with Array, Hash Table, Math. Reported in interviews at Zomato and 0 others.
Split the Array to Make Coprime Products is a hard problem that shows up at Zomato and tests whether you understand the relationship between coprimality and prime factorization. You're given an array and need to find a split point where the product of left elements and product of right elements are coprime (GCD = 1). The 28% acceptance rate signals this isn't about brute force. The trick lives in number theory: you can't track full products without overflow, so you track only the prime factors that matter. This is exactly the kind of problem where missing the pattern costs you the interview.
Companies that ask "Split the Array to Make Coprime Products"
Split the Array to Make Coprime Products is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe naive approach computes all products and checks GCD, which fails on large numbers and isn't efficient enough. The real solution recognizes that two numbers are coprime if and only if they share no prime factors. Since you only care about primes up to 30 (the largest prime under 30 is 29, and any composite made from primes 31+ doesn't affect coprimality for smaller numbers), you can represent each product as a bitmask of which primes divide it. Build a prefix bitmask array and a suffix bitmask array, then iterate to find a split where prefix and suffix share no set bits. Hash tables track prime factor positions for efficiency. If you get stuck on the prime factorization or bitmask representation during your live OA, StealthCoder surfaces the working solution invisibly so you stay in control.
Pattern tags
You know the problem.
Make sure you actually pass it.
Split the Array to Make Coprime Products recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Split the Array to Make Coprime Products interview FAQ
What does it mean for two products to be coprime?+
Two numbers are coprime if their greatest common divisor (GCD) is 1, meaning they share no common prime factors. In this problem, you need the product of the left part and the product of the right part to have GCD = 1.
Why can't I just compute products and check GCD directly?+
Products overflow quickly on large arrays. The real issue is efficiency: you'd recompute products repeatedly. The key insight is to track only which prime factors divide each product, not the actual product value, using a bitmask of small primes.
Which primes matter in the bitmask?+
Only primes up to 30. Any integer up to around 10^18 is determined by its prime factors in {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}. These ten primes fit easily in a 10-bit bitmask.
How do I build the prefix and suffix bitmask arrays efficiently?+
For each element, compute its prime factorization once and set the corresponding bits in a bitmask. Then build prefix and suffix arrays where each entry OR's the bitmasks of all elements up to that point. This takes linear time.
Is this still asked at interview-stage companies?+
Yes. Zomato explicitly reports asking it, and its hard difficulty and low acceptance rate mean it's still considered a strong filter problem. Number theory problems like this stay relevant at companies that value algorithmic depth.
Want the actual problem statement? View "Split the Array to Make Coprime Products" on LeetCode →