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 »

Intersection Points of Two Lines


 You are given Equations of Two lines find Point where they intersects. Eq1 : 3 x – y = 3 Eq2 : 6 x – y = -6 Intersecting Point : ( -3 -12 ) Approach General Equation of Line A x + B y = C Line 1 : A1 x + B1 y… Read More »



 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Input : 1, 0, 1, 2, -1, -4 Output: -1 -1 2 -1 0 1 Approach Brute Force… Read More »

Simple Text Editor Hackerrank


 Problem Statement : Approach Maintain a stack with each version of S . Each time S is modified, push a copy of it onto the stack. Each time undo is called, pop the previous current value from the top of the stack and set the new current value at the top of the stack… Read More »

Min Priority Queue C++ Using STL


 By Default, priority_queue present in STL library supports Max Priority Queue, In max Priority queue top element of the queue is Maximum Number. To Implement Min Priority Queue i will tell you two approaches. 1. Using Operator Over loading In this Approach you need to remember the syntax. 2. Use the Default priority queue which… Read More »

Category: STL

Square Root of an Integer Binary Search


 Given an integer x, find square root of it. If x is not a perfect square, then return floor(√x). Approach We can use Binary Search to find square root. Take 2 variable first = 1 and last = N. While First <= Last, find mid and check mid*mid==N return Mid. If mid*mid>N It mean Mid… Read More »

Max Product Subarray


 Find the contiguous subarray within an array which has the largest product.  Max product Subarray I/P : 2 3 -2 5 O/P : 6 Approach Max Product Subarray  Max Product Subarray Max Product Subarray Max Product subarray Max Product Subarray Max Product Subarray Max Product Subarray Max Product Subarray Max Product Subarray Intuition, If all… Read More »