Coding questions
Tech Mahindra Online Assessment
Overview
Detailed public write-ups on the Tech Mahindra online test are still hard to find.
What public reports and campus notices usually say (still verify officially):
| Item | Working note |
|---|---|
| Online test name | Tech Mahindra Online Assessment |
| Focus areas (metadata) | DSA, aptitude |
| Languages (metadata) | C, C++, Java, Python. |
| Reported round names | (OA → Technical → HR). |
Practice drills
Coding Q1: Check prime
Problem: Write a function that returns true if n is prime and false otherwise. Handle n < 2 correctly.
Approach: Return false for n < 2. Trial-divide from 2 to floor(sqrt(n)). If any divisor divides n evenly, it is composite; otherwise prime.
Complexity: O(√n) time
Tech Mahindra tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Coding Q2: Valid parentheses
Problem: Given a string containing only ‘()[]’, decide whether the brackets are balanced and correctly nested.
Approach: Scan left to right with a stack. Push opening brackets. On a closing bracket, the stack top must be the matching opener. At the end the stack must be empty.
Complexity: O(n) time, O(n) space
Tech Mahindra tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Coding Q3: Two Sum
Problem: Given an array of integers and a target, return indices of two numbers that add up to the target. Assume exactly one solution and you may not use the same element twice.
Approach: Walk the array once. For each value x, check whether target − x was seen earlier in a hash map of value → index. If yes, return both indices; else store x.
Complexity: O(n) time, O(n) space
Tech Mahindra tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Coding Q4: Longest substring without repeating characters
Problem: Given a string s, find the length of the longest substring without repeating characters. Example: ‘abcabcbb’ → 3 (‘abc’).
Approach: Sliding window with a map (or last-seen index) of characters. Expand the right pointer; when a duplicate appears inside the window, move the left pointer past the previous occurrence.
Complexity: O(n) time
Tech Mahindra tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
What to do next
- Open the official careers page or your college placement email for Tech Mahindra
- Search GeeksforGeeks + Reddit for
Tech Mahindra interview experience - Use Faceprep / PrepInsta only if they match your placement email

