Cognizant Interview Questions & Answers PDF
Cognizant Interview Questions & Answers PDF
C# Programming Questions
1. Write a C# program to find the maximum occurrence of a character in a given string.
2. String C# Question: Find the occurrence of letter which is repeated maximum number of times (consider uppercase as
lowercase).
6. Access Modifiers
Database Questions
7. Indexes in SQL
9. ACID Properties
11. Normalization
Data Structures
15. Linked List and Array Questions
Personal Questions
16. Resume-Based Questions
22. Riddle: 2 Liars and 1 Honest Person - How to Choose the Right Box
class Program
{
static void Main()
{
Console.WriteLine("Enter a string: ");
string input = Console.ReadLine();
return maxChar;
}
}
Java Context Questions
2. Inheritance
Expected Answer: Inheritance is an OOP principle where a class (subclass/derived class) inherits properties and methods
from another class (superclass/base class). Java supports single class inheritance but multiple interface inheritance. The
"extends" keyword is used to implement inheritance.
// Base class
class Animal {
protected String name;
// Derived class
class Dog extends Animal {
public Dog(String name) {
this.name = name;
}
// Instance variable
public int instanceCount = 0;
// Constructor
public Counter() {
count++;
instanceCount++;
}
// Static method
public static void displayCount() {
System.out.println("Total count: " + count);
}
}
4. Access Modifiers
Expected Answer: Java has four access modifiers:
These control the visibility and accessibility of classes, methods, and variables.
5. Indexes in SQL
Expected Answer: Indexes are special database structures that improve query performance. They work similar to a book's
index by allowing the database to find data without scanning the entire table.
Types:
Clustered Index: Determines physical order of data (only one per table)
Non-clustered Index: Stores logical order with pointers to physical data
Composite Index: Index on multiple columns
Unique Index: Ensures uniqueness of the indexed column values
.password-field {
width: 100%;
padding: 10px;
margin: 8px 0;
background-color: #e8f0fe;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.login-button {
width: 100%;
padding: 10px;
background-color: #4285f4;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="login-container">
<h2>User Login</h2>
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" class="password-field"><br>
Linked Lists:
Dynamic size
Non-continuous memory allocation
Sequential access (O(n))
Efficient for insertion/deletion but inefficient for random access
Implementation differences:
class Program
{
static void Main()
{
Console.WriteLine("Enter a string: ");
string input = Console.ReadLine();
return maxChar;
}
}
2. String C# Question: Find the occurrence of letter which is
repeated maximum number of times (consider uppercase as
lowercase)
Expected Answer:
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
Console.WriteLine("Enter a string: ");
string input = Console.ReadLine();
return maxChar;
}
}
Expected Answer: Inheritance is an OOP principle where a class (subclass/derived class) inherits properties and methods
from another class (superclass/base class). Java supports single class inheritance but multiple interface inheritance. The
"extends" keyword is used to implement inheritance.
// Base class
class Animal {
protected String name;
// Derived class
class Dog extends Animal {
public Dog(String name) {
this.name = name;
}
// Interface 1
public interface IElectric
{
void Charge();
}
// Interface 2
public interface IAutonomous
{
void SelfDrive();
}
// Instance variable
public int instanceCount = 0;
// Constructor
public Counter() {
count++;
instanceCount++;
}
// Static method
public static void displayCount() {
System.out.println("Total count: " + count);
}
}
6. Access Modifiers
Expected Answer: Java has four access modifiers:
These control the visibility and accessibility of classes, methods, and variables.
Database Questions
7. Indexes in SQL
Expected Answer: Indexes are special database structures that improve query performance. They work similar to a book's
index by allowing the database to find data without scanning the entire table.
Types:
Clustered Index: Determines physical order of data (only one per table)
Non-clustered Index: Stores logical order with pointers to physical data
Composite Index: Index on multiple columns
Unique Index: Ensures uniqueness of the indexed column values
9. ACID Properties
Expected Answer: ACID is an acronym representing the four key properties that guarantee reliable database transactions:
Atomicity: Ensures that a transaction is treated as a single, indivisible unit. Either all operations in the transaction are
completed successfully, or none are (rollback).
Consistency: Ensures that a transaction brings the database from one valid state to another valid state, maintaining all
predefined rules and constraints.
Isolation: Ensures that concurrent transactions do not interfere with each other. Transactions execute as if they were
running one after another, even if they are running simultaneously.
Durability: Ensures that once a transaction is committed, it remains committed even in the case of system failure. The
changes made by the transaction are permanently stored.
Example: When transferring money between accounts, ACID properties ensure the money is neither lost nor duplicated,
regardless of system failures or concurrent operations.
NoSQL Databases:
Schema-less or flexible schema design
Horizontal scalability (scale-out across multiple servers)
Eventual consistency over strict ACID (though some offer ACID)
Optimized for specific data models:
11. Normalization
Expected Answer: Normalization is the process of organizing database tables to minimize redundancy and dependency by
dividing large tables into smaller, related tables.
Must be in 1NF
All non-key attributes are fully functionally dependent on the primary key
Must be in 2NF
No transitive dependencies (non-key attributes depend only on the primary key)
Benefits of Normalization:
SET @i = @i + 1;
END
Example usage:
PIVOT/UNPIVOT
STRING_AGG (SQL Server)
LISTAGG (Oracle)
JSON functions
Window functions (ROW_NUMBER, RANK, DENSE_RANK, NTILE)
.password-field {
width: 100%;
padding: 10px;
margin: 8px 0;
background-color: #e8f0fe;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.login-button {
width: 100%;
padding: 10px;
background-color: #4285f4;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="login-container">
<h2>User Login</h2>
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" class="password-field"><br>
Data Structures
15. Linked List and Array Questions
Expected Answer:Arrays:
Linked Lists:
Dynamic size
Non-continuous memory allocation
Sequential access (O(n))
Efficient for insertion/deletion but inefficient for random access
Implementation differences:
Personal Questions
16. Resume-Based Questions
Expected Answer: Be prepared to discuss all projects listed on your resume in detail. Demonstrate technical knowledge of the
technologies used, explain specific challenges faced and how they were resolved. Clearly articulate your personal role and
contributions to each project. Draw connections between past experiences and the position you're applying for. Use the STAR
method (Situation, Task, Action, Result) to structure your responses.
Why did you choose a particular technology/framework? Focus on technical advantages, team expertise, scalability, or
business requirements that drove the decision.
Why did you structure the project in a certain way? Explain architectural decisions based on requirements,
maintainability, and future scalability.
For "what" questions:
What were your key learnings? Highlight both technical insights and soft skills like collaboration or problem-solving.
What would you do differently? Show reflection and growth mindset by mentioning improvements you'd make with
hindsight.
What challenges did you face? Discuss technical hurdles and how you overcame them, demonstrating problem-solving
abilities.
Use concrete examples to demonstrate your growth and contributions. Explain how your internship experience prepared you
for the role you're applying for.
Express your interest in learning and mastering C# due to its versatility and widespread use in enterprise applications
Highlight transferable programming skills from languages you already know
Mention any steps you've already taken to learn C# (courses, self-study, small projects)
Discuss C#'s benefits for the type of development you want to do (web, mobile, gaming with Unity, etc.)
Demonstrate your ability to quickly learn new technologies based on past experiences
Express willingness to invest extra time to get up to speed
Solution: Ask any person, "If I were to ask the person to your right which box contains the treasure, what would they say?"
Then choose the opposite of what they tell you.
Explanation:
If you ask the truth-teller: They will correctly tell you what the liar would say, which is the wrong box.
If you ask a liar: They will lie about what the other person would say. If the other person is a truth-teller, the liar will not
tell you what the truth-teller would actually say (the correct box). If the other person is a liar, the liar will not tell you what
that other liar would say (the wrong box).
In all cases, the answer you receive will identify a wrong box, so you should choose the opposite.
www.primecoding.in
WWW.PRIMECODING.IN