The Cognizant coding tasks live inside the technical assessment — roughly three problems in 105–120 minutes depending on your cluster, written in Java (Cluster 1) or Python (Cluster 2). The problems are implementation-heavy: strings, arrays, recursion and the occasional pattern-printing task, with SQL queries alongside.
What Cognizant coding questions test
- String manipulation — reversal without built-ins, pattern printing
- Arrays and optimization — single-pass maximum profit, min/max tracking
- Recursion and backtracking — decoding digit strings, combinations
- Sorting — Merge Sort implementation and complexity
- OOP demonstrations in Java (Cluster 1) — the four pillars in code
- Reading input and printing output exactly as specified
Practice real Cognizant coding problems
These problems appeared in memory-based Cognizant papers. Try each one yourself before revealing the approach — solutions are provided in Python, Java and C++.
Write a program to reverse a given string without using any in-built reverse functions. Read the string from input and print its reverse.
Input: cognizant
Output: tnazingoc
Every character is emitted in the opposite order — no library reverse() allowed.
- 1 ≤ |S| ≤ 10^5
- S contains printable characters without spaces
Ratan buys a share at a low price and sells it later at a high price to maximize his profit. Given an array of stock prices where prices[i] is the price on day i, write a program to calculate the maximum profit Ratan can earn from a single buy-and-sell transaction. The share must be bought before it is sold. If no profit is possible, print 0.
Input: prices = [3, 1, 4, 8, 7, 11, 2]
Output: 10
Buy at 1 (day 2) and sell at 11 (day 6) for a profit of 10.
Input: prices = [9, 7, 5, 3]
Output: 0
Prices only fall, so no profitable transaction exists.
- 1 ≤ N ≤ 10^5
- 0 ≤ prices[i] ≤ 10^9
Elliot made a keylogger that records only the numeric values of keys ('a' = 1, 'b' = 2, … 'z' = 26). For a given numeric string, print all possible alphabetical password combinations in lexicographical order. A digit group is valid only if it maps to 1–26 (no leading zeros).
Input: 1234
Output: abcd awd lcd
Valid splits: 1|2|3|4 → abcd, 1|23|4 → awd, 12|3|4 → lcd. (34 > 26, so 3 and 4 cannot combine.)
- 1 ≤ |S| ≤ 20
- S contains only digits
Aiming for GenC Next? Interviewers push past the code into why — complexity, edge cases, and lately how you use AI tools responsibly while coding. Rehearse explaining your approach out loud before the technical interview.

