Tcs Coding Questions - 2021

arr = list(map(int, input().split())) even_sum = sum(arr[i] for i in range(0, len(arr), 2)) odd_sum = sum(arr[i] for i in range(1, len(arr), 2)) print(abs(even_sum - odd_sum)) Asked in: TCS Digital (Multiple slots – November 2021)

def decimal_to_binary(n): binary = "" if n == 0: binary = "0" while n > 0: binary = str(n % 2) + binary n //= 2 # Count ones count_one = binary.count('1') return binary, count_one num = int(input()) b, c = decimal_to_binary(num) print(b) print(c) Asked in: TCS Digital (April 2021) Tcs Coding Questions 2021

For thousands of engineering graduates in India, 2021 was a defining year for their careers. Tata Consultancy Services (TCS), one of the largest IT employers globally, conducted massive recruitment drives using the TCS National Qualifier Test (NQT) and the TCS Digital (Ninja) exams. If you are looking back at the pattern or preparing for future exams based on past trends, understanding the TCS coding questions from 2021 is arguably the most effective strategy. arr = list(map(int, input()

Problem Statement: A scientist has discovered a new number system where the base is 2. Write a program to convert a given decimal number (N) into its binary equivalent. However, you cannot use the bin() function or inbuilt conversion libraries. Additionally, find the number of '1's in the binary representation (Hamming Weight). Problem Statement: A scientist has discovered a new

Asked in: TCS Ninja (September 2021)

public class Main public static boolean validPalindrome(String s) int left = 0, right = s.length() - 1; while (left < right) if (s.charAt(left) != s.charAt(right)) left++; right--; return true; private static boolean isPalindrome(String s, int left, int right) while (left < right) if (s.charAt(left) != s.charAt(right)) return false; left++; right--; return true;