Library Query
A giant library has just been inaugurated this week. It can be modeled as a sequence of N consecutive shelves with each shelf having some number of books. Now, being the geek that you are, you thought of the following two queries which can be performed on these shelves. Change the number of books in one of the shelves. Obtain the number of books on the shelf having the kth rank within the range of shelves. A shelf is said to have the kth rank if its position is k when the shelves are so
View Solution →Starfleet
In a galaxy far away, there is a constant battle between the republic and the droid army. The droid army decided to launch their final attack on the republic. They have N space-fighters. Initially the ith fighter is located at (xi, yi). All of the space-fighters move with constant velocity V units/sec in the positive X direction. i.e., fighter at (xi, yi) moves to (xi+V, yi) in 1 second. The ith space-fighter broadcasts enemy information at a frequency fi. The republic is not scared of the
View Solution →Almost Equal - Advanced
A Sumo wrestling championship is scheduled to be held this winter in the HackerCity where N wrestlers from different parts of the world are going to participate. The rules state that two wrestlers can fight against each other if and only if the difference in their height is less than or equal to K, (i.e) wrestler A and wrestler B can fight if and only if |height(A)-height(B)|<=K. Given an array H[], where H[i] represents the height of the ith fighter, for a given l, r where 0 <= l <= r < N,
View Solution →Almost sorted interval
Shik loves sorted intervals. But currently he does not have enough time to sort all the numbers. So he decided to use Almost sorted intervals. An Almost sorted interval is a consecutive subsequence in a sequence which satisfies the following property: The first number is the smallest. The last number is the largest. Please help him count the number of almost sorted intervals in this permutation. Note: Two intervals are different if at least one of the starting or ending indices are diffe
View Solution →Roy and alpha-beta trees
Roy has taken a liking to the Binary Search Trees(BST). He is interested in knowing the number of ways an array A of N integers can be arranged to form a BST. Thus, he tries a few combinations, and notes down the numbers at the odd levels and the numbers at the even levels. You're given two values, alpha and beta. Can you calculate the sum of Liking of all possible BST's that can be formed from an array of N integers? Liking of each BST is defined as follows (sum of numbers on even levels
View Solution →