Tensorum
YouTubeশেখা শুরু করুন
LeetCode 392 · Two Pointers

Is Subsequence

LeetCode 392 · সহজ · সমাধান, intuition ও ধাপে ধাপে ওয়াকথ্রু

Greedy two-pointer match.

সহজTwo PointersStringDynamic Programming
LeetCode-এ খুলুন ↗

আমি Is Subsequence (LeetCode 392) এভাবে সমাধান করেছি — Two Pointers প্যাটার্নের একটি সহজ প্রবলেম। নিচে: intuition, ধাপে ধাপে approach, আমার accepted Python কোড, animated test cases আর line-by-line debugger।

নিচের বিবরণ ইংরেজিতে।

Intuition

Scan t once; whenever its character matches the next needed character of s, advance in s. If you consume all of s, it's a subsequence.

Approach

  1. 1

    i over s, j over t.

  2. 2

    Match → advance both; otherwise advance only j.

  3. 3

    Return i == len(s).

আমি কীভাবে সমাধান করেছি

Two pointersPythonO(n) time · O(1) space
class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        i=0
        j=0
        while i<len(s) and j<len(t):
            if s[i]==t[j]:
                i+=1
                j+=1
            else:
                j+=1
        return i==len(s)
স্টেপ-থ্রু লোড হচ্ছে…

Is Subsequence — সাধারণ প্রশ্ন

Is Subsequence-এর পেছনে intuition কী?

Scan t once; whenever its character matches the next needed character of s, advance in s. If you consume all of s, it's a subsequence.

Is Subsequence (LeetCode 392) কীভাবে সমাধান করবেন?

1. i over s, j over t. 2. Match → advance both; otherwise advance only j. 3. Return i == len(s).

Is Subsequence-এর time আর space complexity কত?

Time: O(|t|)। Space: O(1)। (Accepted approach: Two pointers।)

Is Subsequence-এ সাধারণ ভুলগুলো কী?

An empty s is always a subsequence.