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

Genc Next

Cognizant
upvote
share-icon
2 rounds | 5 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 1 month
Topics: Data structures, OOPS, Algorithms, Puzzles, DBMS
Tip
Tip

Tip 1 : Practice 50 puzzle questions
Tip 2 : Practice Arrays and and string questions

Application process
Where: Campus
Eligibility: Above 7 CGPA, No backlogs
Resume Tip
Resume tip

Tip 1 : Include 1 internship of at least 3 months
Tip 2 : Include at least 2 projects in your resume

Interview rounds

01
Round
Medium
Online Coding Test
Duration180 minutes
Interview date8 Aug 2021
Coding problem3

This round had 5 questions to be solved

1. Count the occurrences of all the words in a string

Moderate
20m average time
80% success
0/80
Asked in companies
MicrosoftCognizantHCL Technologies

Ninja and his friend playing a game in which his friend gave him a string ‘STR’ that can contain spaces and a List/Array ‘WORDS’ which is of type string containing ‘N’ strings of words. Ninja’s task is to count the occurrences of all the words in ‘STR’.

For Example:

‘STR’ = “i am a Ninja”, ‘N’ = 3 and ‘WORDS[]’ = [“Ninja”,”a”,”am”]. Then the output should be [1,1,1]. Because the occurrence of “Ninja” in ‘STR’ is 1 and the occurrence of “a” in ‘STR’ is 1.Similarly occurrence of “am” is 1.

Note:

The output should be in the same order as given in ‘WORDS’.

Can you help Ninja to generate all valid strings from ‘STR’ by minimum removals?

Problem approach

I iterated over the sentence and broke it using the spaces. I then used a hashmap to store all the words and iterate there count if it came in sentence more than once

Try solving now
Moderate
25m average time
70% success
0/80
Asked in companies
CognizantAppleUber

You are given a string ‘S’ consisting of lowercase alphabets, “(“ and “)”. You need to remove the minimum number of parentheses to make the string valid and print that valid string.

A string is valid iff:

1. It is an empty string, it contains lowercase alphabets only, or
2. It can be written as (S), where ‘S’ is the valid string.
3. It can be written as AB (‘A’ concatenated with ‘B’), where ‘A’ and ‘B’ are valid strings.
For example :
Let string be: “co(di()ng”
The valid string can be: “co(di)ng” or “codi()ng”.
Problem approach

The basic idea is to store the indices of the brackets that are not balanced in a stack. We also maintain a hashmap to store the indices that need to be removed. We traverse the string and push open brackets in the stack. If the current character is ‘)’, we check whether the top element is an open bracket and pop it else, we add the current character index in the map. We also add the indices that are present in the stack. We print the valid string without adding the index present in the map.

Try solving now

3. Find Palindromes

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

You are given an integer ‘N’. Your task is to find all palindromic numbers from 1 to ‘N’.

Palindromic integers are those integers that read the same backward or forwards.

Note:
Order of numbers should be in the non-decreasing matter.
For example:
You are given ‘N’ as 12, so the output should be [1, 2, 3, 4, 5, 6, 7, 8, 9, 11], as all single-digit numbers are palindromic, and 11 is also a palindromic number.
Problem approach

In this approach, we try to create all the palindrome integers till N. To create the palindromes of odd length, we remove the last digit from the number and add the remaining digits in reverse order to the previous digits. To generate the palindrome of even length, we add the reverse of the current number to its digits.

Try solving now
02
Round
Easy
Video Call
Duration90 minutes
Interview date8 Sep 2021
Coding problem2

It was a fairly easy round and was around basic data structures. He also asked about the projects I had and which languages I have previously worked on

1. Sort any given array using bubble sort

Easy
10m average time
90% success
0/40
Asked in companies
OptumAccentureWells Fargo

Bubble Sort is one of the sorting algorithms that works by repeatedly swapping the adjacent elements of the array if they are not in sorted order.

You are given an unsorted array consisting of N non-negative integers. Your task is to sort the array in non-decreasing order using the Bubble Sort algorithm.

For Example:
Bubble Sort implementation for the given array:  {6,2,8,4,10} is shown below :-

Alt test

Problem approach

I applied the bubble sort where I used 2 nested and compared the numbers in the loop. I swapped the numbers if the latter was smaller than the former

Try solving now

2. Write a program to tell if the given number is prime or not

Easy
0/40
Asked in companies
Tata Consultancy Services (TCS)ShareChatCognizant

Write a Program to check whether the given number N is prime or not.

For a given number N check if it is prime or not. A prime number is a number that is only divisible by 1 and itself.
Problem approach

I ran a for loop until the square root of the number. In the for loop I check if any number smaller than that is completely divisble by the given number by using modulus. If yes then the number is not prime. If not then number is prime

Try solving now

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
1734 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