Factacy - Ai Assignment
Factacy - Ai Assignment
Email: [email protected]
___________________________________________________________________________________
#code_in_python3
def longest_substring_length(s):
if not s:
return 0
max_length = 0
start = 0
char_index = {}
start = char_index[char] + 1
else:
char_index[char] = i
return max_length
# Example
s = "iamtushar"
class ListNode:
self.val = val
self.next = next
dummy = ListNode(0)
dummy.next = head
first = dummy
second = dummy
first = first.next
first = first.next
second = second.next
second.next = second.next.next
return dummy.next
head.next = ListNode(2)
head.next.next = ListNode(3)
head.next.next.next = ListNode(4)
head.next.next.next.next = ListNode(5)
result_head = removeNthFromEnd(head, n)
result_head = result_head.next
3. 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's nodes.
class ListNode:
self.val = val
self.next = next
def swapPairs(head):
dummy = ListNode(0)
dummy.next = head
prev_node = dummy
second_node = prev_node.next.next
# Swapping
prev_node.next = second_node
first_node.next = second_node.next
second_node.next = first_node
prev_node = first_node
return dummy.next
# Example
head = ListNode(1)
head.next = ListNode(2)
head.next.next = ListNode(3)
head.next.next.next = ListNode(4)
head.next.next.next.next = ListNode(5)
result_head = swapPairs(head)
result_head = result_head.next