fork download
  1. class Node:
  2. def __init__(self, value, next=None):
  3. self.value = value
  4. self.next = next
  5.  
  6. # For testing
  7. def print_linked_list(head):
  8. current = head
  9. while current:
  10. print(current.value, end=" -> " if current.next else "\n")
  11. current = current.next
  12.  
  13. def edit_dna_sequence(dna_strand, m, n):
  14. temph = Node(0,dna_strand)
  15. prev = temph
  16. cur = dna_strand
  17. while (cur):
  18. for i in range(m):
  19. prev = cur
  20. cur = cur.next
  21. if not cur:
  22. return temph.next
  23. for j in range(n):
  24. prev.next = cur.next
  25. cur = cur.next
  26. if not cur:
  27. return temph.next
  28. return temph.next
  29. dna_strand = Node(1, Node(2, Node(3, Node(4, Node(5, Node(6, Node(7, Node(8, Node(9, Node(10, Node(11, Node(12, Node(13)))))))))))))
  30.  
  31. print_linked_list(edit_dna_sequence(dna_strand, 2, 3))
Success #stdin #stdout 0.09s 14176KB
stdin
Standard input is empty
stdout
1 -> 2 -> 6 -> 7 -> 11 -> 12