Tcs Coding Questions 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)
for(int i = 0; i < n; i++) // For largest if(arr[i] > first_large) second_large = first_large; first_large = arr[i]; else if(arr[i] > second_large && arr[i] != first_large) second_large = arr[i]; // For smallest if(arr[i] < first_small) second_small = first_small; first_small = arr[i]; else if(arr[i] < second_small && arr[i] != first_small) second_small = arr[i]; Tcs Coding Questions 2021
cout << "Second Largest: " << second_large << endl; cout << "Second Smallest: " << second_small << endl; return 0; Asked in: TCS NQT Advanced (July 2021) def decimal_to_binary(n): binary = "" if n ==
Constraints: Time Complexity O(N), Space Complexity O(1). count_one num = int(input()) b