
Problem
Solution
Submissions
Linked List with Basic Operations
Certification: Intermediate Level
Accuracy: 0%
Submissions: 0
Points: 10
Write a JavaScript program to implement a singly linked list with basic operations including insertion, deletion, search, and display. The linked list should support operations like adding elements at the beginning, end, or at a specific position, and removing elements by value or position.
Example 1
- Input: Insert 10, 20, 30 at end, then delete 20
- Output: Initial: 10 -> 20 -> 30 -> null, After deletion: 10 -> 30 -> null
- Explanation:
- Create empty linked list.
- Insert 10 at end: 10 -> null.
- Insert 20 at end: 10 -> 20 -> null.
- Insert 30 at end: 10 -> 20 -> 30 -> null.
- Delete 20: 10 -> 30 -> null.
- Create empty linked list.
Example 2
- Input: Insert 5 at beginning, insert 15 at position 1, search for 15
- Output: List: 5 -> 15 -> null, Search result: Found at position 1
- Explanation:
- Create empty linked list.
- Insert 5 at beginning: 5 -> null.
- Insert 15 at position 1: 5 -> 15 -> null.
- Search for 15 returns position 1 (0-indexed).
- Display final list structure.
- Create empty linked list.
Constraints
- 1 ≤ number of operations ≤ 100
- -1000 ≤ node values ≤ 1000
- Support insertion at beginning, end, and specific position
- Support deletion by value and by position
- Time Complexity: O(n) for most operations
- Space Complexity: O(1) for operations, O(n) for storage
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Create a Node class with data and next pointer
- Implement LinkedList class with head pointer
- Handle edge cases like empty list and single node operations
- Use traversal for search and position-based operations
- Update pointers carefully during insertion and deletion
- Implement helper methods for common operations