DSA Questions and Answers (Strings, Linked List, Stack, Queue)
String Questions
1. Reverse a String - Use two-pointer approach or stack to reverse the characters.
2. Check Palindrome String - Compare characters from start and end.
3. Find First Non-Repeating Character - Use frequency map or array.
4. Count Vowels and Consonants - Iterate and check each character.
5. Check Anagram of Two Strings - Sort both strings or use frequency map.
6. Remove All Duplicate Characters - Use set or frequency array.
7. Longest Common Prefix - Compare characters of all strings.
8. Substring Search (Naive / KMP) - Implement pattern search.
9. Check Rotation of Another String - s2 in s1+s1.
10. Maximum Occurring Character - Use frequency count.
Linked List Questions
1. Reverse a Linked List (Iterative and Recursive) - Use pointer manipulation.
2. Detect Cycle in a Linked List (Floyd's Algorithm) - Use slow and fast pointers.
3. Find Middle Element of Linked List - Use slow and fast pointer approach.
4. Merge Two Sorted Linked Lists - Merge step of merge sort.
5. Remove N-th Node from End - Use two-pointer technique.
6. Delete a Node without Head Pointer - Copy data of next node.
7. Check Palindrome Linked List - Reverse second half and compare.
8. Sort a Linked List (Merge Sort) - Use merge sort on linked list.
9. Rotate Linked List by k places - Change pointers accordingly.
10. Intersection of Two Linked Lists - Use difference of lengths.
Stack Questions
1. Implement Stack using Array - Use array and top pointer.
2. Implement Stack using Linked List - Use linked nodes.
3. Check Balanced Parentheses - Use stack to match brackets.
4. Evaluate Postfix Expression - Use stack to store operands.
5. Convert Infix to Postfix Expression - Use stack and precedence rules.
6. Next Greater Element - Use stack to track elements.
7. Sort a Stack using Recursion - Pop, sort and push back.
8. Get Minimum Element in O(1) - Use auxiliary stack.
9. Largest Rectangle in Histogram - Use stack-based algorithm.
10. Stock Span Problem - Use stack to compute spans.
Queue Questions
1. Implement Queue using Array - Use front and rear indices.
2. Implement Queue using Linked List - Use linked nodes.
3. Implement Circular Queue - Use modulo arithmetic for indices.
4. Implement Deque (Double Ended Queue) - Allow insertion/deletion at both ends.
5. Implement Queue using Two Stacks - Push and pop logic using two stacks.
6. Implement Stack using Two Queues - Use two queues for operations.
7. LRU Cache using Queue - Use queue and hashmap for O(1) operations.
8. Reverse First K elements of Queue - Use stack to reverse first K.
9. Generate Binary Numbers from 1 to N using Queue - BFS like approach.
10. Sliding Window Maximum using Deque - Use deque for max in windows.