Bit Manipulation Interview Questions
- 1of 1 vote
AnswersA gaming application assigns a sessionid to each player every time they start a new session. These sessionid are all unique and can be selected from 1 to 10^6 numbers. A get() and put() function is used to assign and then release the sessionid for each user. A released session id can then be reused and assigned to another player. How can you write the get() and put() function to handle this in time and space optimized manner?
- Shilpi_Roy November 02, 2017 in United States
I did provide o(n) solution with hash table but he seemed to be asking for a bit manipulation or bit masking technique for 32 bit address.| Report Duplicate | Flag | PURGE
Bit Manipulation - 0of 0 votes
AnswersYou are given a positive integer number and you have to return the greatest smaller tidy number of this input number. If the input number itself is tidy, then, it become the answer
- sonesh April 20, 2017 in India
Example
Input: 1234
output: 1234
input: 100
output: 99
input 143456
output: 139999.
PS.A tidy number is a number whose digits are in non-decreasing order.| Report Duplicate | Flag | PURGE
FreshoKartz Software Engineer Intern Bit Manipulation - 0of 0 votes
AnswersYou are given a positive integer number and you have to return a boolean telling whether the input number is a tidy number or not. A tidy number is a number whose digits are in non-decreasing order. For example, 1234 is a tidy number, 122334 is also a tidy number but 143567 is not a tidy number.
- sonesh April 20, 2017 in India| Report Duplicate | Flag | PURGE
FreshoKartz Software Engineer Intern Bit Manipulation - 0of 0 votes
AnswersYou are given an integer, print its 4th least significant bit
- sonesh April 18, 2017 in United States| Report Duplicate | Flag | PURGE
Expedia Software Engineer / Developer Bit Manipulation - 1of 1 vote
AnswersLook at the following sequence:
3, 5, 6, 9, 10, 12, 17, 18, 20....
All the numbers in the series has exactly 2 bits set in their binary representation. Your task is simple, you have to find the Nth number of this sequence.
1 <= T <= 10^6
1 <= N <= 10^14
I tried to implement it as follows but it is giving me wrong answer for some hidden cases.
- ranjani4ever February 21, 2017 in United States#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; #define MAX 10000 #define MOD 1000000007 long long int m[MAX+1]; long long int sum; long long int binary_search(long long int n) { long long int low=0,high=MAX,mid; while(low<high) { mid=low+(high-low+1)/2; if(m[mid]<=n) low=mid; else high=mid-1; } return low; } int main() { m[0]=1; for(long long int i=1;i<=MAX;i++) m[i]=m[i-1]+i; long long int n,k,l; int t; scanf("%d",&t); for(int test=0;test<t;test++) { scanf("%lld",&n); k=binary_search(n); //cout<<m[k]<<" "; l=n-m[k]; cout<<((1<<k+1)%MOD+(1<<l)%MOD)%MOD<<"\n"; } return 0; }
| Report Duplicate | Flag | PURGE
TCS CodeVita Bit Manipulation - 0of 0 votes
AnswersWrite a basic function that returns the starting bit position of a 32 bit pattern (i.e. 0xFE6B2840) within a provided byte array.
For example: Input 1 = [ 0x00 0x01 0xFE 0x6b 0x28 0x40 0x02 0x03 ....]
< Starting position is here at bit 16
Result 1 = 16
Note: The bit pattern could be non-byte aligned.
Input 2 = [ 0x00 0x03 0xFC 0xD6 0x50 0x80 0x04 0x06]
< Starting position is bit 15
Result 2 = 15
- Anonymous August 31, 2016 in -int bitPosition32bitPattern(char* byteArray, int length)
| Report Duplicate | Flag | PURGE
Bit Manipulation - 0of 0 votes
AnswersThe 64-bit representation of a 48-bit address is said to be in canonical form if bits 63 through 48 are either all ones or all zeroes. Implement X86IsCanonicalAddress().
- Mukesh July 07, 2016 in United States| Report Duplicate | Flag | PURGE
VMWare Inc Software Engineer Bit Manipulation - 0of 0 votes
AnswersImplement a function, set_bit_l_to_r(x,y,l,r).
- Mukesh July 07, 2016 in United States
For bits l to r (both inclusive), if they are set in x, also set them in y. Do not change bits of y, if they are not in range l to r, or those bits are not set in x. l and r are 0-based.| Report Duplicate | Flag | PURGE
VMWare Inc Software Engineer Bit Manipulation - 0of 0 votes
AnswersDefine and implement a function that takes two binary numbers represented as strings and returns their sum as another binary number which is again represented as a string. The result should not have any leading zeroes. In case the result is zero, it should be the string "0". Test input "111 1"
- bajan_coder February 27, 2016 in United States| Report Duplicate | Flag | PURGE
JP Morgan Applications Developer Bit Manipulation - 4of 4 votes
AnswersCheck if two integers are equal without using any comparison operators.
- coolProgrammer August 03, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Developer Bit Manipulation - 3of 3 votes
AnswersFind the number of bits set in a given character array.
- JSDUDE May 18, 2015 in United States
After giving him a bit wise operation that was O(n) where n is the number of bits set, he wanted a more optimum solution| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Bit Manipulation - 1of 1 vote
AnswersCheck if an integer is a power of 2 or not.
- Guest December 05, 2014 in India| Report Duplicate | Flag | PURGE
Monotype Senior Software Development Engineer Bit Manipulation - 2of 2 votes
Answerswhat does this code do?
- determinedgal89 October 01, 2014 in United Statesunsigned mystery(unsigned x) { unsigned i=0; while(x) { x=x&(x-1); i++; } return i; }
| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Bit Manipulation - 0of 2 votes
AnswersDesign a system like friend's functionality in facebook. should have all features of facebook's friends functionality. like for each person , he can have any number of friends , he will get suggestions for new firends , showing common friends if we visits any other profile . algo should be scalable , robust .
- gopi.komanduri August 02, 2014 in United States| Report Duplicate | Flag | PURGE
Computer Scientist Algorithm Android Application / UI Design Arrays Bit Manipulation C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Database Distributed Computing Dynamic Programming Hash Table Java Large Scale Computing Linked Lists Math & Computation Object Oriented Design Problem Solving Sorting SQL Stacks System Design Trees and Graphs XML - 0of 0 votes
AnswersDesign a phone book such that fields are searchable with name , with number. Later enhanced teh question asking searchable with address as well.
- gopi.komanduri July 22, 2014 in India| Report Duplicate | Flag | PURGE
Analyst Algorithm Arrays Bit Manipulation Brain Teasers C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures - 2of 6 votes
AnswersConsider the statement
- gjp February 24, 2014 in United States
result = a ? b : c;
Implement the above statement without using any conditional statements.| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Intern Bit Manipulation C - 1of 1 vote
AnswersWrite a piece of code to find out if the system is x86 architecure of Sparc
- gjp February 12, 2014 in United States| Report Duplicate | Flag | PURGE
Bit Manipulation C - 0of 0 votes
AnswersWrite a piece of code to find out if the system is x86 architecture of Sparc
- gjp February 12, 2014 in United States for Driver Development| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Intern Bit Manipulation - 0of 0 votes
AnswersWrite a piece of code to find out if a system is x86 architecture or Sparc?
- gjp February 12, 2014 in United States for Driver Development| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Intern Bit Manipulation - 2of 2 votes
AnswersGenerate MAX_INT (Max signed int value) using bitwise operators. Should work in 32 and 64 bit processors
- bartcois January 28, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Bit Manipulation - 2of 2 votes
AnswersYou have two numbers decomposed in binary representation, write a function that sums them and returns the result.
- getmax0 December 16, 2013 in United States
Input: 100011, 100100
Output: 1000111| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Bit Manipulation - 0of 2 votes
AnswersImplement your own sizeof operator using bitwise operation .
- nehalkumar6 December 04, 2013 in India| Report Duplicate | Flag | PURGE
Qualcomm Applications Developer Bit Manipulation - 4of 4 votes
AnswersGiven an int, write code to return the number of bits that are 1 in O(m) time, where m is the number of bits that are 1.
- ootah November 14, 2013 in United States| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Bit Manipulation - 5of 5 votes
AnswersInitially there is a number n written on board. Two players start playing a game turn by turn. Each player has to replace the number n written on the board by n-2^k (for some k >= 0 such that 2^k < n)?
- ACP Pradyuman October 03, 2013 in United States
Also the number n-2^k has to be as beautiful as n (The beauty of a number depends on the number of one's in its binary representation). The player loses the game when he can't select any such k.
Given the initial number n, determine which player will win the game if both players play optimally. n > 0 and n <= 10^9.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Bit Manipulation - 1of 1 vote
AnswersConsider 3 32-bit (4 byte) numbers A, B and C
- gayathri.jeyaram.k June 20, 2013 in India for Bangalore EE team
A: A3 A2 A1 A0
B: B3 B2 B1 B0
C: C3 C2 C1 C0
Modify C such that
C0=(A0+B0)/2
C1=(A1+B1)/2
C2=(A2+B2)/2
C3=(A3+B3)/2
Without using the obvious method of masking out each byte of A and corresponding byte of B, and add them, and then right-shifting once. Any other masking is allowed.| Report Duplicate | Flag | PURGE
Ittiam Systems Systems Design Engineer Bit Manipulation - -5of 7 votes
Answersneed to implement a weather report functionality. user will provide the city name , need to return the weather report.
- gopi.komanduri May 29, 2013 in India
if weather station exists n functioning properly , will return the weather report of that station .
else ,
will return the nearest available weather station report.
interviewer looking for optimized manner.
looking for datastructures to stores the cities n algo to return the report.| Report Duplicate | Flag | PURGE
Mentor Graphics Analyst Algorithm Arrays Bit Manipulation Brain Teasers C C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Dynamic Programming General Questions and Comments Graphics Hash Table Ideas Linked Lists Math & Computation Object Oriented Design Problem Solving Sets Sorting Stacks String Manipulation Terminology & Trivia Threads Trees and Graphs XML - 0of 0 votes
AnswersDesign a Tic Tac Toe Game. Classes Segregation and Code Flow.
- hprem991 March 18, 2013 in India| Report Duplicate | Flag | PURGE
StartUp Amazon Software Architect Software Engineer / Developer Algorithm Android Application / UI Design Arrays Assembly Automata Behavioral Bit Manipulation Brain Teasers C C++ Object Oriented Design - 0of 0 votes
AnswersImplement memcpy function which accepts num of bits as argument as oppose to number of bytes.
- codomania March 07, 2013 in United States for Windows Phone
memcpy (src, dst, num_bits)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Bit Manipulation - 0of 2 votes
AnswersA log file which has user details(user ID,timestamp) and pages visited in a particular day by that user.The next day -the same kind of log file gets generated.How do you find the probability of users who logged in consecutive days out of the second day - logged in users? The question is simple,but they look for the efficient data structure and time complexity.
- sriramMS December 20, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Application / UI Design Arrays Assembly Automata Behavioral Bit Manipulation Brain Teasers C C# C++ Cache Coding Data Mining Data Structures