Cognizant Interview Questions | Cognizant Recruitment (2021) - InterviewBit

Before you go!

Take this "Cognizant 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 *

Cognizant 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 Cognizant interview

Cognizant is a multinational technology company based in the United States that specializes in business consulting, information technology, and outsourcing. The company's headquarters are in Teaneck, New Jersey. Cognizant is a member of the NASDAQ-100, S&P 500, Forbes Global 2000, and Fortune 500, and is one of the world's most successful and fastest-growing organizations.

Cognizant assists businesses in modernising technology, reimagining processes, and transforming customer experiences in order to stay ahead in an ever-changing environment. It is determined to enhance the way the world works via technology, whether it's by altering the companies that the world relies on or by providing the tools and flexibility you need to develop the best you. Cognizant specializes in information technology, information security, consulting, ITO, and BPO services. Cognizant's business is divided into three areas: digital business, digital operations, and digital systems and technology.

Cognizant offers a great opportunity for learning and creating a career path for aspiring software engineers among all the MNCs offering Fresher Jobs in India. Working here will expose you to a variety of new technologies as well as provide you with the opportunity to work with global customers that will help you improve your talents, problem-solving ability, and entrepreneurial spirit. Your ability to affect the future of your career—and the world—is limitless at Cognizant.

Eligibility Criteria:

  • An applicant must have more than 60% marks in 10th and 12th (or diploma).
  • An applicant must have a minimum of 60% marks in graduation.
  • After HSC(12th), but not after SSC(10th), or between semesters of graduation, a maximum interval of one year is permitted.
  • Graduation and post-graduation in BE, B Tech, ME, M Tech, MCA
  • At the time of the Cognizant selection process, a candidate should not have any pending backlogs.

Cognizant Recruitment Process

Interview process.

From company culture to opportunities for growth, there are several things that make Cognizant an excellent option to begin your career with. It provides a fantastic workplace that encourages employees to develop and improve their skills conducive to individual and company progress.

In this article, we've covered the entire Cognizant interview process as well as a shared preparation method for acing the interview. This study is based on online research and interviews with candidates who have recently appeared in the Cognizant interview process.

For numerous jobs and departments, Cognizant hires both freshers and experienced professionals. Cognizant visits numerous college campuses in their final placements conducts walk-ins, and mega placement drives for fresher hiring. Cognizant primarily hires experienced employees through its career website, HR consulting firms, and employee referral programmes.

This season, Cognizant plans to run a recruitment process for four different positions. The following are the specifics:

  • GENC
  • GENC ELEVATE
  • GENC PRO
  • GENC NEXT

Interview rounds.

Round 1: Aptitude test/Skill based assessment test

 It is an online test that takes place on online platforms such as AMCAT etc.

Candidates applying for the GENC profile are required to appear for the aptitude test, which contains the following sections:                                       

  • Quantitative ability: This section will generally contain questions related to the following topics: Basic Mathematics, Applied Mathematics, and Engineering Mathematics                        
  • Logical reasoning: This section will generally contain questions related to the following topics: Coding deductive logic,  Data Sufficiency, Objective Reasoning, Data Arrangement, Coding Pattern Recognition, Number Series Pattern Recognition.                                         
  • English comprehension: This section will generally contain questions related to the following topics: Vocabulary (Synonyms, Antonym, Contextual Vocabulary), Grammar (Error Identification, Sentence Improvement, and Construction), Comprehension Reading.

Candidates applying for GENC NEXT, GENC PRO, and GENC ELEVATE profiles are required to appear for the skill-based assessment test, which contains the following sections:

Section Topics
MCQ Conceptual and Code Analysis
Coding Challenge Coding Questions

The questions will generally be related to the following topics :

  • Programming Constructs, Data Structures, Algorithms
  • Database/ SQL
  • Web UI

Based on their performances in skill-based assessment tests and interviews, one will be selected for GENC NEXT, GENC ELEVATE, or GEN PRO  profiles. Candidates should have at least basic hands-on programming skills to qualify for the GenC Elevate assessment, which should be substantiated by proof submitted during the self-profiling procedure.

After getting the required cut-off in the aptitude test/skill-based assessment test, the candidates are selected for the technical interview round.


ROUND 2: Technical Interview

The technical face-to-face interview round is the most crucial in the entire interview process. You should be well-versed in computer science fundamentals such as OOPS, DBMS, CN, OS and be able to communicate them clearly to the interviewer.

Programming language knowledge is required. Make sure you're familiar with at least one programming language. It is not necessary for you to be fluent in all programming languages, but you should have sufficient experience with at least one of them, such as C++, Java, or Python. There is a considerable chance that you may be asked to write a code on pen and paper. Problem-solving skills will also be checked by the interviewer.

Knowledge of the most recent technological developments is an added advantage. You should have a fundamental awareness of contemporary technology trends, such as artificial intelligence (AI), big data, and so on. You'll be asked questions about your previous projects and job experiences, such as what you did, what technology you utilized, what you developed, and how successful you were, among other things.

Questions related to CV and company may also be asked. 

After clearing the technical interview round, the candidates are called for HR ROUND. 

ROUND 3: HR Interview

This is the most important round of the interview process. During this round, many in-tenders are rejected. The goal is to maintain a pleasant and confident demeanor. Interviews can be long and tedious, so remember to smile!

During the HR phase, the interview panel will ask you questions about your personality, family background, education, interests, internships, work experience (if applicable), and other topics. Make preparations to answer questions on internships, projects, volunteerism, and extracurricular activities mentioned in your CV. There can be questions related to the company - what are the products/services the company offers, what are its core values, when it was formed, its organizational structure, and so on.

You can never be too prepared when it comes to HR interview questions and responses. The greatest thing you can do is develop a list of the most popular HR interview questions and practice answering them. You should have the answers to these questions at your fingertips. Another crucial thing to keep in mind while going for an interview is to look and behave confidently. Keep in mind that you should not lie or be overconfident. Having excellent body language can make all the difference.

Cognizant Company HR  interview questions For Freshers and Experienced-

  • Tell me something about yourself. (Start with your academics, projects, achievements, other curriculum activities, and your strengths if you are a beginner. Also, tell them about your hobbies, background, and so on. If you're an experienced professional, start with your present position, achievements, previous work history, and then academic and personal information.)
  • Are you willing to relocate to different parts of India?
  • What are your strengths?
  • Why should we hire you?
  • What are some of the characteristics of this profession that you enjoy?
  • Describe your Final Year Project. What new ideas did you bring to the table for this project?
  • Why are you looking for a job change? (If you're an experienced professional seeking a change, this is a common question. The easiest method to respond to this question is to state that you are leaving your current work in order to advance your career. Make sure you don't criticize or speak poorly about the company where you now work.)
  • What is your expected salary? (This is a difficult question to answer. It is generally asked from experienced employees. You may inquire about the company's standard raise for employees.)

Cognizant Technical Interview Questions: Freshers and Experienced

1. Write the code to find the length of a string without using the string functions.

#include <iostream>
using namespace std;
int main()
{
      char str[100];
      int len = 0;
      cout << "Enter a string: ";
      cin >> str;
      while(str[len] != '\0')
      {
             len++;
      }
      cout << "Length of the given string is: " << len;
      cout << endl;
      return 0;
}

2. How will you print the address of a variable without using a pointer?

We may acquire the address of any variable by using the “address of operator” (&) operator, which yields the variable's address.

#include <stdio.h>
int main(void)
{
   // declaring the variables 
   int x;
   float y;
   char z;
   printf("Address of x: %p\n", &x);
   printf("Address of y: %p\n", &y);
   printf("Address of z: %p\n", &z);
   return 0;
}

3. What do you understand about Proactive, Retroactive and Simultaneous Update in the context of DBMS?

  • Proactive Updates: These changes are made to the database before it is put into use in the real-world environment.
  • Retroactive Updates: These updates are applied to a database after it has been operational in the real-world environment.
  • Simultaneous Updates: These updates are applied to the database at the same moment as they become functional in the real-world environment.

4. List out the differences between Generalization and Specialization in DBMS.

GENERALIZATION SPECIALIZATION
Generalization uses a Bottom-Up approach. Specialization uses a top-down approach.
The size of the schema gets reduced in Generalization. The size of the schema gets increased in Specialization.
Generalization is usually applied to a group of entities. Specialization can be applied to a single entity.
The practice of forming groupings from diverse entity sets is known as Generalization. The process of forming subgroups inside an entity set is known as Specialization.
In Generalization, in order to form a higher entity, the differences and similarities between lower entities are ignored and their union is considered. In Specialization, lower entities are formed by splitting higher entities.
Inheritance does not exist in Generalization. Inheritance exists in Specialization.
Example: Consider the ideas of a Student and a Patient. These two entities will have distinct properties. Student entities, for example, will have Roll No, Name, and Mob No attributes, whereas patient entities will have PId, Name, and Mob No attributes. In this case, the Name and Mob No of both the Student and the Patient can be joined as a Person to construct a higher-level entity, which is known as the Generalization Process. Example: Consider the account of a person as an entity. This will have some properties, such as Acc No and Balance. Other properties of the account entity, such as Current Acc and Savings Acc, may exist. Now that Current Acc has Acc No, Balance, and Transactions, and Savings Acc has Acc No, Balance, and Interest Rate, we may argue that specialized entities inherit characteristics from higher-level entities.

5. What is the fill factor in SQL? What is its default value?

The fill factor is the percentage of space on each leaf-level page that will be filled with data. The smallest unit in SQL Server is a page, which is made up of 8K pages. Depending on the size of the row, each page can store one or more rows. The Fill Factor's default value is 100, which is the same as the value 0. The SQL Server will fill the leaf-level pages of an index with the highest number of rows it can fit if the Fill Factor is set to 100 or 0. When the fill factor is 100, the page will have no or very little vacant space.

6. What exactly is index hunting, and how does it aid query performance?

Index hunting is the method of boosting a collection of indexes. This is done because indexes improve query performance as well as query processing time.

It aids in query performance improvement in the following ways:

  • Using the query optimizer, the optimal queries are suggested.
  • To check the effect, parameters such as index, query distribution, and performance are used.
  • Databases are optimized into a small group of problem queries.

7. Write the steps to create, update and drop a view in SQL.

 In SQL, a view is a single table that contains data from other tables. As a result, a view features rows and columns that are identical to those of a real table, as well as fields from one or more tables.

In order to create a view:

CREATE VIEW View_Name AS
SELECT Column1, Column2, Column3, ..., ColumnN
FROM Table_Name
WHERE Condition;

For updating a view:

CREATE VIEW OR REPLACE View_Name AS
SELECT Column1, Column2, Column3, ..., ColumnN
FROM Table_Name
WHERE Condition;

For dropping a view:

DROP VIEW View_Name;

In the above queries, Column1, Column2, .. ColumnN denotes the name of the columns to be added or updated. View_Name denotes the name of the view created and Table_name denotes the name of the current table.

8. What are the similarities and the differences between Shortest Job FIrst (SJF) and Shortest Remaining TIme FIrst (SRTF) CPU scheduling algorithms?

SJF (Shortest Job First) is a scheduling policy that prioritizes the waiting process with the shortest execution time. Shortest Job Next (SJN) or Shortest Process Next are other names for it (SPN). It is a scheduling algorithm that is not preemptive (that is, one process cannot snatch the resources assigned to a currently running process).

The preemptive variant of SJF scheduling is the Shortest Remaining Time First (SRTF). The procedure, next in the queue, with the least amount of time till completion is chosen to be executed in this scheduling technique. Processes that arrive at the same time transform SRTF to SJF.

Similarities:

  • Both SJF and SRTF are essentially difficult to implement since the processes' burst time cannot be predicted.
  • Both SJF and SRTF have the potential to cause process starvation since long processes can be delayed forever if short processes are constantly added.
  • Once all of the processes are in the ready queue, both SJF and SRTF are regarded the same. This is because no preemption is performed after the processes are added to the ready queue.
Shortest Job First Shortest Remaining Time First
SJF is a non-preemptive algorithm. SRTF is a preemptive algorithm.
SJF involves less overheads than SRTF. SRTF involves more overhead than SJF.
SJF results in comparatively lower throughput. SRTF results in increased throughput as execution is faster.
SJF reduces the average waiting time for each process. SRTF may or may not reduce the average waiting time for each process.
SJF involves a lesser number of context switching. SRTF involves a greater number of context switching.

9. What factors influence whether or not a detection algorithm is required in a deadlock avoidance system?

One of the factors is that it is dependent on how frequently a deadlock is likely to occur when this algorithm is implemented. The other is the number of processes that will be affected by deadlock if this algorithm is used.

10. How does Dynamic Loading help in better memory space utilization?

In dynamic loading, a routine is not loaded until it is called. This strategy is very effective when dealing with vast quantities of code, such as error routines, that occur infrequently. All routines are saved in a relocatable load format on the disk. The main program is executed after it has been loaded into memory. When a routine requires to call another routine, the calling routine checks to verify if the other routine is loaded first. If this is not the case, the relocatable linking loader is used to load the requested routine into memory and update the program's address tables. The newly loaded routine is then given control. In this way, dynamic loading helps in better memory space utilization.

11. What is Root Partition in OS?

The root partition is the place where the operating system kernel is located. Other potentially crucial system files that are mounted during boot time are contained in it as well.

12. What is the purpose of a Virtual File System (VFS)?

An abstract layer on top of a more concrete file system is a virtual file system (VFS) or virtual filesystem switch. 

  • The purpose of a VFS is to make it possible for client applications to access various types of concrete file systems in a consistent manner. For example, a VFS can be used to seamlessly access local and network storage devices without the client device recognizing the difference.
  • It can be used to bridge the gap between Windows, traditional Mac OS/macOS, and Unix filesystems, allowing applications to access files on those sorts of local file systems without needing to know what type of file system they're dealing with.
  • A VFS defines the kernel's interface with a certain file system. As a result, adding support for new file system types to the kernel is simple.

13. What is caching? How does caching work?

Caching is a technique for saving numerous copies of the most frequently used data in a temporary storage area (or cache) so that they can be accessed more quickly. It keeps data in a temporary format for software applications, servers, and web browsers, so users don't have to download information every time they visit a website or use an application.

Cached data works by saving data in a device's memory for later access. The data is kept in the memory of a computer, directly below the central processing unit (CPU). The primary cache level is incorporated into a device's microprocessor chip, followed by two more secondary cache levels that feed the primary level. This information is kept until the content's time to live (TTL), which specifies how long it should be cached, expires or the device's disc or hard drive cache fills up.

Data is usually cached in one of two ways: browser or memory caching (data stored locally on the computer) or Content Delivery Networks (data stored in geographically distributed locations).

14. What is Preemptive Multitasking? How is it different from Cooperative Multitasking?

Preemptive multitasking permits computer programs to share operating systems (OS) and underlying hardware resources. It distributes the overall operating and computing time amongst processes, and it uses established criteria to switch resources between processes. Time-shared multitasking is another name for preemptive multitasking.

The operating system never initiates context switching from one process to another in cooperative multitasking. Only when the processes voluntarily cede control on a routine basis, or when they are inactive or logically blocked, does a context switch occur, allowing many applications to run at the same time. In addition, in this multitasking, all processes work together to make the scheduling strategy work.

15. What is plumbing/piping in Linux or Unix?

Plumbing/ Piping refers to the technique of using one program's output as an input to another. For instance, Instead of delivering a folder or drive listing to the main screen, it can be piped and delivered to a file, or sent to the printer to print a hard copy.

A pipe is a type of redirection (the transfer of standard output to another location) used in Linux and other Unix-like operating systems to transport the output of one command/program/process to another for additional processing. The Unix/Linux systems allow a command's stdout to be connected to another command's stdin. The pipe character ‘|' can be used to do this.

16. Name the typical elements of a processed image.

The typical elements of a processed image are:

  • User data: This element of user space includes program data, user stack area, and programs that can be modified.
  • User program: The set of instructions that are to be executed.
  • System Stack: Each process is associated with one or more LIFO (Last In First Out) stacks. Parameters and calling addresses for procedure and system calls are stored here.
  • Process control Block (PCB): Information required by the operating system to control operations.

17. What is Trapdoor in OS?

A trapdoor is a software or hardware mechanism that can be used to bypass system controls. In general, it's malicious software that allows an attacker on the other side of the Internet to gain unauthorized access to a computer system or network by accepting remote commands. Trap door software monitors a specific Transmission Control Protocol (TCP) or User Datagram Protocol (UDP) port for orders.

18. What is the Translation Lookaside Buffer?

Translation TLB (Transaction Look-aside Buffer) is a particular cache that keeps track of recently used transactions. The TLB includes the most recently used page table entries. The CPU analyses the TLB when given a virtual address. The frame number is retrieved and the real address is created if a page table entry (TLB hit) is present. If a page table entry is missing from the TLB (TLB miss), the page number is used as an index while processing the page table. The TLB first checks if the page is already in main memory; if it isn't, a page fault is generated, and the TLB is then modified to incorporate the new page entry.

19. What is the resident set and working set?

At any given time, the resident set is the part of the processed image that is actually in the real memory. It's broken down into subsets, one of which is the working set. The working set is the subset of the resident set required for execution.

20. List the differences between RSA (Rivest, Shamir, Adleman) and Digital Signature Algorithm (DSA).

RSA DSA
RSA is a cryptosystem algorithm. DSA is a digital signature algorithm.
This algorithm finds its application in secure data transmission. This algorithm finds its application in digital signature and its verification.
It implements the mathematical concept of factorization of the product of two large prime numbers. It implements the concept of modular exponentiation and discrete logarithm.
RSA is slower in key generation as compared to DSA. DSA is faster in key generation as compared to RSA.
RSA is faster in encryption but slower in decryption as compared to DSA. DSA is slower in encryption but faster in decryption as compared to RSA.

21. What is a bridge router (als known as brouter) ?

A bridge router, sometimes known as a brouter, is a network device that can function as both a bridge and a router. The brouter forwards all other packets like a bridge and only routes packets for known protocols.

For routable protocols, brouters function at the network layer, while for non-routable protocols, they operate at the data link layer. Brouters operate as routers for routable protocols and bridges for non-routable protocols, handling both routable and non-routable characteristics. Brouters are connecting devices in networking systems that serve as both a network bridge and a router in the internetwork.

22. What is Exterior Gateway Protocol (EGP)?

The Exterior Gateway Protocol (EGP) is a protocol that allows Internet gateways from the same or separate autonomous systems to share network reach-ability information.

EGP serves three primary purposes:

  • Create a set of neighbors.
  • Keep a check on the neighbors (to see if they are still alive and reachable).
  • Notify the neighbors about the networks that are accessible from their autonomous systems.

23. What do you know about Network Virtual Terminal (NVT)?

Rather than communicating in native "languages", all Telnet clients and servers agree to deliver data and commands that conform to a fictional "virtual" terminal type known as the Network Virtual Terminal (NVT). The NVT specifies a set of standards for formatting and sending data, including character set, line termination, and how information about the Telnet session is provided.

Every Telnet client on a terminal can communicate in both its native language and NVT. When a user enters information on his or her local terminal, it is translated to NVT and sent over the network in that format. When the Telnet server receives this information, it converts it from NVT to the format required by the remote host. In reverse, the same procedure is followed for transmissions from the server to the client.

24. What is the Hamming Code?

The Hamming code is a set of error-correction codes that can be used to detect and fix errors that can arise when data is transferred or stored from one source to another. Redundant bits are extra binary bits that are created and added to the data transfer's information-carrying bits to ensure that no bits are lost during the data transfer. A parity bit is a bit that is appended to binary data to verify that the total number of 1s is even or odd. Error detection is done with parity bits. The Hamming Code is essentially the use of additional parity bits to allow for error detection.

25. What is the purpose of a Pseudo TTY (pseudo terminals)?

A bidirectional communication channel is provided by a pair of virtual character devices known as a pseudo TTY (or "PTY"). The master is at one end of the channel, while the slave is at the other. The pseudo-terminal's slave end provides an interface that is identical to that of a conventional terminal. A process that expects to be connected to a terminal can open the slave end of a pseudo-terminal, which will subsequently be controlled by a program that has opened the master end. Anything written on the master end is supplied to the slave end's process as if it were any input entered on a terminal. Anything written to the slave end of the pseudo-terminal, on the other hand, can be read by the process linked to the master end. Network login services, terminal emulators, and other such applications employ pseudo-terminals.

26. What is BufferedWriter? What are flush() and close() used for?

BufferedWriter is a temporary data storage source. It's used to make a buffered character output stream with the default output buffer size.

To flush characters from the buffered writer stream to a file, the flush() function of the BufferedWriter class in Java is employed. It ensures that all data items, including the last character, are written to the file.

The close() function of the Java BufferedWriter class flushes the characters from the buffer stream and then closes it. Calling methods like write() and append() after the stream has been closed will generate an error.

27. What is stored in each of the memory structures- stack and heap, and how are they related to each other?

The stack is a section of memory that stores information about nested method (recursive)  calls all the way down to the present program location. It also holds all local variables and heap references defined in the currently running procedures. This structure enables the runtime to return from the method knowing the address from which it was invoked, as well as to remove all local variables when the procedure has been exited. Every thread has a stack of its own.

The heap is a big chunk of memory used for dynamic allocation. When you use the new keyword to create an object, it is allocated on the heap. The reference to this object, on the other hand, is stored on the stack.

28. Is it possible to «resurrect» an object that has become eligible for garbage collection in Java?

The Garbage Collector (GC) must call the finalize method on an object when it becomes garbage collection eligible. Because the finalize method can only be used once, the GC marks the object as finalized and sets it aside until the next cycle.

You can technically "resurrect" an object in the finalize method by assigning it to a static field, for example. The object would revive and become ineligible for garbage collection, preventing the GC from collecting it in the next cycle.

The object, on the other hand, would be marked as finalized, thus the finalize method would not be invoked when it became eligible again. In essence, you can only use this "resurrection" method only once.

Example:

// Java Program to illustrate Object Resurrection

import java.io.*;
import java.util.*;

public class InterviewBit {

   private int num;

   // Constructor
   public InterviewBit(int num)
   {

       // assigning the parameter value to the member variable
       this.num = num;
   }

   // Creating an ArrayList of class object
   static final ArrayList<InterviewBit> ar = new ArrayList<InterviewBit>();

   protected void finalize() throws Throwable
   {

       System.out.println("Resurrect " + num);

       // By using the this operator, adding the current instance to object
       ar.add(this);
   }

   public String toString()
   {

       return "Element("
           + "number = " + num + ')';
   }
   public static void main(String[] args)
       throws InterruptedException
   {

       for (int i = 0; i < 3; i++)
           ar.add(new InterviewBit(i));
       for (int j = 0; j < 5; j++) {

           // printing the element in the object
           System.out.println("The Elements are : " + ar);

           // Clearing off elements
           ar.clear();

           // Calling the garbage collector function
           System.gc();

           // Making the thread to sleep for 500 ms
           Thread.sleep(500);
       }
   }
}

Output:

The Elements are : [Element(number = 0), Element(number = 1), Element(number = 2)]
Resurrect 2
Resurrect 1
Resurrect 0
The Elements are : [Element(number = 2), Element(number = 1), Element(number = 0)]
The Elements are : []
The Elements are : []
The Elements are : []

Explanation:

The finalize method adds the items to the collection once and then resurrects them. They have been marked as finalized and will not be queued again when they are collected a second time.

29. Is it possible to override and overload a static method in Java? Is it possible to override a private method in Java?

Because static methods are resolved at compile time, one cannot override them in Java. Because objects are only available at runtime, overriding requires a virtual method that is resolved at runtime. In Java, a static method can be overloaded. Overloading has nothing to do with runtime, but each method's signature must be distinct. To alter the method signature in Java, either the number of parameters, the type of arguments, or the sequence of arguments must be changed.

In Java, you can't override a private method because the subclass doesn't inherit the private method, which is required for overriding. In fact, no one outside the class can see a private method, and a call to it is handled at compile time using Type information rather than at runtime using the actual object.

30. What is monkey patch in Python?

Monkey patches are dynamic (or run-time) alterations of a class or module in Python. We can truly change the behavior of code at runtime in Python.

Example:

# m.py
class A:
    def func(self):
          print ("func() is called")

In the code below, we use the above module (m) to change the behavior of func() at runtime by assigning a new value.

import m
def monkey_func(self):
    print ("monkey_func() is called")
  
# replacing the address of "func" with "monkey_func"
m.A.func = monkey_func
ob = m.A()
  
# calling the function "func"
ob.func()

Output:

monkey_func() is called

Explanation: 

We have assigned the monkey_func to the address of “func” of class A. Thus, when we call the “func” function of “ob”, the monkey function is called.

31. Write the code to add two numbers without using arithmetic operators.

The sum of two bits can be found by executing an XOR (^) operation on the two bits. A carry bit can be obtained by performing AND (&) on the two bits.

The logic shown below is a simple Half Adder that may be used to add two single bits. This logic can be extended to integers. If there are no set bits at the same position(s) in a and b, bitwise XOR (^) of a and b yields the sum of a and b. Bitwise AND (&) is used to include common set bits as well. All carry bits are obtained by bitwise AND of a and b. To acquire the needed result, we compute (a & b) << 1 and add it to a ^ b.

// C Program for adding two numbers
// without the use of arithmetic operators
#include<stdio.h>

int Addition(int a, int b)
{
   // Iterate until no carry 
   while (b != 0)
   {
       // carry now stores common
       //set bits of a and b
       unsigned carry = a & b; 

       a = a ^ b;

       // Carry to be shifted by one so that on adding
       // it to a, we get the required sum
       b = carry << 1;
   }
   return a;
}

32. Write a code to print numbers from 0 to 100 in C++ without using loop and recursion.

Template Metaprogramming is the idea used in this code.

Let's have a look at how this works. Non-data types can also be used as parameters in C++ templates. The term "non-datatype" refers to a value rather than a datatype. In the preceding code, for example, N is passed as a value rather than a datatype. For each parameter, a new instance of a generic class is constructed, and these classes are created at compile time.

#include <iostream>
using namespace std;
 
template<int n>
class PrintZeroToN
{
public:
   static void display()
   {
       PrintZeroToN<n-1>::display();  // this should not be mistaken for recursion
       cout << n << endl;
   }
};
 
template<>
class PrintZeroToN<0>
{
public:
   static void display()
   {
       cout << 0 << endl;
   }
};
int main()
{
   const int n = 100;
   PrintZeroToN<n>::display();
   return 0;
}

Explanation:

N is passed as a value rather than a data type in the above program. For each parameter, a new instance of a generic class is constructed, and these classes are created at compile time. When the compiler encounters the line “PrintZeroToN<>::print()” with N = 100, it produces an instance PrintZeroToN<100>. Another function PrintZeroToN<99>::print() is called in function PrintZeroToN<100>::print(), resulting in the creation of an instance PrintZeroToN<99>. All instances from PrintZeroToN<100> to PrintZeroToN<1> are created in the same way. The function PrintZeroToN<0>::print() already exists and prints 0. The PrintZeroToN<1> function prints 1 and so on. As a result, all numbers from 0 to N are printed on the screen.

Cognizant Interview Preparation

Interview Preparation Tips

  • Keep a positive attitude and a smile on your face at all times. If you are confident enough, you have already completed half of the task.
  • Practice well. Just like any other exam or test, you can only pass them if you have a thorough understanding of the material and have practiced at least 100 times before taking the actual tests. If you have any doubts about a subject, make sure you clear them up by reading good books or enrolling in an appropriate online course for aptitude preparation.
  • Make sure you brush up on your coding test papers, as well as practice programming fundamentals, such as C, C++, Java, and other computer fundamentals such as OOPs, concepts, database, and networking. Develop a code to find the GCD of a number or write a code for bubble sort, for example.
  • It is important that you are familiar with your CV. Make sure that everything you've stated on your CV about previous projects and internships is accurate and that you know everything. You'll be asked questions about your previous projects and job experiences, such as what you did, what technology you utilized, what you developed, and how successful you were, among other things.
  • Visit the company’s website.  Make sure you learn everything you can about Cognizant, such as what kind of work/projects it is currently working on. Employers expect you to understand who the company is, what it does, how it fits into your career aspirations. These types of questions are generally asked in the HR round.
  • Make sure you're up to date on the latest technical advancements. You should have a fundamental understanding of current technology trends, such as artificial intelligence (AI), big data, and so on.
  • Speak with assurance. It is more important to listen to the interviewer than to respond. Before you attempt to answer a question, make sure you understand it completely. If you don't understand something, don't be afraid to ask for an explanation.

Frequently Asked Questions

1. Is cognizant interview difficult?

The amount of effort you put into preparing for an interview determines how difficult it is. The more you prepare, the easier it will be to pass the interview. All you need to know is the fundamentals of new technologies, programming languages, your projects, and Cognizant. Interviewers are interested in how candidates approach problems, construct their thought process, and display personal qualities such as communication, in addition to technical knowledge (which is vital).

2. What is the fresher salary in Cognizant?

At Cognizant, a fresher's pay ranges from 3.3 to 4.5 lakhs.

3. What are the questions asked in a Cognizant interview?

Questions are asked related to a fundamental understanding of operating systems, database management systems (RDBMS, various keys), computer networks (particularly the OSI model and its seven layers of function, protocols, IP addresses, routers, and so on), and cloud computing. Your programming abilities will also be examined. Be prepared with the fundamentals of Java, HTML, C, C++ among other topics. The interviewer might ask basic questions regarding the candidate's job experience, expected salary, background, qualification during the HR Round. Learn More.

4. Is there any bond in Cognizant?

There is no such thing as a Bond. In the sense that you are not required to pay any money if you desire to terminate your contract with the firm.

5. Does cognizant have a dress code?

The dress code is casual. Simply maintain a neat and tidy appearance.

6. How can I apply for Cognizant ?

You can apply to Cognizant in a variety of ways, including through employment sites, Cognizant's career page, attending recruiting drives, using the employee referral system, or consulting with placement experts. 

7. How many rounds are there in a Cognizant interview?

The Cognizant Recruitment Process consists of two steps:

  • Online exam
  • Interview process
    • Technical interview
    • HR interview

Check out the above section for the detailed interview process.

8. How is career growth in Cognizant?

Cognizant is proud of its workers' achievements and is committed to promoting their personal and professional development by providing:

  • Well defined role enhancement programs
  • Career planning
  • Opportunities to advance their careers by pursuing further education or industry credentials.
  • Possibilities to apply for open employment at Cognizant