## Box and the Marbel

There are 50 boxes and 50 persons. Person 1 keeps 1 marble in every box. Person 2 keeps 2 marbles in every 2nd box, person 3 keeps 3 marbles in every third box. This process goes on till person 50 keep 50 marbles in the 50th box. Find the total no. Of marbles kept in… Read More »

## Water and Jug Problem Leetcode Solution

You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two jugs. If z liters of water is measurable, you must have z liters of water contained within one or… Read More »

## House Robber II Leetcode Solution

House Robber II After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile,… Read More »

## Minimum Moves to Equal Array Elements II Leetcode Solution

462. Minimum Moves to Equal Array Elements II Leetcode Solution Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by 1. You may assume the array’s length is at most 10,000.… Read More »

## Find All Duplicates in an Array Leetcode Solution

442. Find all Duplicates in an Array Leetcode Solution Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime? Input :… Read More »

## Linked List Cycle Leetcode Solution

141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Approach: Take Two Pointers Pointing to head initially. Then move one pointer by one step and another by two steps. If at any time Both pointer point to the same point returns True. C++ Implementation:

## House Robber Leetcode Solution

198. House Robber Leetcode Solution You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses… Read More »

## Longest Common Prefix

Write a function to find the longest common prefix string among the array of strings. I/p : “binary” , “bin” , “bina” O/p : “bin” Approach Simple Approach Character by Character Matching. Compare the Character of shortest string will all other string . If all are same Add them in the result string else Break… Read More »

## Find Permutation InterviewBit Solution

Given a positive integer n and a string s consisting only of letters D or I, you have to find any permutation of first n positive integer that satisfy the given input string. D means the next number is smaller, while I means the next number is greater. Link to Problem I/P : “DIDD” 5… Read More »

## Find Minimum in a Sorted Rotated Array

You are Given sorted rotated array. Find the minimum value in the Array. I/P : 7 , 8 , 9 , 10 , 12 , 1 ,6 O/P : 1 Approach 1. Simply Linear Search O ( n ) solution. 2. Using Binary Search Idea is quite Straight forward , Find Mid = ( Low… Read More »