Professional Documents
Culture Documents
Problem A : Crackers
A small child (very cute) went for shopping crackers in a mall for Diwali. All the crackers were kept for a display in a queue. Child was very intelligent he can guess the exact height of the cracker by seeing it. He was also stratergic, he will only take a cracker of more or equall height than what he already purchase. He wants to buy maximum number of crackers by making a single pass of a queue. Can you guys please help that child to purchase the crackers in such a way that he gets maximum number of crackers and that too in the non-decreasing order of height. Input: First line contains N(total numbers of crackers). Second line contains the height of N crackers.(Height can be negative also) Constraints: 1 <= N <= 3000 -10^5 <= Height <= 10^5 Time Limit : 1s Output: Maximum numbers of crackers. Print the answer in a single line followed by a '\n' ( just print a new line no need to display '\n' ) Sample Case 1: Input: 10 6 3 4 8 10 5 7 1 9 2 Output: 5\n Explaination: Child will buy crackers of height 3,4,5,7,9 Sample Case 2: Input: 10 -6 3 -4 8 -4 5 -1 1 9 2 Output: 6\n Explaination: Child will buy crackers of height -6,-4,-4,-1,1,2
Problem C : AIBOHPHOBIA
Your task is, given a string S, check whether it is a palindrome or not. Easy.. isn't it ? Wait, here is a twist if its not a palindrome you have to split it in to palindromes in such a way that their concatenation gives S. Still easy ? Now to make this task really good, you have to split in such a way that minimum number of palindromes are formed. In other words, you have to find the minimum number of palindromic pieces, whose concatenation is S Constraints: 1 <= Length of String (S)<= 5600 Time Limit : 1s Input: Single Line contains a String S which will only contain [ 'A' - 'Z' ]. Output: Print the minimum number of palindromes in a single line, followed by a '\n' ( just print a new line, no need to display '\n' ) Sample Case 1: Input: REDIVIDER Output: 1\n Explanation: No need to Split, as its already a palindrome. Sample Case 2: Input: APSISCOOL Output: 6\n Explanation: Following are the pieces, A + P + SIS + C + OO + L --> APSISCOOL ( total 6 pieces).
Problem D : Ra.2
A binary string is called Ra.Two if it has no two consecutive ones in it and begins with a 1. The first few such binary strings in order are {1, 10, 100, 101, 1000, 1001, 1010, 10000, 10001, 10010, 10100, 10101 ..... }. Given N, find the Nth smallest Ra.Two number. Input: First line contains N. Output: Print the answer in a single line, followed by a '\n' ( just print a new line, no need to display '\n' ) Constraints: 1 <= N <= 109 Time Limit : 1s Sample Case 1: Input: 5 Output: 1000\n Sample Case 2: Input: 40 Output: 10001001\n
Problem E : Islands
Given the map of Lakshadweep, find the number of islands in it. You will be given a rectangular map of R rows and C columns. Each cell is either land ( denoted by '#' ) or water ( denoted by '.' ). Two cells are adjacent to eachother, if they share a side. So there can be at most 4 neighbors to each cell ( diagonal cells are not treated adjacent ). Now, an island is a piece of connected land. Find the number of islands present. See the example cases for more clarity. Input: First line contains R and C. Next R lines give the description of the island. Output: Print the answer in a single line, followed by a '\n' ( just print a new line, no need to display '\n' ) Constraints: 1 <= R, C <= 200 Each cell is either a '.' or a '#' Time Limit : 1s Sample Case 1: Input: 34 ...# ##.# #..# Output: 2\n Sample Case 2: Input: 33 ..# #.. .## Output: 3\n