0% found this document useful (0 votes)
15 views3 pages

TCS Ninja Interview Questions

The document outlines key interview questions and coding examples for Python and C, including topics such as data types, memory management, pointers, and recursion. It provides sample code for checking prime numbers, reversing lists and strings, and finding the GCD of two numbers. Additionally, it offers preparation tips for candidates to practice programming concepts and familiarize themselves with coding platforms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

TCS Ninja Interview Questions

The document outlines key interview questions and coding examples for Python and C, including topics such as data types, memory management, pointers, and recursion. It provides sample code for checking prime numbers, reversing lists and strings, and finding the GCD of two numbers. Additionally, it offers preparation tips for candidates to practice programming concepts and familiarize themselves with coding platforms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

TCS Ninja Interview Questions: Python and C

1. Python Questions:

- What are Python's key features?

- What are Python's data types?

- How is memory managed in Python?

- Write a Python program to check if a number is prime.

- How do you reverse a list in Python?

- What is the difference between a shallow copy and a deep copy?

- What are *args and **kwargs in Python?

- Explain Python's Global Interpreter Lock (GIL).

- How would you optimize a Python script?

2. Python Coding Examples:

- Prime number check:

def is_prime(n):

if n <= 1:

return False

for i in range(2, int(n**0.5) + 1):

if n % i == 0:

return False

return True

- Reverse a list:

my_list = [1, 2, 3, 4, 5]

reversed_list = my_list[::-1]
print(reversed_list)

3. C Questions:

- What are the key features of C?

- What are the differences between malloc() and calloc()?

- What is a pointer in C?

- Write a program to reverse a string in C.

- Write a program to find the factorial of a number using recursion.

- Explain the difference between struct and union.

4. C Coding Examples:

- Reverse a string in C:

void reverseString(char str[]) {

int n = strlen(str);

for (int i = 0; i < n / 2; i++) {

char temp = str[i];

str[i] = str[n - i - 1];

str[n - i - 1] = temp;

- Find factorial using recursion in C:

int factorial(int n) {

if (n <= 1) return 1;

return n * factorial(n - 1);

}
5. Combined Python and C Problem:

- Write code in Python and C to find the GCD of two numbers.

Python Implementation:

def gcd(a, b):

while b:

a, b = b, a % b

return a

C Implementation:

int gcd(int a, int b) {

while (b != 0) {

int temp = b;

b = a % b;

a = temp;

return a;

Tips for Preparation:

- Practice basic and advanced programming concepts for Python and C.

- Work on coding platforms like HackerRank and LeetCode.

- Understand practical applications of pointers, memory management, and file handling in C.

- Familiarize yourself with Python's built-in libraries and common idioms.

Good luck with your TCS Ninja Interview Preparation!

You might also like