Tcs Coding Questions 2021 Page
def count_pairs_with_sum(arr, target_sum): count = 0 seen = set()
Given a linked list, find the middle element.
return None
for char in s: if char_count[char] == 1: return char Tcs Coding Questions 2021
class Node: def __init__(self, data): self.data = data self.next = None
print(max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4])) # Output: 6
def max_subarray_sum(arr): max_sum = float('-inf') current_sum = 0 def count_pairs_with_sum(arr, target_sum): count = 0 seen =
print(count_pairs_with_sum([1, 2, 3, 4, 5], 7)) # Output: 2
print(find_middle_element(head)) # Output: 3
Given an array of integers, find the maximum sum of a subarray. current_sum + num) max_sum = max(max_sum
Example: Input - [-2, 1, -3, 4, -1, 2, 1, -5, 4], Output - 6
for num in arr: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum)
Example: Input - "madam", Output - True
return slow.data
Example: Input - 1 -> 2 -> 3 -> 4 -> 5, Output - 3