Created
December 3, 2021 08:13
-
-
Save RaminMammadzada/fa83ae30ca348fadbd1bf5f47f2495ac to your computer and use it in GitHub Desktop.
CodeSignal-removeKFromList
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note: Try to solve this task in O(n) time using O(1) additional space, where n is the number of elements in the list, since this is what you'll be asked to do during an interview. | |
Given a singly linked list of integers l and an integer k, remove all elements from list l that have a value equal to k. | |
Example | |
For l = [3, 1, 2, 3, 4, 5] and k = 3, the output should be | |
solution(l, k) = [1, 2, 4, 5]; | |
For l = [1, 2, 3, 4, 5, 6, 7] and k = 10, the output should be | |
solution(l, k) = [1, 2, 3, 4, 5, 6, 7]. | |
Input/Output | |
[execution time limit] 4 seconds (py3) | |
[input] linkedlist.integer l | |
A singly linked list of integers. | |
Guaranteed constraints: | |
0 ≤ list size ≤ 105, | |
-1000 ≤ element value ≤ 1000. | |
[input] integer k | |
An integer. | |
Guaranteed constraints: | |
-1000 ≤ k ≤ 1000. | |
[output] linkedlist.integer | |
Return l with all the values equal to k removed. | |
[Python 3] Syntax Tips | |
# Prints help message to the console | |
# Returns a string | |
def helloWorld(name): | |
print("This prints to the console when you Run Tests") | |
return "Hello, " + name |
Author
RaminMammadzada
commented
Dec 3, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment