Posts

Showing posts with the label HackerEarth Practice

Array Insert

Gary likes to solve problems of array, but he doesn't like problems that involve queries. His school teacher gave him an assignment full of problems but one of them involve queries. Can you help Gary in solving that problem so that he can go and play with his friends? The problem is : Given an Array A consisting of N positive integers, you have to answer Q queries on it. Queries can be of the two types: * 1 X Y - Update X at location Y in the array. * 2 L R - Print the sum of range [L, R], i.e. Both L and R are inclusive. Note :- Array indexing is from 0. Input : The first line contains two space separated integers N ( Length of Array ) and Q ( Queries ). Next Line contains N space separated integers denoting array A . Next Q Line contains 3 space separated integers for each line , as described above Output : Answer to the each query of type 2 in a new line, only when range is valid, otherwise ouput `-1` Constraints:   1 <= N <= 10^9 1 <= Q ...

Fitting circles

You are given a rectangle of length   a   and width   b . You are required to determine a circle that contains the maximum circumference that fits inside the rectangle. This type of circle is called a big circle. Your task is to determine the maximum number of big circles that can fit inside the rectangle.  Input format First line: An integer   t  denoting the number of test cases First line of each test case: Integers   a   and   b Output format For each test case, print the answer on a new line denoting the maximum number of big circles that can fit in the provided rectangle.   Constraints 1 ≤ t ≤ 1000 1 ≤ a , b ≤ 10 9 SAMPLE INPUT   1 40 10 SAMPLE OUTPUT   4 Explanation 4 circles of radius 10 can fit inside the rectangle.

Anti-palindrome strings

You are given a string  S  containing only lowercase alphabets. You can swap two adjacent characters any number of times (including 0). A string is called anti-palindrome if it is not a palindrome. If it is possible to make a string anti-palindrome, then find the lexicographically smallest anti-palindrome.   Otherwise, print -1 − 1 Input format The first line contains a single integer  T  denoting the number of test cases. The description of  T  test cases follows. Each line contains a string  S   of lower case alphabets only. Output format For each test case, print the answer in a new line. Constraints 1 ≤ T ≤ 100 2 ≤ | S | ≤ 2 × 10 5 S  contains only lowercase alphabets. SAMPLE INPUT 4 bpc pp deep zyx SAMPLE OUTPUT bcp -1 deep xyz Explanation In the first test case, you can create "bcp" which is not a palindrome and it is a lexicographically-small...

Supernatural

You are given a number   n . A supernatural number is a number whose product of digits is equal to   n , and in this number there is no digit 1. Count the number of supernatural numbers for a given   n . Input Contains a single integer   n ,   1 <= n <= 100 . Output Print the number of supernatural numbers. SAMPLE INPUT 4 SAMPLE OUTPUT 2 Explanation There are only two natural numbers, the product of the digits of which is 4 - 4, 22.

Finding vaccines

 You are creating a vaccine to fight against a worldwide novel pandemic virus. A vaccine contains a weakened virus that is injected inside people to produce antibodies to let it fight against the virus. The study of interaction among RNA of various viruses is quite necessary for this. An RNA consists of four types of molecules Guanine ( G ), Adenine ( A ), Cytosine ( C ), and Uracil ( U ). You are given the structures of RNA for the pandemic virus and several vaccine viruses in the form of strings containing characters   G ,   A ,   C , and   U   representing respective molecules. You know that if there is higher interaction between the pandemic virus and vaccine virus, then better the vaccine will be. You also know that the only interaction between any two RNAs is a result of the interaction between their Guanine ( G ) and Cytosine ( C ) molecules. Formally, if the strings for RNA structures are...

Popular posts from this blog

MySQL Multi Source Master Slave Replication using GTID

Setting Up PostgreSQL Logical Replication with Docker Compose

Regex 101: An Introduction to Regular Expressions for Developers