Thursday, December 3, 2026 | London 10°C · Drizzle
DailyGlimpse

AI

LeetCode 3336: Solving the Hard Problem of Counting Subsequences with Equal GCD Using DP

Explainedbychhavi 1 min read

In this tutorial, we tackle LeetCode 3336, a hard-level problem that asks for the number of subsequences where the greatest common divisor (GCD) of the elements is equal across two subsequences. The video begins with a clear explanation of the problem statement, then walks through a brute-force approach, which leads to time limit exceeded (TLE) due to exponential complexity. The core of the lesson is an optimized dynamic programming (DP) solution that efficiently counts the valid subsequences. The DP leverages GCD properties and uses a state representing the current GCD value, reducing the time complexity significantly. The video also covers the time complexity analysis and provides a step-by-step Java implementation. Perfect for developers preparing for coding interviews who want to deepen their understanding of DP and number theory.

React