Skip to content

Instantly share code, notes, and snippets.

View charlespunk's full-sized avatar

charlespunk charlespunk

View GitHub Profile
Write code to remove duplicates from an unsorted linked list.
FOLLOW UP
How would you solve this problem if a temporary buffer is not allowed?
Implement an algorithm to find the kth to last element of a singly linked list.
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x.
You have two numbers represented by a linked list, where each node contains a single digit. The digits are stores in reverse order, such
that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.
FOLLOW UP
Suppose the digits are stored in forward order. Repeat the above problem.
_ _ _ I t _ _ _ _ i s _ _ a _ a p p l e _ _ => I t _ i s _ a _ a p p l e
/*
Given three sorted interger arrays, A, B and C, find three indices (i,j,k) such that max(abs(A[i] - B[j]), abs(A[i]-C[k]), abs(B[j]-C[k])) is minimized.
Implement the function to return the minimal value.
Example:
A: [1,2,4,8,16,32]
B: [3,5,9,15,17,40]
C: [6,13,23,36,45]
Given a circular linked list, implement an algorithm which returns the node at the begining of the loop.
Implement a function to check if a linked list is a palindrome.
//reverse singly linked list
public static Node reverseList(Node root){
if(root == null) return null;
return reverseListHelp(root);
}
public static Node reverseListHelp(Node root){
if(root.next == null) return root;
Node end = reverseListHelp(root.next);
root.next.next = root;