PROBLEM DESCRIPTION We define f(X, Y) as the number of different corresponding bits in the binary representation of X and Y. For example, f(2, 7) = 2, since the binary representation of 2 and 7 a...
XOR-ing the Subarrays! (InterviewBit)
PROBLEM DESCRIPTION Given an integer array A of size N. You need to find the value obtained by XOR-ing the contiguous subarrays, followed by XOR-ing the values thus obtained. Determine and return...
Min XOR value (InterviewBit)
PROBLEM DESCRIPTION Given an integer array A of N integers, find the pair of integers in the array which have minimum XOR value. Report the minimum XOR value. SOLUTION By sorting the array, we e...
Length of Last Word (InterviewBit)
PROBLEM DESCRIPTION Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘, return the length of last word in the string. If the last word does not exist, return 0...
Reverse Bits (InterviewBit)
PROBLEM DESCRIPTION Reverse the bits of an 32 bit unsigned integer A. SOLUTION APPROACH 1 public class Solution { public long reverse(long a) { long res = 0; for(int i=0;...
Trailing Zeroes (InterviewBit)
PROBLEM DESCRIPTION Given an integer A, count and return the number of trailing zeroes. SOLUTION APPROACH 1 public class Solution { public int solve(int A) { int c = 0; f...
Number of 1 Bits (InterviewBit)
PROBLEM DESCRIPTION Write a function that takes an integer and returns the number of 1 bits it has. SOLUTION Think of each bit in a binary number as a switch that can be either on (1) or off (0)...
Find a peak element (InterviewBit)
PROBLEM DESCRIPTION Given an array of integers A, find and return the peak element in it. An array element is peak if it is NOT smaller than its neighbors. For corner elements, we need to consid...
WoodCutting Made Easy! (InterviewBit)
PROBLEM DESCRIPTION There is given an integer array A of size N denoting the heights of N trees. Lumberjack Ojas needs to chop down B metres of wood. It is an easy job for him since he has a nift...
Matrix Median (InterviewBit)
PROBLEM DESCRIPTION Given a matrix of integers A of size N x M in which each row is sorted. Find and return the overall median of matrix A. NOTE: No extra memory is allowed. NOTE: Rows are numb...