Remove duplicates from an unsorted Linked List in Ruby
Alternatives

There are other alternatives (spoiler alert) with around the same time complexity, that adhere to the specification of in-place removal.



Review


  This is in \$O(n)\$.


I'm not sure it is. The outer iteration while (node = node.next) is \$O(n)\$.


while (node = node.next)
  h[node.data] += 1
  if h[node.data] &gt; 1
    previous_node = find_previous(node.data)
    previous_node.next = previous_node.next.next
  end
end



And find_previous(data) is \$O(\log{n})\$.


 def find_previous(value)
    node = @head 

    return false if !node.next
    return node if node.next.data == value 

    while(node = node.next)
      return node if node.next.data == value
    end   
 end



This makes remove_duplicates to be \$O(n\log{n})\$. 

If you keep track of the previous node while iterating the nodes, you could optimize your algorithm to be \$O(n)\$, but as you are using a hash table, it fails to meet the requirements of the challenge.