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

GenC

Cognizant
upvote
share-icon
2 rounds | 5 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 2 months
Topics: Data Structures, DBMS , OOPS, System Design, Algorithms, Dynamic Programming, parsing.
Tip
Tip

Tip 1 - Practice At least 150 Questions of DS algo
Tip 2 - Try to do application based projects 
Tip 3 - Optimize your answers to reduce run time

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

Tip 1 : Be true on your resume
Tip 2 : Make your resume short and crisp
Tip 3 : Include information sequentially.

Interview rounds

01
Round
Medium
Online Coding Interview
Duration120 minutes
Interview date13 Oct 2021
Coding problem2

MCQs- Aptitude + Quantitative
2 questions came in coding round

1. Find the minimum cost to reach destination using a train

Moderate
20m average time
80% success
0/80
Asked in companies
GrowwCognizantMedia.net

There are ‘N’ stations on the route of a train. The train goes from station 0 to ‘N’ - 1. The ticket cost for all pairs of stations (i, j) is given where ‘j’ is greater than ‘i’. Your task is to find the minimum cost to reach the Nth station.

Note:

Cost of entries where j < i  will be represented as INT_MAX VALUE which is 10000 in the price matrix.
Example:
If ‘N’ = 3

'PRICE[3][3]' = {{0, 15, 80,},
               {INF, 0, 40},
               {INF, INF, 0}};

First, go from 1st station to 2nd at 15 costs, then go from 2nd to 3rd at 40. 15 + 40 = 55 is the total cost.It is cheaper than going directly from station 1 to station 3 as it would have cost 80.

The output will be 55.
Try solving now

2. Alice and her love for Strings.

Easy
10m average time
90% success
0/40
Asked in companies
AdobeTata Consultancy Services (TCS)Cognizant

Alice loves string and Bob being her best friend wants to gift a beautiful string to Alice on her birthday. He knows that Alice loves her childhood string ‘A’ and would love to get a new string similar to the string ‘A’.

Somehow Bob convinced one of his friends to send him a random string ‘B’. Now Bob will have to change the random string ‘B’ to make it equal to string ‘A’ so that he can gift this string to Alice on her birthday. But changing the string is a very tedious process. He can change one character of the string to any other character in a single step.

Now he wonders if it is even possible to change the string ‘B’ to string ‘A’ by using at most ‘K’ steps? Can you help Bob figure out if it is even possible to do so under given constraints?

Problem approach

Given

N = 5
Strings are ["aaa", "hack", "zzz", "abcd", "szxp"]
Approach

There must be a minimum of 3 strings that Alice could have started with to end up with the given final array. Note that "aaa" and "zzz" are encodings of each other, so at least one of them must have been present in the original array. Similarly, at least one of "hack" and "szxp" must have been present. "abcd" does not have its encoding in the final array so it is guaranteed to be present in the original array and did not get encoded.

Here are all the 9 ways that Alice could have ended up with the final array:

Alice started with 5 strings: ["aaa", "hack", "zzz", "abcd", "szxp"] and none of them got encoded.
Alice started with 4 strings: ["aaa", "hack", "abcd", "szxp"] and only "aaa" got encoded to "zzz".
Alice started with 4 strings: ["zzz", "hack", "abcd", "szxp"] and only "zzz" got encoded to "aaa".
Alice started with 4 strings: ["zzz", "hack", "abcd", "aaa"] and only "hack" got encoded to "szxp".
Alice started with 4 strings: ["zzz", "szxp", "abcd", "aaa"] and only "szxp" got encoded to "hack".
Alice started with 3 strings: ["aaa", "szxp", "abcd"] with "aaa" and "szxp" getting encoded to "zzz" and "hack" respectively.
Alice started with 3 strings: ["zzz", "szxp", "abcd"] with "zzz" and "szxp" getting encoded to "aaa" and "hack" respectively.
Alice started with 3 strings: ["aaa", "hack", "abcd"] with "aaa" and "hack" getting encoded to "zzz" and "szxp" respectively.
Alice started with 3 strings: ["zzz", "hack", "abcd"] with "zzz" and "hack" getting encoded to "aaa" and "szxp" respectively.
The minimum number of strings Alice could have started with is 3, so the answer is 3.

Try solving now
02
Round
Medium
Face to Face
Duration30 minutes
Interview date11 Nov 2021
Coding problem3

Basic Hr Questions were asked. I was also asked about some questions from DS algo + from my projects. I was also asked questions from DBMS

1. Reverse String

Moderate
0/80
Asked in companies
Info Edge India (Naukri.com)Livekeeping (An IndiaMART Company)IBM

You are given a string ‘S’. You are also given ‘M’ integers in an array ‘A’. You perform ‘M’ operations on this string. The operations are given in an array ‘A’ of size ‘M’.

You perform the operations in the order they appear in the array ‘A’. In the ‘i’th operation, you reverse the substring of ‘S’ from the position ‘A[i]’ to ‘len(S)’ - ‘A[i]’ - 1 (0 based).

Your task is to find the string after performing all the operations.

Example :
‘S’ = “aabcd”, ‘M’ = 2, ‘A’ = [0, 1]
After 1st operation i.e, reversing from [0, 4], ‘S’ = “dcbaa”.
After 2nd operation i.e, reversing from [1, 3], ‘S’ = “dabca”.
Hence, the answer is “dabca”.
Problem approach

1.Initiate
2.The string which is to be reversed is declared.
3.Get the length of the string.
4.Start a loop and then swap the position of the array elements.
5.Keep the exchanged positions.
6.Print the reversed string.

Try solving now

2. Regular Expression Matching

Hard
25m average time
80% success
0/120
Asked in companies
FacebookGrowwSAP Labs

Given an input string 'S' and a pattern 'P', implement a regular expression matching with the support of two special characters ‘.’ (dot) and ‘*’(asterisk) where

1. ‘.’ matches to any single character.
2. ‘*’ matches to zero or more of the preceding element.

If the input string 'S' matches the pattern 'P', then return true else, return false.

Note:
1. You have to match the entire string with the pattern given.

2. Both the strings, 'S' and 'P' contain only lower-case alphabets.

3. Only the pattern will contain additional characters ‘*’ and ‘.’ along with alphabets.
Try solving now

3. Find All Anagrams in a String

Easy
15m average time
85% success
0/40
Asked in companies
IntuitPaytm (One97 Communications Limited)Accenture

You have been given a string STR and a non-empty string PTR. Your task is to find all the starting indices of PTR’s anagram in STR.

An anagram of a string is another string which contains the same characters and is obtained by rearranging the characters.

For example: ‘SILENT’ and ‘LISTEN’ are anagrams of each other. ‘ABA’ and ‘ABB’ are not anagram because we can’t convert ‘ABA’ to ‘ABB’ by rearranging the characters of particular strings.

Note:

1. Both STR and PTR consist of English uppercase letters.
2. Length of string 'STR' will always be greater than or equal to the length of string ‘PTR’.
3. In case, there is no anagram substring, then return an empty sequence.
4. In case of more than one anagrams, return the indices in increasing order.
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
2 rounds | 3 problems
Interviewed by Cognizant
1083 views
0 comments
0 upvotes
company logo
GenC
2 rounds | 5 problems
Interviewed by Cognizant
876 views
0 comments
0 upvotes
company logo
Program Analyst
2 rounds | 6 problems
Interviewed by Cognizant
604 views
0 comments
0 upvotes
company logo
Programmer Analyst Trainee
3 rounds | 8 problems
Interviewed by Cognizant
773 views
0 comments
0 upvotes