Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Before you go!

Take this "TCS Ninja Interview Questions" interview guide with you

Welcome to Interviewbit, help us create the best experience for you!

Currently, You are a:

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your career...

Current Company *
Enter company name *
Experience *

You're all set!

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

TCS Ninja Interview Questions

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

About TCS Ninja

TCS selects applicants for a variety of jobs by conducting the NQT (National Qualifier Test). About 10,000-15,000 job applicants submit 350,000 applications for the TCS NQT test, which provides work to tens of thousands of people. Hence, it's critical to be familiar with the test in order to land a position with TCS.

The TCS Ninja program is excellent for young IT professionals seeking rapid growth. Once you've demonstrated your ability to become a TCS Ninja, you may be switched to the Digital Capacity Assessment (DCA) program. This would be a wonderful opportunity for your career development.

It can be tough to prepare for your first job interview, especially when you've never been through this before. So you will find here the TCS ninja hiring process to the most frequently asked interview questions and tips to crack this interview.

TCS Ninja Recruitment Process

1. Interview Process

TCS Ninja Hiring Process involves two rounds for the freshers.

  • Written Test
  • Interviews

Written Test: 

There are two sections to the TCS Ninja Recruitment written test: cognitive skills and programming. It has a total duration of 180 minutes and includes 92 questions. There are no sectional cutoffs or negative markings, but there are sectional time limits for the test. The test pattern for the TCS Ninja written test is provided below.

Part Skill Group Number of Questions you can expect Time Duration
A Cognitive Skill Numerical Ability 26 40 Mins
A Cognitive Skill Verbal Ability 24 30 Mins
A Cognitive Skill Reasoning Ability 30 50 Mins
B Programming Skill Programming Logic 10 15 Mins
B Programming Skill Hands-on-coding 2 45 Mins

Type of Questions:

  • MCQ: Multiple choice question, there will be four options and you have to choose one of them.
  • Box type: These are fill-in-the-blank type questions you have to write in the blank spaces.

Cognitive Skill

Numerical Ability: In the Aptitude Section of TCS NQT, there are 26 questions and 40 minutes are allotted to solve them. Even so, you will have to be a little quick while solving them since the difficulty level of the Aptitude Section of TCS NQT is considered to be quite high. 

Topics of Numerical Ability:

  • Arithmetic Ability
  • Mensuration
  • Number System
  • Data interpretation
  • Elementry Statistics
  • Simplifications & Approximations

Verbal Ability: There are 24 questions on the TCS NQT English test, and the duration is 30 minutes. The English questions are a little bit easy for people who are proficient in the language. However, the test is highly competitive in general.

Topics of Verbal Ability:

  • Sentence Completion
  • Word Arrangement
  • Error Identification
  • Word Completion
  • Reading Comprehension

Reasoning Ability: In this section of TCS NQT, there are 30 questions, and 50 minutes are allotted to solve them. Even though the difficulty level of the TCS NQT Logical Section is considered to be high, the average time per question is still less than two minutes.

Topics of Reasoning Ability:

  • Decision Making
  • Number Series
  • Cube folding, paper folds, and cuts
  • Visual Reasoning
  • Statement and conclusion
  • Seating arrangements
  • Blood relations
  • Direction based

2. Interview Rounds

When you qualify for the NQT test, you have to go through two rounds of interviews:

Round 1: Technical Round. You will be tested on your programming knowledge if you come from an IT background. You may be asked about Computer Networks, Database Management Systems, Software Management, Operation systems, and Cloud Computing. If you are from Non-CS background you should have basic knowledge about programming. The duration of this round will be between 20 - 30 minutes

Round 2: HR Round(Optional). During this round, the questions are asked  onset situations for testing management skills. It is also to check if candidates are a good fit for their open positions as it often requires managerial and client-facing skills. During this round, you will be asked questions about your hobbies, preferences, and dislikes, as well as questions about popular topics. However, in some instances, HR asked you to answer puzzle-based questions during in-person interviews. The duration of this round will be between 15- 20 minutes.

HR Interview Questions

This round is typically used to evaluate both your interpersonal and communication skills. Typically, the interviewer begins by asking you about your introduction, family history, education, and college. The interviewer can then go on to more challenging questions that require accurate responses.

1. Tell us about yourself

In 70-90% of HR interviews, this is one of the openings and most common questions. Although the question appears to be quite straightforward, your response will have a significant impact on how the interviewer views you.

  • begin with a short self-introduction ( your name, where are you from, your educational background, and a little about your family background).
  • Then, discuss your hobbies and abilities. Include one of your most significant accomplishments as well (if it fits the circumstance).

2. What motivates you to Work with TCS?

One of the most significant questions is this one. No need to justify your desire for the position. However, you must state why you are interested in the position in a certain field or role. Inform the interviewer of the job description that best suits your skills and the values the company upholds, as well as how that fits you.

3. Why Should We Hire You?

The last query is this one. The interviewer will ask you why you should be recruited after summarising your responses to the earlier inquiries. You should take advantage of this question to discuss your qualifications in a way that highlights your personality and demonstrates why you are the ideal candidate for the position. You'll go into trouble if you answer this question incorrectly. Long verbose responses are not worth the attention of the employer. You just have a few milliseconds or seconds to make an impression. Employers don't need to know how fantastic you are. Why are you the best candidate for the position, they want to know. Employers would like to hire you much more if you can provide a compelling justification for why you ought to be recruited.

4. What do you anticipate from the company?

Even if this response is general and may vary depending on the respondent, keep your attitude positive and avoid mentioning the company too much for fear of giving the interviewer the impression that you have been exaggerating.

5. What are your strong and weak points?

The trickiest aspect of answering this question is finding a way to honestly describe both your strengths and faults without coming off as egotistical. Based on the position you have applied for, you should carefully consider your response to this question. 

  • Strength: If someone asks you what your biggest strength is, you may either respond right away with something specific or go into more detail by describing how you've excelled in a certain setting. When the interviewer inquires about your strengths, seize the opportunity to impress.
  • Weakness: During an interview, a potential employer could inquire about your flaws to determine whether you have the drive to use them as a springboard for professional advancement.

6. Are you comfortable relocating?

Don't try to be good in your response; instead, be direct and tell them specifically if you are unable to move locations. If they have any openings for that kind of work, they will take your application into consideration.

7. What are your hobbies?

The majority of candidates find it easy to list their education and skill backgrounds. The work becomes overwhelming when one has to discuss their hobbies or interests in writing. Identifying the abilities or attributes you acquired from your extracurricular activities will help you choose the ones that are most applicable. Make a list of your interests and hobbies, and then list all the skills and qualities you acquired or developed as a result of each activity.

Example: Team sports(Cricket, volleyball, football, tennis), Reading, Writing, public speaking, dancing, etc.

8. In five years, where do you see yourself?

Employers typically use this question to learn more about your long-term objectives and how they relate to the job you're looking for. Even if you are unsure of your specific career goals for the next several years, being prepared to respond to this question will help you succeed and contribute to a successful interview overall. Spend some time considering what you want from your job in the following five years. Do you desire to develop new skills? Are you considering a career in management in the future? Are there any industries that particularly appeal to you to work in? 

Look at the job description and see if you can identify any attributes and skills you already have as well as those you wish to gain more experience in to help connect your goals with the position you're applying for. This will enable you to discuss your objectives in relation to the job you're seeking during the interview.

TCS Ninja Technical Interview Questions: Freshers and Experienced

1. Explain ACID properties in DBMS?

 In order for a database to maintain its integrity, all transactions must adhere to the ACID standard. The ACID acronym refers to atomicity, consistency, isolation, and durability, so let's discuss each of them in turn.

  • Atomicity: An atomic transaction data remains unchanged even after an operation is executed. This means that if an operation is undertaken on the data, either the operation must be completed or it must not be executed at all. A transaction operation should not be split between different parts or executed in stages. It must be completed entirely and not partially.
  • Consistency: The consistency property defines the level of how the data should be kept unchanged. By keeping the data consistent, the DBMS is not allowing any inconsistency in the data. An example of a level of consistency would be when one table contains the data on which the operation is performed while another table should contain the data before performing the operation.
  • Isolation: When the transactions are running concurrently, the outcome should be the same as if the transactions were running serially; that is, the result should be the same as if there were no transactions at all.
  • Durability: The data after an operation is successfully executed is permanent in a DBMS. To ensure the durability of data, the term durability is used. Even if the system fails or crashes, the database may survive. However, if it is lost, the responsibility of the recovery manager is to ensure its durability. Whenever we make changes to values, the COMMIT command must be used.

2. What is the DDL command in MySql explain Create and Alter command?

The Data Definition Language is a set of SQL commands designed to structure databases. It handles database schema descriptions and constructs and modifies database objects' structures in databases. In addition to data, DDL refers to a set of SQL instructions for creating, modifying, and deleting database structures. It does not handle data. Database structures are created, modified, and deleted using DDL commands. All DDL commands are auto-committed, saving all database changes permanently. DDL commands that construct the database structure include:

  • CREATE: A database or one of its objects is created using this command (like tables, indexes, functions, views, stored procedures, and triggers). You can issue two kinds of SQL statements: one that creates a database and another that creates a table.

Syntax:

To create Database: CREATE DATABASE db_name;

Example: CREATE DATABASE store;

To create Table: 

CREATE TABLE table_name(
Column_name1 data_type(size),
Column_name2 data_type(size),
Column_name3 data_type(size),
…..
);

Example: 

CREATE TABLE product(
Id int(10),
Name varchar(100),
Price varchar(10)
);
  • ALTER: The ALTER command in SQL lets us add, delete, and modify items in a table, view, or the whole database. We can also modify, add, and delete constraints, columns, and indexes using the ALTER command.
    • Command to add new Column: 
      • Syntax: ALTER TABLE table_name ADD column_name column-definition;
      • Example: ALTER TABLE product ADD category varchar(50);
    • Command to modify a Column: 
      • Syntax: ALTER TABLE table_name MODIFY (column-definition);
      • Example: ALTER TABLE product MODIFY (category varchar2(100));

3. What is the Drop and Truncate command in SQL?

  • DROP: You may drop a whole database or a table by using the DROP statement. Existing objects such as databases, tables, indexes, and views are destroyed with the DROP command.
    • Syntax: To drop a table: DROP TABLE table_name;
    • To drop a database: DROP DATABASE db_name;
    • Example:  To drop a table: DROP TABLE product;
    • To drop a database: DROP DATABASE store;
  • TRUNCATE: Used to indicate the table’s extents for deallocation (empty for reuse). This method is quicker than the usual integrity checking procedures to remove all data from a table. This procedure was introduced in the SQL:2008 standard for the first time. It is somewhat equivalent to the delete command.
    • Syntax: TRUNCATE TABLE  table_name;
    • Example: TRUNCATE TABLE product;

4. What is the JIT compiler in java?

The Just-In-Time compiler is a critical component of the Java Runtime Environment. It is primarily responsible for optimizing the efficiency of Java-based programs during runtime or execution. Bytecode is a key element of Java that allows for cross-platform execution. The Java Development Kit (JDK) includes the Java compiler (javac), which is used to compile Java source code into bytecode (.class file). The JVM then loads the .class file at runtime and converts the bytecode to binary code (machine code). The interpreter also makes use of machine code. The JIT compiler improves the performance of Java programs by translating bytecode at run time into native machine code.

5. What is the OOPs concept?

OOPs, or object-oriented programming is based on the idea of creating objects, using them repeatedly throughout the program, and then manipulating them to obtain the desired outcome.

Four basic principles of OOPS are

  • Abstraction.
  • Inheritance.
  • Polymorphism.
  • Encapsulation.

6. What is Abstraction in OOPS?

Abstraction basically means hiding the background details of a program and showing only the necessary details. Abstract classes and interfaces can be used to accomplish abstraction.To make a class abstract, we simply use the abstract keyword.

7. What are inheritance and its types in Java?

The process of inheriting features of an existing class into a new class is referred to as inheritance. There are two kinds of classes in inheritance. the class which inherits the properties of a class is called a child class, and the class from which we are inheriting is called the Base or Parent class. Extends is the keyword used for Inheritance.

Example: A Cylinder class can have properties of a Circle class and it also can have extra features.

class Circle {
 float radius;
 function area(){
  return 3.14*radius*radius;
 }
}
class Cylinder extends Circle{

 float height;
 function volume(){
  return 3.14*radius*radius*height;
 }
}

There are Three types of Inheritance in Java:

  • Single Inheritance: When a class is derived from another class, this is known as single inheritance.
  • Multilevel Inheritance: When a class is derived from a class which is also derived from another class, it is known as multi-level inheritance.
  • Hierarchical Inheritance: When a class has more than one parent class then it is called hierarchical inheritance.

8. What is Method Overloading?

Method overloading is a technique that is used to achieve the polymorphism. When a class has multiple methods with the same name but with different parameters or signatures then it is called method overloading.

Example: 

class Example {
 function sum(int num1, int num2){
  return num1+num2;
 }
 function sum(int num1, int num2, int num3){
  return num1+num2+num3;
 }
 function sum(float num1, float num2){
  return num1+num2;
 }
}

9. Explain Insertion sort?

Insertion Sort is a comparison-based sorting algorithm. In each iteration of insertion sort, it picks one element from the unsorted side and finds the current place for it on the sorted side of the list. It works similarly to card sorting.

It is adaptive in nature.

// Insertion sort code in Java
// This sorting algorithm will sort the array in ascending order
import java.util.Arrays;
class InsertionSort {
 void sort(int arr[]) {
   int sizeOfArray = arr.length;
   for (int i= 1; i< sizeOfArray ; i++) {
     int key = arr[i];
     int j = i- 1;
     while (j >= 0 && temp < arr[j]) {
       arr[j + 1] = arr[j];
       --j;
     }
     arr[j + 1] = temp;
   }
 }
 // Driver code
 public static void main(String args[]) {
   int[] unSortedArray = { 12, 10, 31, 4, 13 };
   InsertionSort s = new InsertionSort();
   s.sort(unSortedArray);
   System.out.println("Sorted Array: ");
   System.out.println(Arrays.toString(unSortedArray));
 }
}

Time Complexity:

  • The worst case of insertion sort will be when the given list is in descending order and the time complexity will be O(n^2).
  • The average case time complexity of the insertion sort will also be O(n^2).
  • The best case of Insertion Sort will be when the list is sorted in Ascending order and the time complexity will be O(n).

Space Complexity: Space complexity will be O(1).

10. What is a linked list explain with an example?

A linked list is a linear data structure. Unlike a conventional sequential data structure, a linked list maintains its elements at non-contiguous memory locations. A linked list is composed of nodes interconnected by pointers. A node in the Linked List consists of two parts: data and a pointer. The pointer points to the next node in the list.

The head always points to the first node of the linked list, and the last node will always point to null.

Example: music or video player, next and previous buttons in the browser.

Types of Linked List:

  • Singly Linked List.
  • Doubly Linked List.
  • Circular Linked List.

11. What is an operating system?

An OS acts as the bridge between a computer's users and its hardware. The goal of an OS is to offer a setting where a user may conveniently and effectively run a program. The distribution of services and resources, including memory, processors, hardware, and data, maybe a responsibility of an operating system. Programs sort of a traffic controller, a scheduler, a memory management module, I/O programs, and a filing system are among the operating system's programs that are responsible for managing these resources.

12. What is a firewall? How does it work?

A firewall is a network protection system that regulates internet traffic coming into, leaving, and inside a private network. Firewalls may be thought of as controlled borders or portals that control the flow of authorized and restricted web traffic in a private network. The phrase derives from the notion of physical walls acting as barriers to impede the spread of fire until emergency personnel can extinguish it. Similarly, network security firewalls are used for online traffic control, often to slow the spread of web dangers.

How a firewall works:

Based on a set of pre-established rules, a firewall system examines network traffic. Following that, it filters the traffic to stop any of that traffic from originating from untrustworthy or unreliable sources. Only inbound traffic that is set to accept is permitted.

13. What is the stack data structure and its operations?

The Last In First Out (LIFO) concept is used by stacks, which are dynamic data structures. The first thing to be removed from a stack is the last thing that was added to it. The addition and removal of items are limited in stacks. Only one end of the stack, i.e., the top, can have items added or removed. The top item is the one at the very top. Push() and pop() are the names of the operations that add and remove items, respectively.

Some common operations used on stacks include the following:

  • push(): Push operation is used to insert an item at the top of the stack.
  • pop(): Pop operation is used to remove the element from the top of the stack.
  • isEmpty(): This method is used to know if the stack is empty or not.
  • isFull(): This method is used to know if the stack is full or not.
  • peek(): This method returns the element at any given index in the stack.

14. What is a constructor in java?

A class's member function with the same name as the class is the constructor.

The initialization of objects belonging to a class is done by a particular kind of member function called a constructor. When an object (a class instance) is formed, the constructor is automatically invoked.

A constructor does not have a return type.

Virtual constructors are not a thing; only member functions can be virtual.

Types of Constructors in Java:

  • No-argument Constructor: A constructor with no parameter is called a no-argument or default constructor. If a constructor is not defined in a class then the compiler automatically creates a default constructor.
    • Example:
Class Interviewbit {
Int num1, num2;
    Interviewbit(){
    num1 = 20;
    num2 = 30;
    {
}
Interviewbit ib =new Interviewbit();
  • Parameterized Constructor: Parameterized constructors are constructors that take parameters. Use a parameterized constructor if you wish to initialize class fields with your values.
    • Example:
Class Interviewbit {
Int num1, num2;
    Interviewbit(int num1, int num2){
    this.num1 = num1;
    this.num2 = num2;
    {
}
Interviewbit ib =new Interviewbit();

15. Explain the TCP/IP model?

TCP/IP stands for Transmission Control Protocol/Internet Protocol. It assists us in figuring out the best way to connect a particular computer to the internet and the best way to transfer data between them. When several computer networks are linked together, we can more easily establish a virtual network. To enable communication across large distances, the TCP/IP protocol was created.

It is a connection-oriented protocol.

Layers in the TCP/IP model: There are four layers in the TCP model:

  • Application Layer: It manages the standards for user interfaces and is responsible for node-to-node communication.
  • Transport Layer: It is in charge of ensuring a seamless end-to-end connection and error-free data transfer.
  • Internet Layer: It specifies the protocols that control the logical transmission of data throughout the whole network.
  • Network Access Layer: The protocols available in this layer enable the physical transport of data while keeping an eye out for hardware addressing.

16. What is cloud computing?

The term "cloud computing" refers to the storage and access of data and computing services via the internet. It does not save any information on your computer. It refers to the on-demand availability of computer services such as servers, data storage, networking, and databases. The primary goal of cloud computing is to provide numerous users with access to data centers. Users can also gain access to data stored on a distant server.

Cloud computing reduces the user's hardware and software requirements. The only program that the user needs to be able to operate is the cloud computing platforms interface software, which can be as simple as a Web browser, and the Cloud network handles the rest. We have all encountered cloud computing at some point in our lives; some of the major cloud services we have used or continue to use include mail services such as Gmail, Hotmail, and yahoo, among others.

Example: AWS, Azure, Google.

17. What is Machine Learning?

Machine Learning is a collection of computer algorithms that can learn from examples and improve themselves without being explicitly programmed by a person. Machine learning is an artificial intelligence component that integrates data with statistical methods to predict an output that can be utilized to produce actionable insights. A common machine learning challenge is to make a recommendation. For individuals who have a Netflix account, all movie or series recommendations are based on the user's past data. Unsupervised learning is being used by tech companies to improve the customer experience by personalizing recommendations.

Machine learning is also utilized for tasks such as fraud detection, predictive maintenance, portfolio optimization, task automation, and so on.

TCS Ninja Coding Questions

18. Write a Program to print the Half Pyramid Number Pattern?

Pattern: 

1
22
333
4444
55555

Code:

class PyramidPattern{
   public static void main(String[] args) {
       //to control how many rows we have to print
       int noOfRows=5;
       for(int num=1;num<=noOfRows;++num){
           for(int j=1;j<=num;++j){
               System.out.print(num);
           }
           System.out.println();
       }
   }
}

We have used nested loops to print the pattern. The outer loop is used to control the no of rows we want to print and what number will be printed on each row. An inner loop is used to control the number of types that number will be printed. 

  • Time Complexity: O(n^2)
  • Space Complexity: O(1)

19. Write a program to print the left triangle start pattern?

          * 
        * * 
      * * * 
    * * * * 
  * * * * *

Code:

public class LeftTrianglePattern
{
public static void main(String[] args) {
 int i=0,noOfRows=5,j;
       for(; i<noOfRows; i++)
       { 
           //Inner loop1
           for(j=2*(noOfRows-i); j>=0; j--)
           {           
               System.out.print(" ");
           } 
           //Inner loop2
           for(j=0; j<=i; j++)
           {       
               System.out.print("* ");
           }           
           System.out.println();
       } 
}
}

An outer loop will run to control the number of rows to print. Inner loop1 will control the number of spaces before the pattern in each row. Inner loop2 will print the * in each row after the space.

  • Time Complexity: O(n^2)
  • Space Complexity: O(1)

20. Write a program to check if a number is prime or not?

A number is said to be the prime number if it is divisible by itself or 1. If the number is divisible by any other number then it is not a prime number.

Code:

public class Main {
   static boolean primeNumberChecker(int number){
       int i = 2;
       boolean flag = false;
       while (i <= number / 2) {
         //Check if number is divisible by i
         if (number % i == 0) {
           //set flag to true and breakout of the loop
           flag = true;
           break;
         }
         i++;
       }
       if (!flag)
         return true;
       else
        return false;
   }
 public static void main(String[] args) {
   int numberToCheck = 11;
   //Call the function and store the result
   boolean result = primeNumberChecker(numberToCheck);
   //Check if result is true then number is prime
   if (result)
     System.out.println(numberToCheck + " is a prime number.");
   else
     System.out.println(numberToCheck + " is not a prime number.");
 }
}

Take a boolean variable as and set it to by default false.

Start the loop from 2 because a number is always divisible by 1.

Now check if the number is divisible by any other number.

If the number is divisible by the other number then set the flag variable as true and break the loop.

Now check if a flag is true means the number is not a prime number.

  • Time Complexity: Loop is running only half times of number so the time complexity would be O(n).
  • Space Complexity: O(1)

21. Write a recursive function to print the factorial of a number?

The definition of a factor of a number n is the multiplication of all positive descending integers; the factor of n is represented by the symbol n!.

Code:

public class Factorial{
   static long factorial(int number){
      //Base condition when recursive call will stop
       if(number==0 || number == 1)
           return 1;
       return number * factorial(number-1);
   }
 public static void main(String[] args) {
   //Number to calculate factorial
   int number = 10;
  System.out.println(factorial(number));
 }
}
  • Time Complexity: Time complexity would be O(n).
  • Space Complexity: In each recursive call, it uses stack internally so space complexity would be O(n).

22. Write a program to check if there exist a duplicate key in the array?

import java.util.*;
class Duplicate {
   public static boolean checkDuplicate(int[] arr) {
       // create a hashmap to store the occurrence of the number
       Map<Integer,Integer> container = new HashMap<>();
      //Loop through the array
       for(int i=0;i<arr.length;i++){
           //Check if number already exist in the hashmap
           if(container.containsKey(arr[i])){
               return true;
           }
           else
               container.put(arr[i],1);
       }
       return false;
   }
   public static void main(String[] args){
       //Input array
       int []arr = {10,20,30,40,10};
       System.out.println(checkDuplicate(arr));
   }
}

Output:

true

To solve this problem we will use the HashMap. First, we will check if the key exists in the map or not if it exists means there is a duplicate key in the array. If the key does not exist in the array then we will put the key in the array with value 1. Keep doing this till the last element of the array.

If key exists return false otherwise return true.

  • Time Complexity: Time complexity would be O(n).
  • Space Complexity: We are using additional space to keep a count of the occurrence of each number so space complexity would be O(n).

23. Write a program to calculate the sum of diagonal of a matrix?

Include only the total of the primary diagonal elements and the secondary diagonal elements that are not a part of the primary diagonal.

class Solution {
   public static int diagonalSum(int[][] matrix) {
       int row=0,col,leftSum=0,rightSum=0,n=matrix.length;
       col=n-1;
       while(row<n){
          //Calculate sum of left diagonal
           leftSum += matrix[i][i];
           //Check if row and column are not same 
           if(row!=col)
               //Calculate the sum of right diagonal
               rightSum += matrix[i][j];
               //update row and col
           row++;
           col--;
       }
       return (leftSum + rightSum);
   }
   public static void main(String []args){
       //Input matrix
       int [][]matrix = {{10,20,30},
                     {40,50,60},
                     {70,80,90}};
       int result = diagonalSum(matrix);
       System.out.println(result);
   }
}

Output:

250

Take two variables to store the sum of the left and right diagonal.

Take two pointers row, col to traverse the matrix. If row and col are equal then we have to add that element only once either in leftSum or rightSum.

  • Time Complexity: O(n), as we are running a loop to n times.
  • Space Complexity: O(1)

24. Write a program to check if given number is palindrome or not?

When a number reads the same both forward and backward, it is a palindrome.

Example: 232 is a palindrome while 233 is not.

class Palindrome {
   public static boolean checkPalindrome(int number) {
      //Check if number is zero
       if (number < 0) {
           return false;
       }
      //To store the remaining number after each iteration
       int remain = number;
       int reversNumber = 0;
       while (remain != 0) {
          //Extract last digit and add to the reversed number
           reversNumber = reversNumber * 10 + remain % 10;
           //Update the remaining number
           remain /= 10;
       }
       return number == reversNumber;
   }
   public static void main(String []args){
       //Input number
       int number = 123;
       boolean result = checkPalindrome(number);
       System.out.println(result);
   }
}

Output:

true

Take two-variable remain and reverseNumber initially copy the number into the remaining variable. Start a loop till the remains become zero.

Extract the last digit of the number using the modulus operator and then add it to the reverseNumber. Now update the remaining number. When the remaining is zero comes out of the loop and checks if the number and reverseNumber are strictly equal then returns true otherwise returns false.

  • Time Complexity: O(n), where n is the number of digits in the given number.
  • Space complexity: O(1), as we are only using a single variable to store reversed numbers.

25. Write a program to find the missing element in an array?

We are given an array ranging from 1 to N-1. One of the number is missing from the array the task is to find that number. There is no repeating number in the array.

class MissingNumber {
   public static int missingNumber(int[] arr) {
       int i=0,n=arr.length+1;
       //Calculate sum of n natural numbers and store it
       int sum=0,sumOfNatural=n*(n-1)/2;
      //Loop through the array and calculate the sum of the elements of the array
       for(i=0;i<n-1;i++){
           sum+=arr[i];
       }
      //Return the difference of both
       return sumOfNatural - sum;
   }
   public static void main(String []args){
      //Input array
       int []arr = {3,4,2,0,1,6};
       int result = missingNumber(arr);
       System.out.println(result);
   }
}

Output:

5

Calculate the sum of the first N natural number. Traverse the array using a loop and calculate its sum and store it in the variable named sum.
Return the difference of the sum of natural number and sum.

  • Time Complexity: O(n), we are only iterating through the array.
  • Space Complexity: O(1)

26. Write a program to print fibonacci series?

The Fibonacci sequence is a collection of integers (the Fibonacci numbers) that goes from 0 to 1, then 1, then 1, then a series of numbers that increase continuously after that. In the series, each number is equal to the sum of the two numbers that came before it.

public class FibanacciSeries
{
   public static void main(String []args){
     int e1 = 0, e2 = 1, nextElement = 0;
     int range=100;
     // print the first two element of fibonacci which is 0 and 1
     System.out.print(e1 + "," +e2);
     //Initially nextElement will be the third element in the series
     nextElement = e1 + e2;
    //Run loop till nextElement is equal to range
     while (nextElement <= range) {
      //Print the next element in the series
       System.out.print(","+nextElement);
       //Update e1 by assigning e2 to it
       e1 = e2;
       //Update e2 by assigning nextElement to it
       e2 = nextElement;
       nextElement = e1 + e2;
     }
   }
}

In the Fibonacci series, we have to focus on three numbers because the next number in the series will be the addition of two preceding numbers.

Take three variables initially the first(e1) and second(e2) will be 0 and 1. In the third variable(nextElement) we will store the next element in the series.

So start a loop upto the range and in iteration do this, replace e1 with e2(e1=e2) and e2 with nextElement(e2=nextElement) and then in nextElement store the sum of e1 and e2.

  • Time Complexity: O(n), as the loop runs only from 1 to n.
  • Space Complexity: O(1)

27. Write a program to find the sum of each row of a matrix?

class RowSum{
static void sumOfRow(int matrix[][],int row, int col)
{
 int i, j;
 int sum = 0;
 for (i = 0; i < row; ++i) {
  for (j = 0; j < col; ++j) {
                                      //Calculating sum of elements in a row
   sum = sum + matrix[i][j];
  }
  System.out.println(sum);
                             //Reset sum after each row
  sum = 0;
 }
}
public static void main(String[] args)
{
                   //Input matrix
 int[][] matrix = {{1,2,3,4},
                   {5,6,7,8},
                   {9,10,11,12},
                   {13,14,15,16}};
 sumOfRow(matrix,4,4);
}
}

Output:

10, 26, 42, 58

Take variable sum to store the sum of the row. Start traversing the matrix and in each traversal calculate the sum of the row and then print it and then rest it.

  • Time Complexity: O(m*n), we are traversing through the whole matrix so. Where m is the number of rows and n is the number of columns.
  • Space Complexity: O(1)

Useful Resources

TCS Ninja Interview Preparation

1. Interview Preparation Tips

  • Learn computer fundamentals: You must be familiar with ideas related to object-oriented programming as well as operating systems, database management systems, computer networks, and data structures. Also, you must have a little knowledge of C and C++.
  • Practice: Practice simple coding questions like pattern printing, array-based problems, recursion-based problems, and SQL queries. There are various platforms like Interviewbit, hackerrank, and leetcode where you can practice coding questions for your preparations.
  • Latest Technology: Try to get some basic knowledge of the latest trending technologies like Machine Learning, Artificial Intelligence, Cloud Computing, etc. Sometimes interviewers can ask basic questions related to these fields.
  • Problem Solving Approach: In an interview, when the interviewer asks a coding question, first try to understand the problem. If there is any doubt, then discuss the problem with the interviewer. Then first make a brute force solution, then optimize the solution.
  • Be Genuine & Confident: Always give sincere, assured responses to the interviewer's queries. If you make any false statements during the interview and the interviewer discovers them. This will then result in your rejection.

Frequently Asked Questions

1. Does TCS Ninja have Negative Marking?

In the TCS Ninja exam, there is no negative marking although each question will have some predefined times. If you are unable to solve in the given time constraint then that question will be skipped automatically and you can not reattempt it. The time for each question can be from 1-3 minutes depending on the topic and level of the questions.

2. Is the TCS Ninja interview tough?

You will be qualified to participate in the TCS NINJA Technical Interview after passing the NQT Round. Make every effort to get ready for this stage of the hiring process as it is the most difficult. Although if you are prepared for it then there will be no problem at all. In comparison to other similar companies, TCS ninja has the easiest interview process. If your basic knowledge of computer fundamentals and programming is clear then you can easily crack its interview.

3. How to apply for TCS Ninja?

TCS Ninja has a highly difficult form-filling process. Many students who want to work at TCS are turned down because they did not complete the TCS application form.

  • Goto the TCS ninja website and register yourself. 
  • Then click on the IT option. 
  • Then you will be required to fill in the basic details about yourself.
  • After that is complete, your registration process with OTP received on your mobile number.
  • After you have completed and double-checked all of the details, click the submit button.
  • Also, register yourself on TCN ION. Without registering on it your application will not proceed further.

4. How can I introduce myself in the TCS Ninja interview?

If you are a fresher, start with your academics, projects, achievements, other curriculum activities, and strengths. Also, inform them about your interests, background, and so on. If you're an experienced professional, begin with your current position, achievements, previous work history, and then academic and personal details.

5. What is the TCS Ninja package for Freshers?

Shortlisted applicants are offered a package from 3.36 to 3.6 LPA by Tata Consultancy Services. Along with this, you can get a 60,000 bonus based on your performance.

6. How long is the TCS Ninja Interview?

It depends upon the interviewer how long your interview can go. Generally, the interview lasts up to 15-20 min but sometimes it can be up to 30 mins. If interviewers have asked a coding question then it can also be up to 40-45 mins.

7. What is the Eligibility Criteria at TCS Ninja?

The revised Eligibility Criteria for TCS Ninja are listed in the table below and will be applicable to those who graduate in 2022. More information can be found in the table below:

TCS Ninja Eligibility Criteria Detailed Information
Qualification B.E, B.tech(All branches), M.E, Mtech BCA, MCA
10th Marks 60% or above
12th Marks 60% or above
Graduation Minimum 60%
Gap in Education Up to two years
Backlogs or Arrears  At the time of taking the Aptitude Exam, there should be one active backlog.
Get Placed at Top Product Companies with Scaler Know More 
Get Placed at Top Product Companies with Scaler Know More 
Get Placed at Top Product Companies with Scaler
Sat transparent 640a34d454880bf68e3bfdf33f2389f2214043f59ad18b4c7f7b114e834fb257.svg

Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Personalised feedback report with solutions
Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Real life Interview Questions
Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Identify exact topics to improve

Your feedback is important to help us improve.
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
Select an option *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
Graduation Year *
Graduation Year *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test