Cognizant interview experience Real time questions & tips from candidates to crack your interview

SDE - 1

Cognizant
upvote
share-icon
2 rounds | 5 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 3 Months
Topics: Data Structures, My SQL, OOPS, Database, Algorithms, Dynamic Programming, Operating System
Tip
Tip

Tip 1 : Practice Atleast 250 Questions Leetcode
Tip 2 : For DSA questions in interviews, start explaining from the brute force approach and then move to the optimal one. Convey your thought process to the interviewers, so that they can help you out if you get stuck.
Tip 3 : Do not write anything that you are not confident of in resume
Tip 4 : Do atleast 2 projects

Application process
Where: Campus
Eligibility: 7 CGPA
Resume Tip
Resume tip

Tip 1 : Try to include at least one development project in your resume.
Tip 2 : Interviewer will ask anything from your resume so be prepared for it.
Tip 3 : Don't mention some random projects which you are not sure about or copied from Google or somewhere else.

Interview rounds

01
Round
Easy
Online Coding Interview
Duration180 Minutes
Interview date7 Sep 2021
Coding problem2

The first round was based on algorithms, pseudo-codes, 2-3 questions from DBMS and CN, 3 coding questions, and 3 DBMS queries.

1. NINJA ATTACK

Moderate
35m average time
65% success
0/80
Asked in companies
CognizantInfosysIBM

Ninja has built his team of ninjas to fight with the enemies in his city. Ninja made a plan of attacking all his enemies. In his team, every ninja has his own range of hitting and they had secretly got the hitting range of their enemies as well. So Ninja allowed some swaps between his ninjas so that they can minimize the hamming distance that is the number of positions where the hitting range of enemies and ninjas are different.

Your task is to write a code that can minimize the hamming distance. You are being provided with two arrays ‘ninja’ and ‘enemies’ both of the same size and an array ‘allowedSwaps’ where each allowedSwaps[i] = [ ai, bi ] indicates that you are allowed to swap the elements at index ai and index bi.

The Hamming distance of two arrays of the same length, ninja, and enemies, is the number of positions where the elements are different.

Example :

Consider the case ‘ninja’array is [ 1, 2, 3, 4 ], ‘enemies’array is [ 2, 1, 4, 5 ] and ‘allowedSwaps’ are  = [ [ 0, 1 ], [ 2, 3 ] ] so after swapping in best manner according to ‘allowedSwaps’ our ‘ninja’ array becomes [ 2, 1, 4, 3 ]. So minimum Hamming distance is ‘1’ as now there is only one different element as compared to ‘ninja’ and ‘enemies’ array index.
Note :
1. You are allowed to do as many swap operations on the ‘ninja’ array as you want but according to the ‘allowedSwap’ array.
2. You are not required to print anything explicitly. It has already been taken care of. Just implement the function.
Problem approach

Step 1 : Calculate the XOR of two numbers.
Strp 2 : Count the number of set bits.

Try solving now

2. Find Number Of Islands

Moderate
34m average time
60% success
0/80
Asked in companies
AmazonUberApple

You are given a 2-dimensional array/list having N rows and M columns, which is filled with ones(1) and zeroes(0). 1 signifies land, and 0 signifies water.

A cell is said to be connected to another cell, if one cell lies immediately next to the other cell, in any of the eight directions (two vertical, two horizontal, and four diagonals).

A group of connected cells having value 1 is called an island. Your task is to find the number of such islands present in the matrix.

Problem approach

A graph where all vertices are connected with each other has exactly one connected component, consisting of the whole graph. Such a graph with only one connected component is called a Strongly Connected Graph.
The problem can be easily solved by applying DFS() on each component. In each DFS() call, a component or a sub-graph is visited. We will call DFS on the next un-visited component. The number of calls to DFS() gives the number of connected components. BFS can also be used.

Try solving now
02
Round
Medium
Video Call
Duration45 minutes
Interview date5 Oct 2021
Coding problem3

It was a TR+HR round .
The interviewer started with “Tell me about yourself”. Then he asked some Java fundamental questions then he sked me the lifecycle of Software development. In HR round I was asked about what I know about Cognizant why I want to join this particular company, Am i okay with relocation, How can I contribute to companies growth etc.

1. Nth Fibonacci Number

Easy
0/40
Asked in companies
HCL TechnologiesAccentureIBM

The n-th term of Fibonacci series F(n), where F(n) is a function, is calculated using the following formula -

    F(n) = F(n - 1) + F(n - 2), 
    Where, F(1) = 1, F(2) = 1


Provided 'n' you have to find out the n-th Fibonacci Number. Handle edges cases like when 'n' = 1 or 'n' = 2 by using conditionals like if else and return what's expected.

"Indexing is start from 1"


Example :
Input: 6

Output: 8

Explanation: The number is ‘6’ so we have to find the “6th” Fibonacci number.
So by using the given formula of the Fibonacci series, we get the series:    
[ 1, 1, 2, 3, 5, 8, 13, 21]
So the “6th” element is “8” hence we get the output.
Problem approach

step 1 : initilize a = 0 and b = 1
step 2 : for i = 1 to i = n:
print(a)
temp = a+b
a = b
b = temp

Try solving now

2. Puzzle

You live in Dubai and had an infinite supply of oil and a 5 liters and 3 liters jar,
how would you measure exactly 4 liters (of-course in minimum numbers of step) ?

Problem approach

Fill the 5-liter bowl. Then fill the 3-liter bowl from the 5-liter bowl. You will now have 2 liters left in the 5 liter bowl.

Empty the 3-liter bowl, and then transfer the 2 liters from the 5-liter bowl into it.

Now fill the 5-liter bowl again, then pour water carefully from the 5-liter bowl into the 3-liter bowl until it is full - exactly one more liter.

The 5-liter bowl now has exactly 4 liters.

3. Puzzle

You have a birthday cake and have to cut it into 8 equal pieces by making 3 cuts only. How do you do it?

Problem approach

The solution can be divided into 3 basic steps. But apart from this there are also other method of executing this task.
Step 1: Cut the cake into quarters (4 pieces) using 2 of the cuts – one horizontally down the centre of the cake and the other vertically down the centre of the cake. This will leave you with 4 pieces (or slices) of cake.

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

Skill covered: Programming

Which SQL keyword removes duplicate records from a result set?

Choose another skill to practice
Similar interview experiences
company logo
SDE - 1
2 rounds | 6 problems
Interviewed by Cognizant
1237 views
0 comments
0 upvotes
company logo
SDE - 1
2 rounds | 4 problems
Interviewed by Cognizant
709 views
0 comments
0 upvotes
company logo
SDE - 1
2 rounds | 6 problems
Interviewed by Cognizant
1455 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 9 problems
Interviewed by Cognizant
631 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 1
1 rounds | 2 problems
Interviewed by Tata Consultancy Services (TCS)
0 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 4 problems
Interviewed by Tata Consultancy Services (TCS)
5992 views
0 comments
0 upvotes
company logo
SDE - 1
2 rounds | 3 problems
Interviewed by BNY Mellon
5242 views
3 comments
0 upvotes