Interview
TCS CodeVita Previous Year Questions With Solutions: 10 Patterns to Practise
CodeVita previous year questions by pattern: 10 recurring problem types, key insights, complexity, five original Python solutions and a topic table.

Practise the rounds for TCS CodeVita
Short answer: CodeVita questions are wordy stories wrapped around a small set of classical patterns: number theory, hashing, sorting with sweeps, DP, grid search and simulation. This page groups the problem types that students commonly report from earlier seasons, explains the insight behind each, and gives five original Python solutions that we ran locally. We do not reproduce TCS problem statements; every example is paraphrased or written fresh.
If you are still deciding whether to enter, start with the TCS CodeVita 2026 preparation guide for dates and eligibility, and the TCS MockVita 2026 guide for the practice contests.
How to use this page
Previous-year problems are useful for one reason: they show you the shape of what gets asked. Memorising a past problem helps almost nothing, because TCS writes new narratives every season. What transfers is recognising "this is a sweep over sorted events" or "this is a sieve plus prefix sums" within two minutes of reading.
A caveat on sourcing. TCS does not publish a full archive on the official portal that we could check, and third-party sites list problems under inconsistent names and seasons. So we describe problem types as candidates report them, and we do not attach a season number to any of them. Treat the frequency table below as our observation of what circulates, not official statistics.
Ten recurring problem types
1. Primes that are sums of consecutive primes
What it asks (paraphrase): given a limit N, count how many numbers up to N are prime and can also be written as the sum of two or more consecutive primes. One third-party blog lists a "Consecutive Prime Sum" problem from the 2020 contest; confirm the exact source before relying on it.
Pattern: sieve plus running sums.
Key insight: sieve once, then extend each starting prime until the running sum passes N. Use a set so a prime reachable two ways is counted once.
Complexity: sieve O(N log log N); the double loop breaks early, so it is roughly O(P x L) where P is the prime count and L the longest useful run.
PYTHON
Check by hand: 5 (2+3), 17 (2+3+5+7), 23 (5+7+11) and eight more up to 97 give 11 for N = 100. We cross-checked with a separate brute force.
2. Count pairs with a given difference
What it asks: in an array, count unordered pairs whose values differ by exactly K. Commonly reported with a different story (pairs of items, pairs of days).
Pattern: hash map of seen values.
Key insight: for each element x, earlier elements equal to x-K or x+K each form one pair. Handle K = 0 separately so you do not double count.
Complexity: O(n) time, O(n) space, against the O(n^2) loop that times out.
PYTHON
3. Minimum platforms or rooms
What it asks: given arrival and departure times for trains (or meetings, or guests), find the maximum number present at once.
Pattern: sort events and sweep.
Key insight: turn each interval into two events, sort, and keep a running count. Decide up front whether an arrival at the exact minute of a departure overlaps; the sort tie-break encodes that choice.
Complexity: O(n log n).
PYTHON
4. Number of ways to make a total
What it asks: count the ways to reach a target using given step sizes or coin values, order not mattering.
Pattern: unbounded knapsack style DP.
Key insight: loop over coins on the outside and amounts on the inside. Swapping the loops counts ordered sequences instead, a classic wrong answer that still passes the sample.
Complexity: O(coins x target).
PYTHON
5. Shortest path in a grid with blocked cells
What it asks: minimum moves from the top-left to the bottom-right of a grid with obstacles, sometimes with extra rules (keys, teleports, one wall break).
Pattern: BFS, with extra state in the visited key when rules are added.
Key insight: if a rule changes what you can do later (a key collected), put it in the state: (row, col, keys). Forgetting this is the usual cause of a wrong answer on hidden cases.
Complexity: O(R x C x states).
PYTHON
6. Circular elimination (Josephus style)
What it asks: people stand in a circle, every K-th is removed, find the survivor or the removal order. Insight: for survivor only, use the recurrence f(n) = (f(n-1) + k) mod n, O(n); simulate with a list only when the order is needed.
7. Spiral, diagonal and rotation on matrices
What it asks: print or transform a matrix in an unusual traversal. Insight: this is a parsing and index-bookkeeping problem, not an algorithm one. Shrink four boundaries inward and stop when they cross.
8. String compression and pattern counting
What it asks: count or rewrite substrings under a custom rule. Insight: convert the rule to a single pass with a counter or stack before reaching for DP. Long inputs punish O(n^2) substring enumeration.
9. Modular arithmetic and combinatorics
What it asks: count arrangements modulo 10^9+7. Insight: precompute factorials and inverse factorials once, then every nCr is O(1). Python integers do not overflow, but a slow loop still times out.
10. Greedy with a priority queue
What it asks: schedule tasks, merge ropes, or serve customers to minimise total cost. Insight: if "always take the smallest/largest available" feels right, prove it with a swap argument, then use a heap. O(n log n).
Topic frequency: our observation
This table reflects how often each pattern shows up in the problems candidates share and in the practice material we reviewed. It is not official TCS data and the counts are rough.
| Pattern | How often we see it | Typical difficulty |
|---|---|---|
| Arrays, hashing, sorting and sweeps | Very often | Easy to medium |
| Number theory (primes, gcd, modular) | Very often | Medium |
| Grid and graph search (BFS/DFS) | Often | Medium |
| Dynamic programming | Often | Medium to hard |
| Strings and custom parsing | Often | Easy to medium |
| Simulation and matrix traversal | Often | Easy |
| Greedy and heaps | Sometimes | Medium |
| Combinatorics and counting | Sometimes | Medium to hard |
| Advanced graphs, geometry, bit tricks | Rare, mostly late rounds | Hard |
The practical reading: if you can do sorting, hashing, sieves, BFS and basic DP quickly and cleanly, you can cover most of what a first round asks. The DSA Patterns Sheet lists these same patterns with practice problems.
How Round 1 is scored (what we could and could not verify)
TCS's official Season 14 page confirms the season, eligibility, languages and prize pool. It does not state the Round 1 scoring rules, and the Round 1 date is not announced. What we found is candidate-reported from older seasons:
- A problem generally counts only if it passes all the hidden test cases; passing only the sample cases did not earn credit in reports we saw.
- Ranking has been described as number of problems solved first, with time as a tiebreak, and no penalty for wrong submissions in older seasons.
- Older write-ups describe a window of several hours for the round.
Rules vary by season. Treat all of this as unconfirmed for Season 14 and read the contest rules on codevita.tcsapps.com before you start. Last checked 29 Oct 2026.
A practice routine that works
- Week 1: solve two problems per pattern above untimed, writing a two-line input/output restatement first.
- Week 2: repeat under a clock. Read all problems for five minutes, rank them, solve easiest first.
- Week 3: take the MockVita contests (guide) and review every failed hidden case for parsing or edge-case causes.
- Always: test the empty, single-element and maximum-size inputs. Most lost marks are edge cases, not algorithms.
To rehearse the interview side that follows a good rank, try an AI mock interview, and see TCS interview questions and process.
FAQ
Where can I find CodeVita previous year questions?
TCS shows sample problems on the official CodeVita site, and many third-party sites collect past problems. Third-party names and seasons are often inconsistent, so use them for patterns rather than as a faithful archive.
What are CodeVita round 1 questions like?
Long narrative statements over classical patterns, often with custom input formats. The spread in difficulty is wide, so ordering matters.
Are these solutions in Python enough for the contest?
CodeVita allows C, C++, Java and Python. Python is fine for most first-round problems if the algorithm is right; use C++ or Java if you know a problem needs tight loops at maximum constraints.
Will the same problems repeat in Season 14?
Do not count on it. Narratives change; patterns repeat.
How many problems should I solve to qualify?
TCS has not published a cut-off we could verify. Aim for as many correct hidden-case solutions as you can; see the scoring section above.
Is CodeVita useful if I miss the cut?
Yes. The same skills are tested in every timed coding round, from HackerRank-style assessments to campus drives.
Topics
Related on Thita
Your next step
Practise the rounds for TCS CodeVita
Most selection rounds open with a timed coding test. Work through the DSA patterns they draw on, run your code in the browser, then rehearse the interview out loud with an AI interviewer.