Cognizant GenC Elevate Coding Questions 2025

GenC Elevate Coding Questions for 2025 graduates

This section is the most important part of the Cognizant GenC Elevate Hiring. Cognizant programming test Questions are of moderate difficulty, in this post you will find all the most important and latest pattern based sample Cognizant GenC Elevate Coding Questions with their solutions.

GenC Elevate Coding Questions

Detailed Analysis for CTS GenC Elevate Coding Questions

This will be the second section of GenC Elevate online test. In this section you will have to solve a total of 4 coding questions in 60 mins. The difficulty level of the questions will range from moderate to high. In previous year online test, Cognizant restricted the students to use only Java and Python for solving the coding questions, although there is no such official announcement this time now, we recommend you give more emphasis on these coding languages.

Gen C Elevate Coding RoundDetails 
Number of Questions4 Questions 
Time Duration60 Minutes 
ImportanceHigh 

Below we have provided some sample practice questions based on the pattern of Cognizant Coding Questions for GenC Elevate, make sure you practice all of them while preparing for GenC Elevate online test.

 

Practice Questions for Cognizant GenC Elevate Coding Round

Question 1

You want to buy a particular stock at its lowest price and sell it later at its highest price. Since the stock market is unpredictable, you steal the price plans of a company for this stock for the next N days.
Find the best price you can get to buy this stock to achieve maximum profit.

Note: The initial price of the stock is 0.

Input Specification:

Input1: N, number of days
Input2: Array representing change in stock price for the day.

Output Specification:

Your function must return the best price to buy the stock at.

Example1:

Input1: 5
Input2: (-39957,-17136,35466,21820,-26711}
Output: -57093
Explanation: The best time to buy the stock will be on Day 2 when the price of the stock will be -57093.

Example2:

Input1: 5
Input2: (-39957, -17136, 1, 2, -26711)
Output: -80801
Explanation: The best time to buy the stock will be on Day 5 when the price of the stock will be -83801.

Example3:

Input1: 9
Input2: (-4527,-1579,-38732,-43669,-9287,-48068,-30293,-30867,18677}
Output: -207022
Explanation: The best time to buy the stock will be on Day 8 when the price of the stock will be -207022.

Question 2

Given a positive whole number n, find the smallest number which has the very same digits existing in the whole number n and is greater than n. In the event that no such certain number exists, return – 1.

Note: that the returned number should fit in a 32-digit number, if there is a substantial answer however it doesn’t fit in a 32-bit number, return – 1.

Example 1:

Input: n = 12
Output: 21
Explanation: Using the same digit as the number of permutations, the next greatest number for 12 is 21.

Example 2:

Input: n = 21
Output: -1
Explanation: The returned integer does not fit in a 32-bit integer

Question 3

Henry is extremely keen on history and every one of the ages of his family. He does a ton of exploration and understands that he has plummeted from the incomparable Amaya line. After a ton of looking through old records and the most recent records of the general public, he can discover all the parent-kid connections in his family right from the extraordinary ruler Ming of the tradition to himself.

These connections are given in the structure of a direct exhibit where the emperor is at the main position and his kids are at pos (2i + 1) and (2i + 2)

This is the pattern followed throughout.

Henry needs to sort out every one of the kin of individual X from the information.

Write a program for Henry to figure out all the siblings of person X from the data.
Return the sorted list of all of Henry’s siblings.

If no sibling return {-1}

  • input 1: N, the length of the array
  • input2: An array representing the ancestral tree
  • input 3: X, the person whose siblings are sought.
  • output – return the array of all siblings in increasingly sorted order.

Example 1 :

input 1: 5
input 2: {1,2,3,4,5}
input 3: 1
output: {-1}
Explanation: x is the root of the tree and has no siblings

Example 2 :

input 1: 6
input 2: {1,2,3,4,5,6}
input 3: 5
output: {4,6}
Explanation: {2,3 } are the children of {1}. {4,5,6 } are the children of {2,3}, thus the siblings of x= 5 are {4,6}

Question 4

Rohan and his team are participating in the Treasure Hunt event of college in which in each step they have to solve one problem to get a clue about the Treasure location. Rohan’s team has performed very well and reached the final step where they have to provide a code of a problem to get a final clue about treasure .

Given a string s, they need to find the longest palindromic subsequence’s length in s.
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

The string contains only lowercase letters.

Write a program to help Rohan’s team that takes in input as String x and returns the length of the longest palindromic subsequence of x.

Input Specification:

input1: string input

Output Specification:

Return the length of the longest palindromic subsequence

Example 1:

Input: s = “bbbab”
Output: 4
Explanation: One possible longest palindromic subsequence is “bbbb”.

Example 2:

Input: s = “cbbd”
Output: 2
Explanation: One possible longest palindromic subsequence is “bb”.

Question 5

Given a number n, the task is to find the remainder when n is divided by 11. The input number may be very large.

Since the given number can be very large, you can not use n % 11.

Input Specification:

inputs a large number in the form of a string

Output Specification:

Return the remainder modulo 11 of input1

Example1:

Input: str = 13589234356546756
Output: 6

Example2:

Input: str = 3435346456547566345436457867978
Output: 4

Example3:

input: str = 121
Output: 0

Question 6

Jasleen has bought a new bulb factory. The factory has a single file of machines, numbered from 1 to N. Each machine has a certain number of fully prepared bulbs.
Jasleen has a rule she wants to follow. She wants to collect an equal amount of bulb from
each machine from which she collects bulbs.

Jasleen can start collecting bulb from any machine, but once she starts collecting, she collects
from every consecutive machine until she reaches the last machine she wants to collect from. Find the maximum number of bulbs she can collect.

Input Specification:
Input1: N, the number of machines
Input2: An array of N elements (a1,a2 a3……aN], denoting the number of fully prepared bulbs in each machine of the factory.

Output Specification:
An integer output denoting the maximum number of bulbs that Allie can collect.

Example 1:
input1: 3
Input2: [1,2,3]

Output: 3

Example 2:
input1: 4
Input2: [5,8,9,10]

Output: 20

Question 7

An astrologer gives a matrix to devilliers and tells him to add a largest row sum and largest column sum of the given matrix.The number which appears as a result is his lucky number for the final match jersey.

Write a program that adds up the largest row sum and the largest column sum from an N- rows*M-columns array of numbers to help devilliers for finding his lucky number for the final match jersey.

As a preliminary phrase , you should reformat the sequence of numbers as a matrix, whose number of rows and columns are to be specified as arguments.

Input Specification:

  • Input 1: Integer for row dimension of the array
  • Input 2: Integer for column dimension of the array
  • Input 3: Array elements to be entered in row major.

Output Specifications:

  • Largest row sum+ Largest column sum

Example 1:
Input1:4
Input2: 4
Input3: {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4}

Output: 26

Explanation:
The array has 4 rows (input1) and 4 columns (input2). The largest sum among the four columns is 10 and the largest sum among the four rows is 16. We get the final sum of 26 (10+16).

Example 2:
Input1:2
Input2: 2
Input3: {1,2,5,6}

Output: 19

Explanation:

The array has 2 rows (input1) and 2 columns (input2). The elements in the first row are 1 and 2 and the elements in the second row are 5 and 6 (input3). The largest sum among the two columns is 8(2+6) By adding those two up. We get the final sum of 19 (11+8).

Example 3:
Input1: 3
Input2: 3
Input3: {3,6,9,1,4,7,2,8,9}

Question 8

Williamson is an analyst he needs to analyse a particular topic for performing analysis for that he needs to find a permutation of a given object.He don’t know how to find permutation so for simplifying his work he is hiring one software developer who can code for him and find a permutation and combination of a given object.

Consider you are giving an interview to williamson for working with him. Find a permutation of given input to proof that you are fit for his requirement.

Input Specification:
nCr where n and r are numbers given by Williamson to you
nCr is defined as n! / (r! x (n-r)!)

Here, n! denotes the factorial of a number. Also, you have to calculate this number as modulo
Input Specification:

  • input1: The number n.
  • Input2: The number r.
  • Input3: The number m,
    .

Output specification:

  • The value of nCr%m.

Example 1:
Input1: 3
Input2: 2
Input3: 10000000009

Output:3

Explanation:
n=3.r=2,m=100 So, n!=3!=6, r!=2!=2, (n-1)!= 1!=1.
So, nCr = (6/(2*1))%1000000009= 3.

Example 2:
input1: 5
input2: 2
input3: 1000000009

Output: 10

Explanation:
n=5,r=2, m=100 So, n!=5!=120, r!=2=2, (n-1)!= 3!=6.
So, nCr = (120/(2*6))%1000000009= 10.

Question 9

A Derangement is a permutation of n elements, such that no element appears in its original position.
For example, a derangement of {0, 1, 2, 3} is {2, 3, 1, 0}.
Given a number n, find the total number of Derangements of a set of n elements.

Input Specification:
input1: N, the number of Objects

Output Specification:
Return the number of arrangements in which no object occurs at its original
position

Example 1:

Input: n = 2
Output: 1
For two elements say {0, 1}, there is only one possible derangement {1, 0}

Example 2:

Input: n = 3
Output: 2
For three elements say {0, 1, 2}, there are two possible derangements {2, 0, 1} and {1, 2, 0}

Example 3:

Input: n = 4
Output: 9
For four elements say {0, 1, 2, 3}, there are 9 possible derangements {1, 0, 3, 2} {1, 2, 3, 0} {1, 3, 0, 2}, {2, 3, 0, 1}, {2, 0, 3, 1}, {2, 3,1, 0}, {3, 0, 1, 2}, {3, 2, 0, 1} and {3, 2, 1, 0

Question 10

Vira writes an apology letter to anu. However, before Anu can read it, Vira’s enemy Rohan takes it and rotates the characters of each word left to right N times. Find the number of words that remain the same even after this shifting of letters.

Input Specification:

  • input1: String of words
  • input2: N, number of times rotation happens

Output Specification:

  • Your function should return the number of correct words.

Example 1:

input1: llohe ereth
input2: 2

Output : 2

Example 2:

input1: Sorry
input2: 2

Output : 0

Question 11

After Watching a movie at PVR, Adil is pondering over the number of ways in which he can pay for the movie. He has x1, x2, x3, x4 coins of values 1,2,5 and 10 respectively. He wants to determine the number of ways in which he can pay an amount A.

You need to fill in a function that returns the number of ways to pay total amount

Input Specifications:

Input 1: An integer value denoting the total amount to be paid

Output Specification:
Return an Integer value denoting the number of ways to pay the total amount

Example1:
Input1: 40
Output : 195

Example2:
Input1: 4
Output : 3