Posts

CodeChef OCT17 : Problem Code: PERFCONT

Problem: Chef wants to organize a contest. Predicting difficulty levels of the problems can be a daunting task. Chef wants his contests to be balanced in terms of difficulty levels of the problems. Assume a contest had total P participants. A problem that was solved by at least half of the participants (i.e. P / 2 (integer division)) is said to be cakewalk difficulty. A problem solved by at max P / 10 (integer division) participants is categorized to be a hard difficulty. Chef wants the contest to be balanced. According to him, a balanced contest must have exactly 1 cakewalk and exactly 2 hard problems. You are given the description of N problems and the number of participants solving those problems. Can you tell whether the contest was balanced or not? Input The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two space separated integers, N, P denoting the number of problems, number of ...

HackerRank(greedy): Minimum Absolute Difference in an Array

Problem:  Consider an array of integers, . We define the absolute difference between two elements, and (where ), to be the absolute value of . Given an array of integers, find and print the minimum absolute difference between any two elements in the array. Input Format The first line contains a single integer denoting (the number of integers). The second line contains space-separated integers describing the respective values of . Constraints Output Format Print the minimum absolute difference between any two elements in the array. Sample Input 0 3 3 -7 0 Sample Output 0 3 Explanation 0 With integers in our array, we have three possible pairs: , , and . The absolute values of the differences between these pairs are as follows: Notice that if we were to switch the order of the numbers in these pairs, the resulting absolute values would still be the same. The smallest of these possible absolute di...

Codevita 2017 Round-1 Problem-C

Problem: CodeVita 2017 Round 1 Problem -C (download from below ...  if any problem in downloading then comment)  http://s000.tinyupload.com/?file_id=52952119059621072275 Solution : /* Author: Krishankant Ray * CodeVita 2017 Round 1 */ #include<iostream> #include<vector> using namespace std; int main () { int d,k = 0 ; string arr; cin >> d; cin >> arr; int n = arr.length(); char R[n]; for ( int f = 0 ; f < n; ) { R[f] = arr[k ++ ]; f += (( 2 * d) - 2 ); } for ( int i = 1 ; i < d - 1 ;i ++ ) { R[i] = arr[k ++ ]; for ( int j = i; j < n;) { j += (( 2 * d) - 2 - ( 2 * i)); R[j] = arr[k ++ ]; j += (( 2 * i)); if (j < n) R[j] = arr[k ++ ]; } } for ( int l = d - 1 ; l < n;l += (( 2 * d) - 2 )) { R[l] = arr[k...

CodeVita 2017 Round-1 Problem-B

Problem : Concatenating primes If you like numbers, you may have been fascinated by prime numbers. Sometimes we obtain by concatenating two primes. For example, concatenating 2 and 3, we obtain the prime 23. The aim is to find all such distinct "concatenated primes" that could be obtained by concatenating primes ≤ a given integer N.   Input Format:   Integer N Output Format: M, the number of distinct primes that could be obtained by concatenating two primes ≤ N Constraints: N ≤ 70 Example 1 Input 10 Output 4 Explanations The primes ≤ 10 are 2, 3, 5, 7. These can be used to form the following concatenated numbers: 22, 23, 25, 27, 32, 33, 35, 37, 52, 53, 55, 57, 72, 73, 75, 77. Of these, there are four primes: 23 37 53 and 73. Hence the output is 4. Example 2 Input 20 Output 17 Explanation The prime numbers up to 20 are 2 3 5 7 11 13 17 and 19. Concatenating these two at a time in all possible ways, we get the following numbers: 22 23 25 27 211 213 217 219 32 33...

TCS-Codevita 2017 Round-1 Problem-A

Problem : Mountain peak sequence Consider the first three natural numbers 1, 2, 3. These can be arranged in the following ways: 2, 3, 1 and 1, 3, 2. Inboth of these arrangements, the numbers increase to a certain point and then decrease. A sequence with this property is called a "mountain peak sequence". Given an integer N, write a program to find the remainder of mountain peak arrangements that can be obtained by rearranging the numbers 1, 2, ...., N. Input Format: One line containing the integer N Output Format: An integer m, giving the remainder of the number of mountain peak arrangements that could be obtained from 1, 2, ...., N is divide by Mod Constraints : Mod = 109+7 N ≤ 109 Example 1 Input 3 Output 2 Explanation There are two such arrangements: 1, 3, 2 and 2, 3, 1 Example 2 Input 4 Output 6 Explanation The six arrangements are (1, 2, 4, 3), (1,3,4,2), (1,4,3,2), (2,3,4,1), (2,4,3,1), (3,4,2,1) Note: Please do not use packag...

Codechef SEPT17 CookOff - Subsequence Equality Problem Code: LIKECS01

Problem: (Link:  https://www.codechef.com/problems/LIKECS01 ) Chef Tobby is playing a rapid fire with Bhuvan. He gives Bhuvan a string S and each time, Bhuvan has to guess whether there exists 2 equal subsequences in the string or not. Bhuvan got a perfect score in the game with Chef Tobby. However, Chef Tobby has now asked Bhuvan to write a program that will do this automatically given a string S . Bhuvan is an intelligent man but he does not know how to write a code. Can you help him? Find two different subsequences such that they are equal in their value, more formally, find two sequences of indices (a 1 , a 2 , ..., a k-1 , a k ) and (b 1 , b 2 , ..., b k-1 , b k ) such that: 1≤ a i , b i ≤ |S| a i < a i+1 for all valid i b i < b i+1 for all valid i S a i = S b i for all valid i there exist at least one i such that a i is not equal to b i Input section The first line contains T , the number of test cases. Each of the next T lines contain ...