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 »

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 »