Home
Gaurav's GitHub Page
Cancel

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...

Implement Power Function (InterviewBit)

PROBLEM DESCRIPTION Implement pow(x, n) % d. In other words, given x, n and d, Find (x^n % d) Note that remainders on division cannot be negative. In other words, make sure the answer you retur...

Painter's Partition Problem (InterviewBit)

PROBLEM DESCRIPTION Given 2 integers A and B and an array of integers C of size N. Element C[i] represents the length of ith board. You have to paint all N boards [C0, C1, C2, C3 … CN-1]. There ar...

Rotated Sorted Array Search (InterviewBit)

PROBLEM DESCRIPTION Given an array of integers A of size N and an integer B. array A is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2 ). You are...

Allocate Books (InterviewBit)

PROBLEM DESCRIPTION Given an array of integers A of size N and an integer B. The College library has N books. The ith book has A[i] number of pages. You have to allocate books to B number of stu...

Capacity To Ship Packages Within B Days (InterviewBit)

PROBLEM DESCRIPTION A conveyor belt has packages that must be shipped from one port to another within B days. The ith package on the conveyor belt has a weight of A[i]. Each day, we load the ship...