Find the largest rectangular are in a histogram where largest area can be made up of contiguous bars.
For simplicity, assume that all bars have same width of 1 unit.
Given a value N, we want to make change for N cents and we have infinite supply of each of S={S1, S2...Sm}valued coins, how many ways we can make the change? The order of coins does not matter.
For example for N=4, and S={1,2,3}, there are four solutions: {1,1,1,1}, {1,1,2}, {2,2},{1,3}. So output should be 4.
Given a DLL, with next pointer pointing to the next node in the list and one arbit pointer which can point to any node, not just the previous one. Duplicate this linked list in O(n) time and O(1) space complexity.
Equilibrium index of an array is an index such that sum of elements at lower indexes is equal to sum of the elements at higher indexes.
For example: in an array {-7, 1, 5, 2, -4, 3, 0}, 3 and 6 are the equilibrium indexes.
Write a function equilibrium(int a[], int n) that prints all equilibrium indexes if present .
Time complexity should be O(n).
Given two sorted arrays of equal length, how do u find a pair of numbers one from each array such that absolute difference between two numbers is minimum.
The cost of stock is given on each day. Find the maximum profit that you can make by buying and selling it on those days. There can be two conditions.
1. You can buy and sell only once
2. You can buy and sell multiple times
For example: If the given array is {100,180,260, 310, 40, 535, 695}
The maximum profit can be earned by buying on Day 0, selling on day 3. Again buy on day 4 and sell on Day 6.
Write a function to check if two rectangles defined
as below, have common area or not. The functions take the top left and
bottom right coordinate as input and return 1 if they have common area,
otherwise return 0. Input Output
10 1
20
20
10
10
20
20
10
Given a list of N coins, their values {a1, a2, ...aN} and the total sum S. Find the minimum number of coins , the sum of which is S(we can use as many coins of one type as we want) or return -1 if it's not possible to select coins in such a way that they sum upto S. Explanation for algorithm is given here: http://www.topcoder.com/tc?d1=tutorials&d2=dynProg&module=Static
Given two linked list, insert nodes of second linked list into first at alternate position of first list.
Ex- first List is 1->2->3->4->5 and second list is 6->7->8->9->10
first list should be 1->6->2->7->3->8->4->9->5->10 and second list empty
The nodes of second list should be inserted only if positions are available.
Ex- first List is 1->2->3- and second list is 4->5->6->7->8
first list should be 1->4->2->5->3->6 and secodn list should be 7->8
Use of extra space is not allowed. Expected tiem complexity should be O(n) where n is the number of nodes.
Given two strings, find the length of longest common substring.
For example: Given strings are: "GeeksForGeeks" and "GeeksQuiz". The out put should be 5.
Givenn a floating point number, write a function to count ste bits in its binary representation.
For example: Floating point representation of 0.15625 has 6 set bits.
Rearrange positive and negative numbers in O(n) time and O(1) complexity. If there are more positive or negative number, they will appear at the end of the array.
Ex:
Input Array : {-1,2,-3,4,5,6,-7,8,9}
Output Array: {9,-7,8,-3,5,-1,2,4,6}
Given two arrays A and B containing elements of digit, return array A-B. Your machine can only do calculation of less than 20.
Ex: A- {1,2,5,7,5}
B- {3,4,8,9}
A-B = {9,0,8,6}
Given a n by m matrix of bits find the largest X that is formed in the matrix and return the size of the diagonal of that X. An X is defined as 2 equally sized diagonals that share a single 1.
Given a n by m matrix of bits find the largest X that is formed in the matrix and return the size of the diagonal of that X. An X is defined as 2 equally sized diagonals that share a single 1.
Given a string say "ABCD". Now create a new string with duplicates of each character in the original string and append the reverse of the same string (with duplicates) excluding the last character.
First iteration: AABBCCCCBBAA [ABC three types of chars; Here c is the last char.Ignore duplicates after the last char c]
Fibonacci Numbers: A number is said to be Fibonacci number if it follows the fibonacci property. (Ex: 112, 1123, etc). But additionally, it need not necessarily start with 1, as with the normal fibonacci series. So, in this new definition, 112(1,1,2) is a fibonacci number and so is 121224(12,12,24), and so is 252550(25,25,50). So, given any two numbers as input, print out all the Fibonacci Numbers within that range..