HARDasked at 1 company

Find the Number of Subsequences With Equal GCD

A hard-tier problem at 29% community acceptance, tagged with Array, Math, Dynamic Programming. Reported in interviews at Infosys and 0 others.

Founder's read

You're staring at a hard problem that asks you to count subsequences where every element shares the same GCD. It's the kind of problem that looks alien at first, then snaps into focus once you see the pattern. Infosys has asked it. The acceptance rate sits at 28%, which means most candidates either miss the trick or code themselves into a corner. The real challenge isn't the GCD logic itself, it's knowing when and how to apply dynamic programming to avoid brute-forcing every possible subsequence. If this problem lands in your live assessment and you haven't drilled the GCD + DP bridge, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
1
Difficulty
HARD
Acceptance
29%

Companies that ask "Find the Number of Subsequences With Equal GCD"

If this hits your live OA

Find the Number of Subsequences With Equal GCD 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. Built by a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

The trap is thinking you need to generate all subsequences and filter them. You don't. The key insight is to iterate through all possible GCD values that could exist in the array, then count subsequences that achieve each one using DP. For each element, you update states: either it joins an existing subsequence with a certain GCD, or it starts a new one. The GCD of a subsequence can only shrink or stay the same as you add elements, never grow, which bounds your state space. Most failures come from either trying to track subsequences directly (time explosion) or mishandling the GCD update logic when a new element enters. Number Theory and Array iteration matter, but Dynamic Programming is what makes it tractable. This is exactly where StealthCoder acts as your hedge on live OAs: if the DP transition doesn't lock into place during the interview, a working solution surfaces instantly.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find the Number of Subsequences With Equal GCD 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. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find the Number of Subsequences With Equal GCD interview FAQ

Is this really a hard problem or just annoying?+

It's genuinely hard. The 28% acceptance rate isn't inflated. The idea of pairing subsequence counting with GCD state transitions isn't intuitive. If you've never combined Number Theory with DP before, you'll likely time out or TLE. Most candidates understand GCD. Most understand DP. Bridging them under pressure is where the problem lives.

Do I need to know every GCD value in advance?+

No, but you need to know that GCD values are bounded. For any array of size n, the number of distinct GCD values that can emerge from subsequences starting at any position is O(log max element). This bound is what makes the DP tractable. Abuse this constraint to avoid unnecessary state bloat.

What's the main pitfall when coding this?+

Mishandling the DP transition. When you see a new element, you can't just update existing GCD states, you must also create a new state where that element stands alone. Many solutions forget this or implement it wrong, leading to undercounting. Get the transition logic right first, optimize later.

Is this still asked at big tech companies or just Infosys?+

The input shows Infosys has asked it. Hard Math + DP problems are less common in typical FAANG loops than graph or tree problems, but Number Theory tends to resurface at certain types of companies. If you're targeting roles with heavy algorithmic rigor, this pattern is worth drilling.

How do I practice this without grinding 100 similar problems?+

Focus on understanding why subsequence counting + GCD state transitions work together. Practice problems that combine counting subsequences (DP) with properties that only shrink or stay constant (like GCD). Then solve this one until you can code it from memory under time pressure.

Want the actual problem statement? View "Find the Number of Subsequences With Equal GCD" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.