Posts

Showing posts from October, 2017

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 differ