All Questions
56 questions
1
vote
2
answers
79
views
Alternate linked list merge
I wanted to merge 2 linked list’s elements alternatively. I counted the length of these 2 linked lists manually, then created a dummy-headed node to use for the merge. I am getting the errors "...
0
votes
1
answer
54
views
I'm having a problem with insertion in a singly Linked List on python
So, I was coding a linked list in python using classes and after succesfullly defining and running all of the methods I setted up for the class, I decided to create an "insert" method, where ...
-1
votes
2
answers
2k
views
LeetCode - 2. Add Two Numbers
I'm attempting to address Leetcode problem 2. Add Two Numbers:
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of ...
0
votes
1
answer
126
views
Find kth node from the end
I written below function to find kth node from the end. However, one hidden test case is failing.
Please let me know what is wrong with below code.
def find_kth_from_end(l, k):
slow = l.head
...
1
vote
0
answers
62
views
error with reversing linked lists in Python
I've been trying to write a code that will reverse the linked list and I think I've got the concept of reversing the linked list down but I cannot put it into code.
the ideal outcome should be
4
3
2
1
...
1
vote
2
answers
245
views
Modifying the value in a singly linked list at specified index
I'm trying to implement a method in my linked list called set_value() where the value gets modified at that index. However, my code does not reflect the change whenever the function is called. I'm not ...
0
votes
2
answers
99
views
Why is my code causing a time limit error, Leetcode 24 ( Linked List)
I am working on LeetCode problem 24. Swap Nodes in Pairs
:
Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list'...
0
votes
0
answers
26
views
Issue with code on class nodes in a linked list implementation
I have implemented a linked list using classes in Python. However, I'm facing an issue with the code when it comes to manipulating the nodes. The code doesn't seem to work as expected, specifically in ...
0
votes
1
answer
1k
views
How to solve Linked list found cycle error
The code below is written to solve Rotate List problem in leetcode, but my code is throwing "Found cycle in the ListNode" error.
I can't find which line is creating the cycle, help!
# ...
0
votes
1
answer
860
views
pseudocode to store the elements of a linked list in reverse order
I am working on an algorithm to store the elements of a singly linked list in reverse order inside an array. my tutor suggested the following pseudocode for the problem - everyone in the classroom was ...
0
votes
1
answer
31
views
Two kind of outputs for same code in linkedlist with python
else:
n = self.head
while n.ref is not None:
n = n.ref
n.ref = new_node
** output -> 30 20 10**
if i execute this code o/p is right *
else:
while self....
0
votes
2
answers
125
views
Check if the Linked List is Palindrome or not
When I try to check whether the linked list is palindrome or not, the following code gives me the error. My Approach is:
Step 1:- I am reversing the linked list (temp = reverseLL(head).
Step 2:- ...
-1
votes
1
answer
65
views
Reverse the Linked List using Recursion
I am using recursion to reverse the linked list but not getting the result. Whenever I am using the following code for the input [1,2,3,4,5,6,-1], it shows me the result [1->None]. I am not getting ...
0
votes
0
answers
20
views
Linked List how to know if two identical nodes are different, i.e. different nodes saved in different parts of memory or a reference to the same node [duplicate]
Ive recently started learning about linked lists and I have a confusion. For the implementation, Im going forward with the Linked list and node implementation used in [linked list problems in leetcode]...
0
votes
2
answers
3k
views
TypeError: __init__() missing 1 required positional argument: 'head' my compiler is giving error at line 51
I am trying to learn linked list in ppython. This is a really simple code. All I am trying to do here is to call a class's constructor. But it is giving me an error. It is saying:
#This is the code I ...