DSA Sheet - Day 6 Strings

DSA Sheet Day 6 - Strings | ExpertFunda

🚀 DSA Sheet – Day 6: Strings (Part 1)

Welcome to Strings! This section focuses on pattern recognition, frequency counting, and sliding window techniques — all extremely common in interviews.

📊 Progress Tracker

Progress: 0 / 6 Completed

Done Problem Practice Level Companies
Valid Palindrome Solve Easy Cisco, Zoho, Paytm
Valid Anagram Solve Easy Google, Directi
Reverse Words in String Solve Medium Amazon, Adobe
Remove All Occurrences Solve Medium Google, Microsoft
Permutation in String Solve Medium Uber, Goldman Sachs
String Compression Solve Medium Amazon

🧠 Key Approaches

  • Valid Palindrome: Two pointer, ignore non-alphanumeric
  • Valid Anagram: Frequency count (array/hashmap)
  • Reverse Words: Trim + reverse logic
  • Remove Occurrences: Stack or string simulation
  • Permutation in String: Sliding window + frequency match
  • String Compression: Two pointer (in-place write)

⚡ Quick Cheatsheet

Valid Palindrome


int l = 0, r = s.size() - 1;

while(l < r){
  if(!isalnum(s[l])) l++;
  else if(!isalnum(s[r])) r--;
  else if(tolower(s[l++]) != tolower(s[r--])) 
    return false;
}
    

Valid Anagram


int count[26] = {0};

for(char c : s) count[c - 'a']++;
for(char c : t) count[c - 'a']--;
    

Permutation in String (Sliding Window)


vector s1(26), s2(26);

for(char c : s1) s1[c - 'a']++;

for(int i = 0; i < s2.size(); i++){
  s2[s2[i] - 'a']++;
}
    

🔥 Pro Tip

Strings are all about patterns:
  • Two Pointer Traversal
  • Sliding Window
  • Frequency Counting
Once you recognize patterns, most string problems become predictable.
Continue Reading →