# Tech Mahindra Placement – Round 2 Coding Questions & Practice Guide

**Hey everyone!** 👋

Recently, I appeared for the **Tech Mahindra placement process** and successfully cleared **Round 1** 🎉. In **Round 2**, we were tested on a mix of **MCQs** and **Automata programming questions**. To help those preparing, I’m sharing some of the programming questions that came up for me and a few my friend encountered during this round. You can use them to practice and get a feel for the kind of questions asked. 🚀

---

### **Round 2 Overview**

1. **MCQs**: These covered concepts from basic programming, data structures, and problem-solving. Be sure to brush up on logic, arrays, and basic algorithms.
    
2. **Automata (Programming Questions)**: We had to solve two coding problems. Below are detailed explanations of the questions.
    

---

### **Programming Questions**

#### **Question 1: Sum of Odd Digits**

**Problem Statement:**  
Given a positive integer, calculate the sum of its odd digits.

**Example:**  
Input: `27283`  
Output: `10` (7 + 3)

**Approach:**

1. Extract each digit of the number.
    
2. Check if the digit is odd.
    
3. Add all odd digits and return the sum.
    

**Test Cases:**

* Input: `13579` → Output: `25`
    
* Input: `24680` → Output: `0`
    

---

#### **Question 2: Rearrange Array Elements**

**Problem Statement:**  
Given an array of integers, rearrange it so that all even numbers appear before all odd numbers, maintaining their relative order.

**Example:**  
Input: `[13, 14, 15, 20]`  
Output: `[14, 20, 13, 15]`

**Approach:**

1. Separate the even and odd numbers while maintaining their relative order.
    
2. Combine the even numbers first, followed by odd numbers.
    

**Test Cases:**

* Input: `[2, 4, 6, 1, 3, 5]` → Output: `[2, 4, 6, 1, 3, 5]`
    
* Input: `[1, 3, 5, 7]` → Output: `[1, 3, 5, 7]`
    

---

#### **Question 3: Repeated Digits in a Number**

**Problem Statement:**  
Given a number, count how many digits appear more than once.

**Example:**  
Input: `1253532`  
Output: `3` (Digits `2`, `3`, and `5` are repeated)

**Approach:**

1. Count the occurrences of each digit.
    
2. Return the count of digits that appear more than once.
    

**Test Cases:**

* Input: `1112233` → Output: `3`
    
* Input: `12345` → Output: `0`
    

---

#### **Question 4: Multiply All Digits in a Number**

**Problem Statement:**  
Given a positive integer, calculate the product of all its digits.

**Example:**  
Input: `123`  
Output: `6` (1 × 2 × 3)

**Approach:**

1. Extract each digit of the number.
    
2. Multiply all the digits together.
    

**Test Cases:**

* Input: `234` → Output: `24`
    
* Input: `101` → Output: `0`
    

---

#### **Question 5: Fibonacci Series**

**Problem Statement:**  
Generate the Fibonacci series up to a given number of terms.

**Example:**  
Input: `5`  
Output: `[0, 1, 1, 2, 3]`

**Approach:**

1. Start with the first two terms, `0` and `1`.
    
2. Continue adding terms until the desired number is reached.
    

**Test Cases:**

* Input: `7` → Output: `[0, 1, 1, 2, 3, 5, 8]`
    
* Input: `1` → Output: `[0]`
    

---

#### **Question 6: Find the Nth Smallest Element in a List**

**Problem Statement:**  
Given a list of integers and a number nn, find the nn-th smallest element.

**Example:**  
Input: `([7, 10, 4, 3, 20, 15], 3)`  
Output: `7`

**Approach:**

1. Sort the array in ascending order.
    
2. Pick the nn-th smallest element.
    

**Test Cases:**

* Input: `([1, 3, 2, 4, 5], 2)` → Output: `2`
    
* Input: `([100, 200, 300, 400], 1)` → Output: `100`
    

---

### **Tips for Solving Automata Questions**

1. **Practice Speed:** Time is limited, so work on optimizing your solutions. Avoid overcomplicating logic.
    
2. **Write Clean Code:** Indentation and clarity matter, as these tests are often auto-evaluated.
    
3. **Edge Cases:** Always test your code for edge cases, such as empty arrays, single-digit numbers, or large inputs.
    
4. **Brush Up Basics:** Topics like arrays, strings, and simple algorithms are frequently tested.
    

---

### **Wrapping Up**

These questions will give you a good start in preparing for **Tech Mahindra placements** or any similar tests. Practice them, understand the logic behind each, and work on your efficiency.

If you’re preparing for your placements, **best of luck!** Feel free to reach out if you have any questions or want help with more practice problems. Let’s crack those interviews together! 🚀

Happy coding! 😊
