Given a number N , write a program to obtain a number M by reversing the digits of N . If M contains trailing zeros, they must be removed (which happens naturally during integer reversal).

The 2021 coding section was typically part of the or the Programming Logic & Coding rounds. Number of Questions : 2 coding questions. Time Allotted : 45 to 60 minutes in total.

Binary search variations, custom sorting (sorting based on specific criteria), and greedy selection.

def toggle_bits(n): # Find MSB position binary_str = bin(n)[2:] msb_pos = len(binary_str) # Create mask to toggle bits mask = (1 << msb_pos) - 1 # Toggle bits using XOR result = n ^ mask return result # Example: n=10 (1010) -> Toggle -> 0101 (5) print(toggle_bits(10)) Use code with caution. 4. Tips for Preparing for TCS Coding Questions

Modern compilers with strict time limits (usually 1.0 to 2.0 seconds per test case).

def base17_to_decimal(s): try: # Python's built-in int function handles up to base 36 decimal_val = int(s, 17) return decimal_val except ValueError: return "Invalid Input" # Driver Code if __name__ == "__main__": inp = input().strip() print(base17_to_decimal(inp)) Use code with caution. C++ Implementation

What’s good

The TCS coding test is an online assessment that evaluates a candidate's programming skills. The test typically consists of 2-3 questions that need to be solved within a time frame of 60-90 minutes. The questions are based on programming concepts, data structures, and algorithms. The test is designed to assess a candidate's ability to write clean, efficient, and well-documented code.

Input: 13 (1101) → Output: 3. while(n) count++; n = n & (n-1);

1 Star2 Stars3 Stars4 Stars5 Stars
Tcs Coding Questions 2021 Загрузка...
Реклама

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Tcs Coding Questions 2021