CAMPUS PLACEMENT PREPARATION
Tech Mahindra Campus Assessment November 2026 – 3 Python Coding Questions with Solutions
Complete problem statements, examples, Python programs and step-by-step explanations.
PYTHON
2026
Introduction
Preparing for the Tech Mahindra Campus Assessment 2026? Practising hands-on programming questions is an important part of preparing for technical placement assessments.
In this article, we cover three Python programming questions visible in a Tech Mahindra Mettl campus assessment screenshot from November 2026.
These questions cover mathematical problem-solving, Python Pandas and recursion with dynamic programming.
For every question, we provide a problem statement, sample input, expected output, Python code and a step-by-step explanation.
Assessment Details
- Company: Tech Mahindra
- Assessment platform: Mettl
- Assessment period: November 2026
- Programming language: Python
- Question type: Hands-on programming
- Number of questions covered: 3
Note: The questions are reconstructed from assessment screenshots. The Maximum Rainfall Date question has incomplete original instructions, so its example and output below use an explicitly stated interpretation. These solutions are practice solutions, not verified official answer keys.
📚 Table of Contents
Question 1: Solve the Equation
Problem Statement
Given an integer N, your task is to find and return the number of sets of 3 positive integers a, b and c that satisfy the following equation:
Conditions:
- a, b and c must be positive integers.
- The values of a, b and c can be the same.
- Each unordered set is counted only once.
Example
INPUT
N = 11We need to find all sets of three positive integers satisfying the equation.
Let’s check some combinations:
| a | b | c | Result |
|---|---|---|---|
| 1 | 1 | 1 | 6 |
| 1 | 1 | 2 | 11 ✓ |
| 1 | 2 | 2 | 17 |
EXPECTED OUTPUT
One valid unordered set: (1, 1, 2).
Python Code
PYTHON 3 SOLUTION
from math import isqrt
def solve(N):
count = 0
a = 1
while 6 * a * a <= N:
b = a
while a*a + 3*b*b + 2*a*b <= N:
D = 4*N - 3*a*a - 3*b*b - 2*a*b
root = isqrt(D)
if root * root == D:
numerator = root - a - b
if numerator >= 0 and numerator % 2 == 0:
c = numerator // 2
if c >= b:
count += 1
b += 1
a += 1
return count
N = 11
print(solve(N))Output:
Code Explanation
- Initialize count to zero.
- Iterate through possible values of a and b, maintaining a ≤ b.
- Calculate the discriminant using the quadratic equation in c.
- Check whether the discriminant is a perfect square using isqrt().
- Calculate c and verify that c ≥ b.
- Increment count for every valid unordered set.
Important concept: The code uses mathematical optimization rather than checking every possible triple. The number of unordered sets is counted only once.
Question 2: Maximum Rainfall Date
Problem Statement
You are given a CSV file containing weather information with the following columns:
| Column | Description |
|---|---|
| COUNTRY | Name of the country. |
| DATE | Date in integer format (YYYYMMDD). |
| RAIN | Rainfall received on a given date in mm. |
| SNWD | Depth of snow in cm. |
| SNOW | Amount of snowfall received on a given date. |
The visible assessment title is Maximum Rainfall Date. Since the remaining instructions are not visible, the following example assumes that the task is to find the date corresponding to the highest rainfall across the complete dataframe.
Example
Consider the following sample dataset:
| COUNTRY | DATE | RAIN | SNWD | SNOW |
|---|---|---|---|---|
| India | 20240101 | 10 | 0 | 0 |
| India | 20240102 | 25 | 0 | 0 |
| India | 20240103 | 60 | 0 | 0 |
| India | 20240104 | 15 | 0 | 0 |
| USA | 20240105 | 45 | 2 | 5 |
Rainfall values are 10, 25, 60, 15 and 45.
The highest rainfall is 60 mm, recorded on 3 January 2024.
EXPECTED OUTPUT UNDER THIS INTERPRETATION
Maximum Rainfall: 60 mm
Python Code Using Pandas
Assuming the dataframe has already been loaded into a variable called data_frame:
PYTHON PANDAS SOLUTION
import pandas as pd
def solve(data_frame):
# Find the index of maximum rainfall
max_index = data_frame["RAIN"].idxmax()
# Get the corresponding date
result = data_frame.loc[max_index, "DATE"]
return int(result)
# Sample dataset
data_frame = pd.DataFrame({
"COUNTRY": ["India", "India", "India", "India", "USA"],
"DATE": [20240101, 20240102, 20240103,
20240104, 20240105],
"RAIN": [10, 25, 60, 15, 45],
"SNWD": [0, 0, 0, 0, 2],
"SNOW": [0, 0, 0, 0, 5]
})
print(solve(data_frame))Output:
Code Explanation
- idxmax(): Returns the index of the maximum rainfall value.
- loc[]: Retrieves the date from the corresponding row.
- int(): Converts the date to an integer.
Alternative: Maximum Rainfall Date for Each Country
If the original task asks for the maximum rainfall separately for each country, use this alternative solution:
def solve(data_frame):
result = data_frame.loc[
data_frame.groupby("COUNTRY")["RAIN"].idxmax(),
["COUNTRY", "DATE", "RAIN"]
]
return result.reset_index(drop=True)This groups the data by country and finds the date with the maximum rainfall for each country.
Important: The exact original requirement, including whether the maximum is global or country-wise, is not readable in the assessment screenshot. The two implementations above cover these interpretations.
Question 3: Crystal Seed Energy
Problem Statement
A materials lab grows crystals by repeatedly splitting seeds.
A seed of size 1 stores 1 unit of energy, and a seed of size 2 stores 2 units of energy.
A larger seed of size n splits according to the following rules:
Rule 1: If n is even
It splits into one seed of size n/2 while absorbing n extra units.
Rule 2: If n is odd
It splits into two seeds of sizes (n-1)/2 and (n+1)/2.
Your task is to find and return the energy E(N) modulo 1000000007.
Base conditions:
- E(1) = 1
- E(2) = 2
- N can be as large as 10¹⁵.
Example
INPUT
N = 7Since 7 is an odd number:
Step 1: Calculate E(3)
Since 3 is odd:
E(3) = E(1) + E(2) = 1 + 2 = 3
Step 2: Calculate E(4)
Since 4 is even:
E(4) = E(2) + 4 = 2 + 4 = 6
Step 3: Calculate E(7)
E(7) = 3 + 6 = 9
EXPECTED OUTPUT
Python Code Using Recursion and Memoization
PYTHON 3 SOLUTION
from functools import lru_cache
MOD = 1000000007
@lru_cache(maxsize=None)
def energy(n):
# Base conditions
if n == 1:
return 1
if n == 2:
return 2
# Even number
if n % 2 == 0:
return (energy(n // 2) + n) % MOD
# Odd number
else:
return (
energy((n - 1) // 2) +
energy((n + 1) // 2)
) % MOD
def solve(N):
return energy(N)
N = 7
print(solve(N))Output:
Code Explanation
- lru_cache: Stores previously calculated energy values.
- Base conditions: Returns 1 for seed size 1 and 2 for seed size 2.
- Even condition: Adds n to the energy of the half-sized seed.
- Odd condition: Adds the energies of the two resulting seeds.
- Modulo: Keeps the result within the required modulo value.
Why Use Memoization?
During recursion, the same seed sizes may be calculated more than once. Memoization stores previously calculated values and avoids unnecessary repeated calculations.
Since each recursive step reduces the seed size approximately by half, the recursion depth is logarithmic in N. For the stated N limit of 10¹⁵, this is suitable for Python recursion.
Summary of All 3 Python Coding Questions
| Question | Concept | Python Tools |
|---|---|---|
| Solve the Equation | Mathematical Logic | isqrt(), while |
| Maximum Rainfall Date | Data Analysis | Pandas, idxmax(), loc[] |
| Crystal Seed Energy | Recursion and DP | lru_cache, modulo |
How to Prepare for Tech Mahindra Coding Assessments?
If you are preparing for Tech Mahindra campus placements, focus on the following programming topics:
- Python fundamentals and data types.
- Lists, strings and dictionaries.
- Loops and conditional statements.
- Mathematical problem-solving.
- Recursion and dynamic programming.
- Python Pandas and CSV processing.
- Time and space complexity.
- Edge cases and optimization.
Disclaimer
This article is prepared for educational and interview preparation purposes using assessment screenshots shared for the November 2026 Tech Mahindra campus assessment. The original screenshots do not show all instructions for the Maximum Rainfall Date question. Examples and solutions are provided for practice and should not be treated as an official Tech Mahindra answer key. HiringHustle is an independent placement preparation platform and is not affiliated with Tech Mahindra.
Conclusion
These three Python programming problems cover important concepts such as mathematical logic, Pandas data analysis, recursion and dynamic programming.
Practising these problems will help students improve their coding skills and prepare for technical placement assessments.
Keep practising. Keep learning. Get ready for your next coding assessment!
TGH Software Solutions Recruitment 2026: Amazing Python Jobs
Related Tags
Tech Mahindra, Tech Mahindra Campus Assessment 2026, Tech Mahindra Coding Questions, Tech Mahindra Python Questions, Campus Placement 2026, Python Coding Questions, Python Interview Questions, Pandas Interview Questions, Recursion in Python, Dynamic Programming, Freshers Interview Preparation, Mettl Assessment.
