Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With

Analysis With Solution

TECH MAHINDRA Non-SDE ALL CODING


Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation
SOLUTIONS:

https://www.youtube.com/c/PappuCareerGuide/

1. Gp ( Done)

2. Bitwise operation (Done)

3. Frequency Count (Done)

4. Caesar Cipher (Done)

5. Number of Decoding (Done)

6. Longest Common Subsequence 

7. Numbers Puzzle

8. Longest Increasing Subsequence 

9. Moving Apples

10. infix to postfix

11. Penalty

12. Euler’s Totient Function

13. Next Number Generator

14. Next Number Element

15. Maximum Subarray

16. Minimise a String

17. Dubai Airport 

18. Possible Decodings

19. Longest Decreasing Subsequence 


Join Now
20. Longest Palindromic subsequence

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 3/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

21. Module 11 code


Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation
22. Roots of the Quadratic Equation

23. Maximum Subarray

1. Geometric Progression Question with Solution:

Geometric Progression In C++


// Solved By Pappu Career Guide


#include <bits/stdc++.h>

using namespace std;


int main() {

    double second_term;

    double third_term;

    int n;

    cin>>second_term>>third_term>>n;

    double r = third_term/second_term;  //9/3=3


    double a = second_term/r;

    double nth_term = a * pow( r, n-1);


    cout<<nth_term;

Join Now

return 0;

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 4/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation


}

https://t.me/techmahindra2021crack

In Python

Coming Soon.....

In C

Coming Soon.....

https://www.youtube.com/c/PappuCareerGuide/

2. BitWise Operation Question with Solution:

In C++

// solved by Pappu Kumar Guide


#include <bits/stdc++.h>

using namespace std;


int main() {

// a#b#c
// ex 
// 10 - binary- 1 0 1 0
// output 2#1#3

int n;

Join Now

cin>>n;
https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 5/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation


int a=0; // most

int b=-1; // least


int c=-1;

int i=0;
// solved by Pappu Career Guide

// performing bit marking


while(n>0)

{
    if(n&1)

  {
        a++;

        if(b==-1)

    {

            b=i;
    }

        c=i;
  }

    i++;

Join Now
    n=n>>1; //right shift

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 6/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

}
Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

cout<< to_string(a)<<"#" << to_string(b) <<"#" <<


to_string(c);
// solved by Pappu Kumar Guide
return 0;

In Python

n=int(input())

bi=bin(n)

bi=int(bi[2:])

x=[]

// Solved By Pappu Career Guide

while(bi>0):

    x.append(bi%10)

    bi//=10

a=x.count(1)

b=x.index(1)

x.reverse()

c=len(x)-x.index(1)-1
Join Now
print(a,b,c,sep="#")

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 7/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

In C
Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

Coming Soon.....

https://t.me/techmahindra2021crack

3. Frequency Count Question with Solution:

Frequency Count In C++


// Solved By Pappu Career Guide


#include <bits/stdc++.h>

using namespace std;


string helper(string s)

// Solved By Pappu Kumar (Coder Guy)


{
    int arr[26]={0};  // there are 26 alphabets 
in the english char
    for(int i=0;i<s.length();i++) // loop through 
the input string
  {
        arr[s[i]-97]++; // 
to come back with the 0 position

  }
    string result="";

    for(int i=0;i<26;i++)  // for character 


count with loop
  {
Join Now
        if(arr[i]>0) // if char is present

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 8/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation


    {
            char ch = 97+i; // add the value of 
ASCII value of i = 1 - taking b
            result+=ch;

            result+=to_string(arr[i]);

    }

  }

    return result;
https://t.me/techmahindra2021crack
}

int main() {

    string s;

    cin>>s;

    cout<<helper(s);

    return 0;

In Python

Coming Soon.....

In C
Join Now
Coming Soon.....

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 9/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

4. Caesar Cipher Question with Solution:

Caesar Cipher In C++


// Solved By Pappu Career Guide


#include <bits/stdc++.h>
using namespace std;
// Solved By Pappu Kumar (Coder Guy)

string helper(string s)
{
    string result = ""; // answer store string

    for(int i=0;i<s.length();i++) // loop through


 the input string

  {
        char ch = char((s[i] + 3 - 97)%26 + 97);

        result+=ch;

  }

    return result;

}
int main() {

    string s;

    cin>>s;

Join Now
    cout<<helper(s);

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 10/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation


    return 0;

}
https://t.me/techmahindra2021crack

In C

Coming Soon.....

In Python

Coming Soon.....

https://t.me/placemate

5. Number of Decodings

The solution in Python:

def numDecodings(s): 

 if not s:

  return 0

 dp = [0 for x in range(len(s) + 1)] 

 # base case initialization

 dp[0] = 1 

 dp[1] = 0 if s[0] == "0" else 1   #(1)

 for i in range(2, len(s) + 1): 

Join Now
  # One step jump

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 11/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

  if 0 < int(s[i-1:i]) <= 9:    #(2)


Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

   dp[i] += dp[i - 1]

  # Two step jump

  if 10 <= int(s[i-2:i]) <= 26: #(3)

   dp[i] += dp[i - 2]

 return dp[len(s)]

https://t.me/techmahindra2021crack

s=input()

print(numDecodings(s))

In C

Coming Soon.....

In c++

Coming Soon.....

6. Longest Common Subsequence 

// Solved By Pappu Career Guide

#include <bits/stdc++.h>

using namespace std;

string helper(string s1 , string s2)

{
Join Now
https://t.me/freshersoffcampjobs

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 12/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

    int dp[s1.length()+1][s2.length()+1];
Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

https://t.me/placemate

    for(int i=0;i<=s1.length();i++)

  {

        for(int j=0;j<s2.length();j++)

    {

            dp[i][j]=0;

    }

  }

https://t.me/freshersoffcampjobs

    for(int i=1;i<=s1.length();i++)

  {

        for(int j=1;j<=s2.length();j++)

    {

            if(s1[i-1]==s2[j-1])

      {

                dp[i][j]=1+dp[i-1][j-1];

      }

            else

Join Now
      {

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 13/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

      }

    }

  }

    return dp[s1.length()][s2.length()];

int main() {

    string s1;

    string s2;

    cin>>s1>>s2;

    cout<<helper(s1,s2);

https://t.me/freshersoffcampjobs

    return 0;

7. Numbers Puzzles Solution in C

// Solved By Pappu Career Guide

#include<stdio.h>

Join Now
#include <stdlib.h>

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 14/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

void swap(int *x, int *y){


Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

    int temp;

    temp = *x;

    *x = *y;

    *y = temp;

void BubbleSort( int arr[], int n ){

    int i, j;

 for(i=0;i<n-1;i++){

    for (j = 0; j < n-i-1; j++){ 

           if (arr[j] > arr[j+1]){

              swap(&arr[j], &arr[j+1]);

           }

  }

 }

int Display(int arr[], int n){

    int i;

    for(i=0;i<n;i++){

Join Now
    printf("%d \n", arr[i]);

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 15/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

 } 
Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

https://t.me/freshersoffcampjobs

 int AbsValue(int arr[],int n){

    int sum=0;

    for(int i=n-1;i>0;--i){

        sum += abs(arr[i]-arr[i-1]);

  }

    printf("%d",sum);

  }

int main(){

    int arr[] = {3,2,1};

    int n = sizeof(arr) / sizeof(arr[0]);

    BubbleSort(arr, n);

    //Display(arr,n);

    AbsValue(arr,n);

8. Longest Increasing Subsequence Solution in Python

// Solved By Pappu Career Guide


Join Now

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 16/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

https://t.me/freshersoffcampjobs

9. Moving Apples

// Solved By Pappu Career Guide


Join Now

https://t.me/techmahindra2021crack

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 17/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

10. inFixToPostFix Solution in Python


Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation
// Solved By Pappu Career Guide

def inFixToPostFix():

inFix = '3*(x+1)-2/2'

postFix = ''

s = Stack()

for c in inFix:

    # if elif chain for anything that c can be

    if c in "0123456789x":

        postFix += c

    elif c in "+-":

        if s.isEmpty():

            s.push(c)

        elif s.top() =='(':

            s.push(c)

    elif c in "*/":

        if s.isEmpty():

            s.push(c)

        elif s.top() in "+-(":

            s.push(c) Join Now

https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 18/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

    elif c == "(":
Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

        s.push(c)

    elif c == ")":

        while s.top() is not '(':

            postFix += s.pop()

        s.pop()

    else:

        print("Error")

print(postFix)

return postFix

https://t.me/techmahindra2021crack

pappu5

11. Penalty Solution in C++

// Solved By Pappu Career Guide

#include <bits/stdc++.h>

using namespace std;

int helper(int n, int arr[])

    int penalty = 0;
Join Now

    sort(arr, arr+n); // inbuild method foro sort the array


https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 19/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

    for(int i=1;i<n;i++) // look through all the element in


Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation
the array

  {

        penalty+=abs(arr[i]-arr[i-1]);  // adding the


adjecent element in a penalty variables

  }

    return penalty;

int main() {

    int n;

    cin>>n;

    int arr[n];

    for(int i=0;i<n;i++)

  {

        cin>>arr[i];

  }

    cout<<helper(n, arr);

return 0;

https://t.me/techmahindra2021crack

}
Join Now

12. Euler’s Totient Function in C++


https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 20/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

// Solved By Pappu Career Guide


Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

#include <stdio.h>

int gcd(int a, int b)

if (a == 0)

return b;

return gcd(b % a, a);

int phi(unsigned int n)

unsigned int result = 1;

for (int i = 2; i < n; i++)

if (gcd(i, n) == 1)

result++;

return result;

int main()

{
Join Now

int n;
https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 21/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

for (n = 1; n <= 10; n++)


Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

printf("phi(%d) = %d\n", n, phi(n));

return 0;

pappu4

13. Next Number Generator in C++

// Solved By Pappu Career Guide

14. Next Number Element in C++

// Solved By Pappu Career Guide

15. Maximu Subarray in C++

// Solved By Pappu Career Guide

16. Minimise a String in C++

// Solved By Pappu Career Guide

17. Dubai Airport in C++

// Solved By Pappu Career Guide

18. Possible Decodings in C++

// Solved By Pappu Career Guide

19. Longest Decreasing Subsequence in C++

// Solved By Pappu Career Guide


Join Now

20. Longest Palindromic subsequence in C++


https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 22/28
7/2/22, 11:46 PM Tech M 2nd Round Non-SDE Complete All Asked Coding Repeated Questions Complete Analysis With Solution

// Solved By Pappu Career Guide


Freshersocjob.com - Latest Jobs for Freshers and Interview Prepparation

21. module 11 in Python

// Solved By Pappu Career Guide

def remainder(st) :

  ln = len(st)

  rem = 0

  for i in range(0, ln) :

    num = rem * 10 + (int)(st[i])

    rem = num % 11

  return rem

st = "3435346456547566345436457867978"

print(remainder(st))

🛑Tech Mahindra 2nd Round 12th April Non-S…


Non-S…

Join Our Official Telegram Channel


Join Now
How To for Download All Section Non-SDE Tech With
Coding Question with solution Complete in One PDF:  
https://www.freshersocjob.com/2021/04/tech-mahindra-2nd-round-13th-april-exam.html 23/28

You might also like