Tech Mahindra 2021 Non-SDE (3-6 Dec) Hands on Coding Question Asked with Solution | Part: 1 - BitWise Operation

Tech Mahindra 2021 Non-SDE (3-6 Dec) Hands on Coding Question Asked with Solution
Tech Mahindra 2021 Non-SDE (3-6 Dec) Hands-on Coding Question Asked with Solution

BitWise Operation Question with Solution:

In C++
// solved by Pappu Kumar (Coder Guy)

#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;

cin>>n;

int a=0; // most

int b=-1; // least

int c=-1;

int i=0;
// solved by Pappu Kumar (Coder Guy)

// performing bit marking
while(n>0)

{
    if(n&1)

    {
        a++;

        if(b==-1)

        {

            b=i;
        }

        c=i;
    }

    i++;

    n=n>>1; //right shift
}

cout<< to_string(a)<<"#" << to_string(b) <<"#" << to_string(c);
// solved by Pappu Kumar (Coder Guy)
return 0;

}

// solved by Pappu Kumar (Coder Guy)


In Python:


Also, See,

// Solved By Pappu Kumar (Coder Guy)

n=int(input())

bi=bin(n)

bi=int(bi[2:])

x=[]

// Solved By Pappu Kumar (Coder Guy)

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

print(a,b,c,sep="#")

// Solved By Pappu Kumar (Coder Guy)

Tech Mahindra 2021 Non-SDE (3-6 Dec) Hands-on Coding Question Asked with Solution | Part: 1 - BitWise Operation

Tech Mahindra 2021 Non-SDE (3-6 Dec) Hands-on Coding Question Asked with Solution | Part: 2 - Geometric Progression

Tech Mahindra 2021 Non-SDE (3-6 Dec) Hands-on Coding Question Asked with Solution | Part: 3 - Caesar Cipher

Tech Mahindra 2021 Non-SDE (3-6 Dec) Hands-on Coding Question Asked with Solution | Part: 3 - Frequency Count


Also, apply for jobs,

Google (STEP) Internship 2021

Tech Mahindra Foundation Intern 20/2021

Cadence Off-Campus Drive 20/2021 

H-Town Technologies Off-Campus Drive 20/2021

JK Technosoft Off-Campus Drive 2021

Techjockey Off-Campus Drive 2019-2020

Swiggy Off-Campus Drive 2018-2021

Microsoft Research Fellows Program 2020-2021

TCS Off-Campus Drive 2021

Also, Read the Latest Interview Experience, 

Tips to Follow to Crack Tech Mahindra Exam 2021

CTS - Cognizant 96 Important Interview Questions 2021

TCS Ninja and Digital 2021 All Interview Questions

Hexaware technical interview 2021 

Stay tuned with www.freshersocjob.com to receive more such updates on recruitment. Join our Telegram Channel and Join our WhatsApp Group To get Instant updates for All Recruitment Internships and Off-Campus of 2021 Pass-Out Batch and Other Batch.


Comments