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

Genc Next

Cognizant
upvote
share-icon
3 rounds | 8 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 3 months
Topics: Data Structures, Pointers, OOPS, System Design, Algorithms, Dynamic Programming
Tip
Tip

Tip 1 : Be Consistent 
Tip 2 : Do at least 1projects based on MEAN or MERN Stack
Tip 3 : Practice Striver Sheet

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

Tip 1 : Add Projects, Certification detail
Tip 2 : Try to question yourself from each and every point from resume and prepare answers

Interview rounds

01
Round
Medium
Online Coding Interview
Duration120 minutes
Interview date15 Sep 2020
Coding problem2

This round consist of 2 part:
1st was MCQs(60 minutes)
2nd part was Coding(60 minutes)

1. Armstrong Number

Easy
15m average time
85% success
0/40
Asked in companies
OracleIBMOptum

You are given an integer ‘NUM’ . Your task is to find out whether this number is an Armstrong number or not.

A k-digit number ‘NUM’ is an Armstrong number if and only if the k-th power of each digit sums to ‘NUM’.

Example
153 = 1^3 + 5^3 + 3^3.

Therefore 153 is an Armstrong number.
Problem approach

The idea is to first count number digits (or find order). Let the number of digits be n. For every digit r in input number x, compute rn. If sum of all such values is equal to n, then return true, else false.

Try solving now

2. Sort Array

Moderate
15m average time
85% success
0/80
Asked in companies
HSBCOYOCognizant

You are given an array consisting of 'N' positive integers where each integer is either 0 or 1 or 2. Your task is to sort the given array in non-decreasing order.

Note :
1. The array consists of only 3 distinct integers 0, 1, 2.
2. The array is non-empty.
Problem approach

Count the number of 0s, 1s and 2s in the given array. Then store all the 0s in the beginning followed by all the 1s then all the 2s.

Algorithm: 
Step 1:Keep three counter c0 to count 0s, c1 to count 1s and c2 to count 2s
Step 2:Traverse through the array and increase the count of c0 if the element is 0,increase the count of c1 if the element is 1 and increase the count of c2 if the element is 2
Step 3:Now again traverse the array and replace first c0 elements with 0, next c1 elements with 1 and next c2 elements with 2.

Try solving now
02
Round
Hard
Online Coding Test
Duration120 minutes
Interview date2 Oct 2020
Coding problem4

Timing: Evening,
In this round, 4 programming questions of moderate to hard level from the topics Trees, Graphs, Linked Lists, etc.

1. Sort 0 1

Moderate
0/80
Asked in companies
AccentureMorgan StanleyTata Consultancy Services (TCS)

You have been given an integer array/list(ARR) of size N that contains only integers, 0 and 1. Write a function to sort this array/list. Think of a solution which scans the array/list only once and don't require use of an extra array/list.

Note:
You need to change in the given array/list itself. Hence, no need to return or print anything. 
Problem approach

1. Take two pointer type0(for element 0) starting from beginning (index = 0) and type1(for element 1) starting from end (index = array.length-1). 
Initialize type0 = 0 and type1 = array.length-1 
2. It is intended to Put 1 to the right side of the array. Once it is done, then 0 will definitely towards the left side of the array.

Try solving now

2. Maximum Distance

Easy
19m average time
85% success
0/40
Asked in companies
CognizantEmevest TechnologiesCaterpillar Inc

You have been given an array ‘ARR’ that might contain duplicate elements. Your task is to find the maximum possible distance between occurrences of two repeating elements i.e. elements having the same value. If there are no duplicate elements in the array, return 0.

Try solving now

3. Maximum Product Subarray

Moderate
25m average time
75% success
0/80
Asked in companies
AmazonMicrosoftSamsung

You are given an array “arr'' of integers. Your task is to find the contiguous subarray within the array which has the largest product of its elements. You have to report this maximum product.

An array c is a subarray of array d if c can be obtained from d by deletion of several elements from the beginning and several elements from the end.

For e.g.- The non-empty subarrays of an array [1,2,3] will be- [1],[2],[3],[1,2],[2,3],[1,2,3]. 
For Example:
If arr = {-3,4,5}.
All the possible non-empty contiguous subarrays of “arr” are {-3}, {4}, {5}, {-3,4}, {4,5} and {-3,4,5}.
The product of these subarrays are -3, 4, 5, -12, 20 and -60 respectively.
The maximum product is 20. Hence, the answer is 20.
Follow Up:
Can you solve this in linear time and constant space complexity?
Problem approach

int maxSubarrayProduct(int arr[], int n)
{
// max positive product
// ending at the current position
int max_ending_here = 1;

// min negative product ending
// at the current position
int min_ending_here = 1;

// Initialize overall max product
int max_so_far = 0;
int flag = 0;
/* Traverse through the array.
Following values are
maintained after the i'th iteration:
max_ending_here is always 1 or
some positive product ending with arr[i]
min_ending_here is always 1 or
some negative product ending with arr[i] */
for (int i = 0; i < n; i++)
{
/* If this element is positive, update
max_ending_here. Update min_ending_here only if
min_ending_here is negative */
if (arr[i] > 0)
{
max_ending_here = max_ending_here * arr[i];
min_ending_here
= min(min_ending_here * arr[i], 1);
flag = 1;
}

/* If this element is 0, then the maximum product
cannot end here, make both max_ending_here and
min_ending_here 0
Assumption: Output is alway greater than or equal
to 1. */
else if (arr[i] == 0) {
max_ending_here = 1;
min_ending_here = 1;
}

/* If element is negative. This is tricky
max_ending_here can either be 1 or positive.
min_ending_here can either be 1 or negative.
next max_ending_here will always be prev.
min_ending_here * arr[i] ,next min_ending_here
will be 1 if prev max_ending_here is 1, otherwise
next min_ending_here will be prev max_ending_here *
arr[i] */

else {
int temp = max_ending_here;
max_ending_here
= max(min_ending_here * arr[i], 1);
min_ending_here = temp * arr[i];
}

// update max_so_far, if needed
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
}
if (flag == 0 && max_so_far == 0)
return 0;
/* if all the array elements are negative */
if (max_so_far == 1)
{
max_so_far = arr[0];
for(int i = 1; i < n; i++)
max_so_far = max(max_so_far, arr[i]);
}
return max_so_far;
}

Try solving now

4. Find Number Of Islands

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

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

The solution is inspired by finding the total number of connected components in a graph problem. The idea is to start Breadth–first search (BFS) from each unprocessed node and increment the island count. Each BFS traversal will mark all cells which make one island as processed. So, the problem reduces to finding the total number of BFS calls.

In each BFS traversal, start by creating an empty queue. Then enqueue the starting cell and mark it as processed. Next dequeue the front node, process all eight adjacent cells of the current cell, and enqueue each valid cell, which is land. Repeat this process till the queue is not empty.

We can find all the possible locations we can move to from the given location by using the array that stores the relative position of movement from any location.

Try solving now
03
Round
Medium
Video Call
Duration50 mintes
Interview date15 Oct 2020
Coding problem2

Interviewer: Introduce Yourself
Me: Gave a brief intro.
Interviewer: Which projects have you done? (asked me about the project mentioned in my resume).
Me: Gave an explanation of my ML projects.
Interviewer: What are the modern/ the latest technologies that are trending in IT?
Me: ML, DataScience, IOT, BlockChain, etc.
Interviewer: Can you give a real-life example of where Machine Learning is used.
Me: Gave an example of a social media website.
 

1. DBMS Questions

They gave me one problem statement and asked me to write a query.

Write a query to retrieve Departments who have less than 2 employees working in it.
What do you know about SQL?
What are Dml DDL command’s
Constraints in SQL
What is a subquery

Problem approach

SELECT DEPARTMENT, COUNT(EmpID) as 'EmpNo' FROM EmployeeInfo GROUP BY DEPARTMENT HAVING COUNT(EmpD) < 2;

2. Technical Questions

Difference between C++ and Java
4 pillars of OOP
Difference between abstraction and encapsulation.
Difference between JRE, JDK, and JVM.
Why Java is a platform-independent language and what is bytecode?
Situational questions like if a machine is having JRE but not JDK, it will run or not or vice versa.

Here's your problem of the day

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

Skill covered: Programming

To make an AI less repetitive in a long paragraph, you should increase:

Choose another skill to practice
Similar interview experiences
company logo
Genc Next
2 rounds | 5 problems
Interviewed by Cognizant
1249 views
0 comments
0 upvotes
company logo
Genc Next
2 rounds | 7 problems
Interviewed by Cognizant
1733 views
0 comments
0 upvotes
company logo
Genc Next
3 rounds | 6 problems
Interviewed by Cognizant
867 views
0 comments
0 upvotes
company logo
Genc Next
3 rounds | 9 problems
Interviewed by Cognizant
1064 views
0 comments
0 upvotes