🔤 Strings (Coding)
Day 2 | ⏱️ Part of 3-Hour Coding Block | TCS Interview Prep
📌 Subtopics
- Anagrams: Check if two strings are anagrams, group anagrams
- Palindromes: Check palindrome, longest palindromic substring
- Frequency Counting: Character frequency, first non-repeating character
- Pattern Matching: Naive approach, KMP algorithm basics
🌐 Learning Resources
| Resource | Link |
|---|---|
| GFG — String Data Structure | geeksforgeeks.org |
| GFG — Anagram Check | geeksforgeeks.org |
| GFG — Palindrome Check | geeksforgeeks.org |
| GFG — Pattern Matching (KMP) | geeksforgeeks.org |
| NeetCode — Strings | neetcode.io |
| LeetCode — String Problems | leetcode.com |
✅ Must-Practice Problems (LeetCode)
| Problem | Difficulty | Link |
|---|---|---|
| Valid Anagram | Easy | leetcode.com/problems/valid-anagram |
| Valid Palindrome | Easy | leetcode.com/problems/valid-palindrome |
| Longest Palindromic Substring | Medium | leetcode.com/problems/longest-palindromic-substring |
| First Unique Character | Easy | leetcode.com/problems/first-unique-character-in-a-string |
| Implement strStr() | Easy | leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string |
| Longest Common Prefix | Easy | leetcode.com/problems/longest-common-prefix |
📝 Key Patterns
# Check Anagram
from collections import Counter
def is_anagram(s, t):
return Counter(s) == Counter(t)
# Check Palindrome
def is_palindrome(s):
s = s.lower()
return s == s[::-1]
# First Non-Repeating Character
def first_unique(s):
freq = Counter(s)
for i, ch in enumerate(s):
if freq[ch] == 1:
return i
return -1
# Frequency Count
def char_frequency(s):
freq = {}
for ch in s:
freq[ch] = freq.get(ch, 0) + 1
return freq
🔗 Related Topics
- Arrays and Hashing — Hashing patterns are core to string frequency counting and anagram checks
- Dynamic Programming — Longest palindromic substring, edit distance, and regex matching are classic DP string problems
- Patterns and Series — Alphabetic/numerical reasoning patterns and shift ciphers
- Odd Man Out and Analogy — Letter analogies and word anagram identification
- Verbal Ability — General grammar, context, and email writing (concepts of word groupings)