Problem database last updated: June 20, 2025

CCognizant logo

Cognizant Coding Interview Questions

29 problems · 18 Easy, 10 Medium, 1 Hard · Ranked #66 of 458

Difficulty breakdown

18 Easy

62% · avg 23%

10 Medium

34% · avg 59%

1 Hard

3% · avg 18%

Top topics

array
41.4%
math
27.6%2.2x
string
20.7%
two-pointers
20.7%1.5x
database
17.2%15.4x
sorting
13.8%

Interview profile

Based on 29 reported problems, Cognizant interviews are easier than average - only 3% Hard compared to 18% across all companies.

Compared to the industry average, Cognizant puts unusual emphasis on database (17.2% of problems, 15.4x the industry average), recursion (10.3% of problems, 2.3x the industry average), math (27.6% of problems, 2.2x the industry average). If you're short on time, these are the categories to double down on.

The most common topics are array (41.4%), math (27.6%), string (20.7%), two-pointers (20.7%). Problems below are sorted by frequency, the ones at the top are asked most often.

All 29 problems

Palindrome Number

Solve

Given an integer x, return true if x is a palindrome, and false otherwise.

EasyVery Likely
math

Count Subarrays Of Length Three With A Condition

Solve

Given an integer array nums, return the number of subarrays of length 3 such that the sum of the first and third numbers equals exactly half of the second numbe...

EasyVery Likely
array

Smallest Value of the Rearranged Number

Solve

You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.

MediumVery Likely
mathsorting

Two Sum

Solve

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target.

EasyVery Likely
arrayhash-map

Fibonacci Number

Solve

The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, startin...

EasyVery Likely
mathdynamic-programmingrecursion

Valid Anagram

Solve

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

EasyLikely
hash-tablestringsorting

Longest Palindromic Substring

Solve

Given a string s, return the longest palindromic substring in s.

MediumLikely
two-pointersstringdynamic-programming

Remove Duplicates from Sorted Array

Solve

Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order o...

EasyLikely
arraytwo-pointers

Maximum Subarray

Solve

Given an integer array nums, find the subarray with the largest sum, and return its sum.

MediumLikely
arraydivide-and-conquerdynamic-programming

Reverse Integer

Solve

Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1...

MediumLikely
math

Longest Common Prefix

Solve

Write a function to find the longest common prefix string amongst an array of strings.

EasyLikely
arraystringtrie

Valid Parentheses

Solve

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

EasyLikely
stringstack

Second Highest Salary

Solve

Table: Employee

MediumLikely
database

Product Sales Analysis I

Solve

Table: Sales

EasyLikely
database

Managers with at Least 5 Direct Reports

Solve

Table: Employee

MediumLikely
database

Count Primes

Solve

Given an integer n, return the number of prime numbers that are strictly less than n.

MediumLikely
arraymathenumeration

Students and Examinations

Solve

Table: Students

EasyLikely
database

Median of Two Sorted Arrays

Solve

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

HardLikely
arraybinary-searchdivide-and-conquer

Binary Search

Solve

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then ret...

EasyLikely
arraybinary-search

Merge Two Sorted Lists

Solve

You are given the heads of two sorted linked lists list1 and list2.

EasyLikely
linked-listrecursion

Search Insert Position

Solve

Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were ins...

EasyLikely
arraybinary-search

Move Zeroes

Solve

Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.

EasyLikely
arraytwo-pointers

Fizz Buzz

Solve

Given an integer n, return a string array answer (1-indexed) where:

EasyLikely
mathstringsimulation

Rising Temperature

Solve

Table: Weather

EasyLikely
database

3Sum

Solve

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

MediumLikely
arraytwo-pointerssorting

Longest Substring Without Repeating Characters

Solve

Given a string s, find the length of the longest substring without duplicate characters.

MediumLikely
hash-tablestringsliding-window

Add Two Numbers

Solve

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a sing...

MediumLikely
linked-listmathrecursion

Merge Sorted Array

Solve

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and num...

EasyLikely
arraytwo-pointerssorting

Happy Number

Solve

Write an algorithm to determine if a number n is happy.

EasyLikely
hash-tablemathtwo-pointers

How often are these problems asked?

Frequency scores are based on crowdsourced interview reports. A higher score means the problem has been reported more often in recent Cognizant interviews.

Very Likely

75-100%

Likely

50-74%

Sometimes

25-49%

Rare

0-24%

Preparing for your Cognizant coding interview

Cognizant interviews focus heavily on array, math, string problems. If you're short on time, these are the categories to prioritize. The problems on this page are sorted by frequency, so start from the top and work your way down.

Beyond solving problems, practice explaining your approach. Cognizant interviewers care about your thought process - how you break down a problem, consider edge cases, and evaluate tradeoffs between solutions. A clean O(n) solution you can explain clearly beats an O(log n) solution you can't articulate.

Looking for more companies? Browse all 458 companies in our directory, or sharpen your fundamentals with our free data structure visualizers and AI-powered DSA tutor.

Frequently Asked Questions

What coding problems does Cognizant ask in interviews?add

Cognizant has been reported to ask 29 distinct coding problems. The most common topics are array, math, string. 18 are Easy difficulty, 10 are Medium, and 1 are Hard. Problems are sorted by frequency - the ones at the top are asked most often.

How hard are Cognizant coding interviews?add

Based on 29 reported problems, Cognizant interviews are easier than average - only 3% Hard compared to 18% across all companies. 34% of questions are Medium difficulty. Focus on the high-frequency Medium problems first, then work through the Hard ones.

How should I prepare for a Cognizant coding interview?add

Start with the highest-frequency problems listed on this page. Focus on the core topics: array, math, string. Practice solving them under time pressure and explaining your approach out loud. Mock interviews with AI can simulate the real experience.

Other companies to explore

Ready to ace your Cognizant interview?

Simulate a real Cognizant coding interview with an AI interviewer. Get a scorecard with specific feedback on your problem-solving, code quality, and communication.

Simulate a Cognizant interview with AIarrow_forward