Challenge - 5 Problems
Linked List vs Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateWhen is a linked list better than an array?
Choose the best scenario where using a linked list is more suitable than using an array.
Attempts:
2 left
💡 Hint
Think about which data structure allows easy insertion and deletion without shifting many elements.
✗ Incorrect
Linked lists allow fast insertion and deletion anywhere because they only change pointers, unlike arrays which require shifting elements.
❓ Predict Output
intermediateOutput of array vs linked list insertion time simulation
What is the output of the following C# code simulating insertion times for array and linked list?
DSA C#
using System; using System.Collections.Generic; class Program { static void Main() { int[] array = new int[5] {1, 2, 3, 4, 5}; LinkedList<int> list = new LinkedList<int>(array); // Insert 10 at index 2 in array for (int i = array.Length - 1; i > 2; i--) { array[i] = array[i - 1]; } array[2] = 10; // Insert 10 after second node in linked list var node = list.First.Next; list.AddAfter(node, 10); Console.WriteLine(string.Join(",", array)); foreach (var val in list) Console.Write(val + ","); } }
Attempts:
2 left
💡 Hint
Check how insertion shifts elements in array and how linked list insertion works.
✗ Incorrect
In the array, elements from index 3 to end shift right to make space at index 2. In the linked list, insertion after second node places 10 between 2 and 3.
🔧 Debug
advancedWhy does this linked list traversal code cause an error?
Identify the error in this C# linked list traversal code and what error it causes.
DSA C#
LinkedList<int> list = new LinkedList<int>(new int[] {1, 2, 3}); var node = list.First; while (node != null) { Console.WriteLine(node.Value); node = node.Next.Next; }
Attempts:
2 left
💡 Hint
Think about what happens when node.Next is the last node.
✗ Incorrect
Accessing node.Next.Next without checking if node.Next is null causes NullReferenceException.
🚀 Application
advancedChoosing data structure for a music playlist app
You are designing a music playlist app where users can add, remove, and reorder songs frequently. Which data structure is best and why?
Attempts:
2 left
💡 Hint
Consider which structure handles frequent insertions and deletions well.
✗ Incorrect
Linked lists allow easy insertion and removal anywhere without shifting elements, ideal for reordering playlists.
❓ Predict Output
expertFinal state of linked list after mixed operations
What is the final printed state of the linked list after running this C# code?
DSA C#
using System; using System.Collections.Generic; class Program { static void Main() { LinkedList<int> list = new LinkedList<int>(); list.AddLast(1); list.AddLast(2); list.AddLast(3); var node = list.First.Next; // node with value 2 list.Remove(node); // remove 2 list.AddFirst(0); list.AddLast(4); list.AddAfter(list.First, 5); foreach (var val in list) Console.Write(val + " -> "); Console.Write("null"); } }
Attempts:
2 left
💡 Hint
Track each operation step-by-step on paper.
✗ Incorrect
After removing 2, list is 1->3. Adding 0 at front: 0->1->3. Adding 4 at end: 0->1->3->4. Adding 5 after first (0): 0->5->1->3->4.
