Posts

Showing posts with the label Practice Questions

Rare Antiques

 Practice Questions   Rare Antiques   Problem Statement  Berlin is in an auction lot where there are antiques with different ID's, in the black market antiques are sold in pair and a pair of antiques are considered rare if their sum of ID is x. Berlin need a total number of rare antiques so that he can plan accordingly.  Boundary Condition(s)  1 <= t <= 10 ⁵ 1 <= n <= 10 ⁵ 0 <= a[i] <= x <= 10 ⁵  Input Format  First line represents the number of test cases. Second line represents the number of antiques and x in line. Third line represents the input array with distinct element.  Output Format  Number of rare antiques.  Example Input/Output 1   Input  1 5 5 1 3 2 4 7  Output  4  Explanation  The antique ID's are given as 1, 3, 2, 4, 7 and the sum necessary, x is 5. Then the pairs satisfying the conditions will be 1-4, 2-3. Hence, in total 4 antiques are rare.

Intruder Alert

 Practice Questions   Intruder Alert   Problem Statement  Tamayo is organizing an event on a big ground for the new year. There are lots of people here. It is a couple's event and both have been assigned the same ID. It has been in the news that a person named 'tokyo' can infiltrate the event with a unique ID different from all the couples there. You are the security head of the event and your job is to find the ID of tokyo as soon as possible. You decide to catch the imposter when everyone enters in a line as it's not necessary for a couple to enter together you need to check with their ID. Given the ID's in the order of line, find the imposter's ID.  Boundary Condition(s)  1 <= t <= 10 ³ 1 <= n <= 10 ³ 1 <= a[i] <= 10 ⁶  Input Format  First line represents the number of test cases. Second line represents the number of couples in line. Third line represents the input array/list.  Output Format  An integer rep...

Hostages

 Practice Questions   Hostages   Problem Statement  Professor have barricades of different length and he wants to store hostages by making a boundary using those barricades, but the professor realized that he can only use three barricades to store a group and they should be attached end to end so no one can escape, tell the professor how many possible ways are to assemble barricades.  Boundary Condition(s)  1 <= t <= 10 ³ 1 <= n <= 10 ³ 1 <= a[i] <= 10 ⁶  Input Format  First line represents the number of test cases. Second line represents the number of barricades. Third line represents the input array.  Output Format  Total possibility to arrange barricades.  Example Input/Output 1   Input  1 5 6 7 4 9 1  Output  4  Explanation  Possible arrangements are 9 4 7 9 4 6 7 4 6 7 4 9 so there are 4 possible arrangements. Solution for Hostage

Greedy Manager

 Practice Questions   Greedy Manager   Problem Statement  You are a resource manager and you need to manage gold, you already have enough to fulfill everyone's need. There is a line of people who either give gold to you represented by positive value or take gold from you represented by a negative values. You are greedy so you decided to get maximum profit so you decided to skip people but as you are under surveillance once you start accepting the person request you can only stop once and you need to take at least one person. You already have a list of people and their requests, so you can decide beforehand.  Boundary Condition(s)  1 <= t <= 10 ⁵ 1 <= n <= 10 ⁵ -10 ⁴  <= a[i] <= 10 ⁴  Input Format  First line represents the number of test cases. Second line represents the number of people. Third line represents the input array.  Output Format  Number of extra gold, -ve if you give the gold.  Example I...

Smallest String Possible

 Practice Questions   Smallest String Possible   Problem Statement  You are given two string S and T each of length N and K pairs of integers L ᵢ  and R ᵢ  ( 0 ≤ L ᵢ  < R ᵢ  ≤ N - 1) You can perform any of the two operations any number of times. You can replace the character of the string S at the i-th a position with the character of string T at i-th position. You can choose from any given K pairs and You are allowed to swap characters at the position L ᵢ  and R ᵢ  in the string T. Now you have to perform all the operations optimally so that the string S can be lexicographically smallest. http://en.wikipedia.org/wiki/Lexicographical_order Note: All characters of S and T are lower case English letters. [a - z].  Input Format  The first line will contain the number of test cases. For each test case, the next line will contain N and K, the length of the string and the number of pairs of integers. The n...

Maximum String Score

 Practice Questions   Maximum String Score   Problem Statement  You are given a list S that contains strings. Note: Each string in the list consists of only lowercase Latin Letters. The score of any string P is represented as follows. The sum of the number of strings in S in which P occurs as a substring and the number of strings in S in which P occurs as a prefix.  Example  If S = [ 'abc', 'abab', 'aba' ] and P = 'ab', then score of P = 3. This is because (P occurs in all the strings) + 3 (P occurs in 'abc', 'abab', and 'aba' as a prefix) = 6. Note: If P occurs as a prefix in any of the strings, then it will also contribute to the substring. Your task is to determine the maximum score possible of any string provided.  Input Format  The first line contains T denoting the number of test cases. For each test case The first line contains the N denoting the number of strings in the list. The Next N lines contain the elements of the ...