1️⃣ Which data structure is best suited for implementing a browser’s forward and back buttons?

  • 🅰️ Stack
  • 🅱️ Queue
  • 🅾️ Linked List
  • 🔄 HashMap

Correct Answer: Stack

2️⃣ How would you efficiently find the first non-repeating character in a string?

  • 🅰️ Using a HashMap to count frequencies.
  • 🅱️ Sorting the string first.
  • 🅾️ Iterating through the string twice.
  • 🔄 Using a Queue for character traversal.

Correct Answer: 🅰️ Using a HashMap to count frequencies.

3️⃣ Which sorting algorithm is best for nearly sorted arrays?

  • 🅰️ Quick Sort
  • 🅱️ Merge Sort
  • 🅾️ Insertion Sort
  • 🔄 Heap Sort

Correct Answer: 🅾️ Insertion Sort

4️⃣ What is the time complexity of finding an element in a Binary Search Tree (BST) in the average case?

  • 🅰️ O(1)
  • 🅱️ O(log n)
  • 🅾️ O(n)
  • 🔄 O(n log n)

Correct Answer: 🅱️ O(log n)

5️⃣ What problem-solving technique is primarily used in the “Knapsack Problem”?

  • 🅰️ Greedy Algorithm
  • 🅱️ Divide and Conquer
  • 🅾️ Dynamic Programming
  • 🔄 Backtracking

Correct Answer: 🅾️ Dynamic Programming

6️⃣ How do you detect a cycle in a Linked List?

  • 🅰️ Using two pointers (slow and fast).
  • 🅱️ Using a HashSet to store visited nodes.
  • 🅾️ Iterating through the list multiple times.
  • 🔄 Both 🅰️ and 🅱️.

Correct Answer: 🔄 Both 🅰️ and 🅱️.

7️⃣ Which of these algorithms does NOT work in O(n log n) time complexity?

  • 🅰️ Merge Sort
  • 🅱️ Heap Sort
  • 🅾️ Quick Sort
  • 🔄 Bubble Sort

Correct Answer: 🔄 Bubble Sort

8️⃣ What is the key advantage of a Trie (Prefix Tree) over a HashMap for storing strings?

  • 🅰️ Faster search for exact strings.
  • 🅱️ Space efficiency for long strings.
  • 🅾️ Fast prefix-based searches.
  • 🔄 Easier to implement.

Correct Answer: 🅾️ Fast prefix-based searches.

9️⃣ What is the Big-O complexity of adding an element to a HashMap in the best case?

  • 🅰️ O(1)
  • 🅱️ O(log n)
  • 🅾️ O(n)
  • 🔄 O(n log n)

Correct Answer: 🅰️ O(1)

🔟 Bonus Question: What is the output of the following code snippet?

int[] nums = {1, 2, 3, 4};
System.out.println(nums[nums.length]);
  • 🅰️ 4
  • 🅱️ 0
  • 🅾️ ArrayIndexOutOfBoundsException
  • 🔄 None of the above

Correct Answer: 🅾️ ArrayIndexOutOfBoundsException

These questions are a mix of theoretical and practical coding challenges, ideal for engaging your YouTube audience. Let me know if you’d like to expand on any of these or customize further!

--

--

AKCoding.com
AKCoding.com

Written by AKCoding.com

Empowering developers with programming concepts and code

No responses yet