TGViewer
Coding Interview Resources Coding Interview Resources @crackingthecodinginterview · 52.2K subscribers
Post #2690 2.87K
✅ Coding Interview Questions with Answers [Part-2] 💻🚀

11. What is a sliding window algorithm?
A technique for solving problems involving arrays or strings by maintaining a window that slides over data. It helps reduce time complexity by avoiding nested loops.
Example: Finding the max sum of subarrays of size k.

12. Detect cycle in a linked list.
Use Floyd's Cycle Detection Algorithm (Tortoise and Hare).
⦁ Move two pointers at different speeds.
⦁ If they meet, a cycle exists.
⦁ To find the cycle start, reset one pointer to head and move both one step until they meet again.

13. Find the intersection of two arrays.
Use a HashSet to store elements of the first array, then check each element in the second array.
⦁ Time: O(n + m)
⦁ Space: O(min(n, m))

14. Reverse a string or linked list.
⦁ For a string: Use two-pointer swap or Python's slicing.
⦁ For a linked list: Use three pointers (prev, curr, next) and iterate while reversing links.

15. Check if a string is a palindrome.
Use two pointers from start and end, compare characters.
Return false if mismatch, true if all characters match.

16. What are the different sorting algorithms?
⦁ Bubble Sort
⦁ Selection Sort
⦁ Insertion Sort
⦁ Merge Sort
⦁ Quick Sort
⦁ Heap Sort
⦁ Radix Sort
Each has different time and space complexities.

17. Explain quicksort vs. mergesort.
⦁ Quicksort: Divide and conquer, picks a pivot.
⦁ Average: O(n log n), Worst: O(n²), Space: O(log n)
⦁ Mergesort: Always divides array into halves, then merges.
⦁ Time: O(n log n), Space: O(n), Stable sort

18. What is a binary search tree (BST)?
A tree where left child < node < right child.
⦁ Efficient for searching, insertion, deletion: O(log n) if balanced.
⦁ Unbalanced BST can degrade to O(n)

19. Inorder, Preorder, Postorder traversals.
⦁ Inorder (LNR): Sorted order in BST
⦁ Preorder (NLR): Used to copy or serialize tree
⦁ Postorder (LRN): Used to delete tree

20. Implement LRU Cache.
Use a combination of HashMap + Doubly Linked List.
⦁ HashMap stores key-node pairs.
⦁ Linked list maintains access order.
⦁ When cache is full, remove the least recently used node.
Operations (get, put): O(1) time.

💬 Double Tap ♥️ For Part-3!
  • ❤ 6
More from @crackingthecodinginterview
  1. Oct 9, 2026🔥 SQL Interview Case Studies (Advanced Business Scenarios) 💯 🧠 Case Study 1: Find Repea…
  2. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
  3. Oct 8, 2026🎓 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘄𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲𝘀! 🚀🔥 Upgr…
  4. Oct 7, 2026🚀 DSA Topics Every Programmer Should Know 💻🔥 📦 1. Arrays ✔ Traversal ✔ Searching ✔ Sor…
  5. Oct 7, 2026🚀𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 | 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰…
  6. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →