Chhaya Shah’s Post

🚀 𝐃𝐚𝐲 89/100 – 𝐈𝐬 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 Today’s problem was 𝐈𝐬 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 — a simple yet fundamental problem to understand two-pointer technique. 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: We can efficiently check if one string is a subsequence of another using two pointers. 💡 𝐂𝐨𝐫𝐞 𝐈𝐝𝐞𝐚: Traverse both strings Move pointer of s only when characters match Always move pointer of t  𝐖𝐡𝐲 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬? We try to match characters of s in order within t without disturbing sequence. ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Initialize two pointers i (for s) and j (for t) If characters match → move both Else → move only j If i reaches end of s → subsequence exists ⏱️ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 📦 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(1) #Day89 #100DaysOfCode #Java #DSA #LeetCode #TwoPointers #CodingJourney

  • graphical user interface, text, email

To view or add a comment, sign in

Explore content categories