This is the blog of site xoptutorials.com. All the news will be posted here and on the facebook page of xoptutorials.
Showing posts with label HackerRank::Algorithms::Warmup. Show all posts
Showing posts with label HackerRank::Algorithms::Warmup. Show all posts
Monday, September 7, 2015
Thursday, July 30, 2015
HackerRank::Algorithms::Warmup::Time Conversion
This is a basic implementation task, we need to add 12 to the hour number if necessary and output the result, be sure to implement carefully , take care of hour == 24 and if you are about to output a single digit as a minute, second or hour output it in format 0[digit] , don't forget the 0.
Wednesday, July 22, 2015
HackerRank::Algorithms::Warmup::Service Lane
I think understanding this task is a lot harder than the solution itself, so I will not spoil it for you, try to understand it, and trust me it's about finding the minimum number in the given segment ;)
HacerRank::Algorithms::Warmup::Extra long factorials
For solving this I again used my handy bigInt class for C++ which still lacks the division operation but has all it needs to sovle this task. Although, I encountered another problem, for some reason the submission receives "Abort Called" message when submitted in hackerrank , I don't know the reason, it works fine on my computer, anyway, I made a precalculated list of factorials and got accepted, either way the class itself is included in the source code below, it works fine.
HacerRank::Algorithms::Warmup::Caesar Cipher
Simply loop over all the characters, check whether the current character is a letter or not and then simply get the K-th next letter. Check the source code for a better understanding.
Tuesday, July 21, 2015
HacerRank::Algorithms::Warmup::Library Fine
There are just some if statements to check and output the corresponding answer for each case.
Sunday, July 19, 2015
HackerRank::Algorithms::Warmup::Staircase
In any case, out output answer has to be an NxN array with either space bars of with '#' symbols. The # sybol has to appear only in the cells where in the coordinate [X,Y] the Y is more or equal than N-X.
HackerRank::Algorithms::Warmup::Plus Minus
There is not much to explain here, simply count the number of negatives, positives and zeros and divide on N.
HackerRank::Algorithms::Warmup::Diagonal Difference
For any I from 1 to N , the indexes of the first diagonal's elements are [I,I] and the second diagonal's elements will have the index [I, N-I] ( if numeration starts from 1).
Saturday, July 18, 2015
Saturday, April 18, 2015
HackerRank::Algorithms::Warmup::Sherlock and The Beast
N is maximum 100000, and based on that here is a very very simple solution. Simply take all the numbers which are divisible by 3 which will show the numbers of 5s, then check if the remaining number of digits is divisible on 5, if it is, then we should update our answer, and in the end print it out.
HackerRank::Algorithms::Warmup::Identify Smith Numbers
We need to prime factorize the number and take the sum of digits of the factors and compare to the sum of digits of the initial number. Factorizing takes somewhat sqrt(N) time so it will fit in the time limit.
HackerRank::Algorithms::Warmup::Kaprekar Numbers
I chose not to give this much a lot of thinking. I made a little ugly-looking brute-force solution which found the Kaprekar numbers (there are not too many of them, about 20 numbers from 0 to 100000). And then , for getting accepted I just put in those 20 numbers in an array and processed the input.
HackerRank::Algorithms::Warmup::Is Fibo
80th Fibonacci numbers is much bigger than 10^10 which means even by looping over all the possible numbers for checking whether the given number is a Fibonacci number or not will take something like 10^5 * 80 which is enough for getting AC.
HackerRank::Algorithms::Warmup::Max Min
We simply sort out the array and take the minimum difference of the first and last numbers of every continuous subsequence of length K.
Wednesday, April 15, 2015
HackerRank::Algorithms::Warmup::Filling Jars
Look at the question carefully " the average number of candies" which means that we don't care about the interval [A,B] all we care for is the total number of candies which can be calculated easily.
HackerRank::Contests::ProjectEuler::Project Euler #7: 10001st prime
The 10001st prime number is not a big one, so jsut using a sieve of Eratosthenes for to find the prime numbers up to 5000000 is more than enough. For reading more info about the sieve of Eratosthenes go here.
Sunday, April 12, 2015
HackerRank::Algorithms::Warmup::Sherlock and Squares
The first look at the constraints is very important. A,B<=10^9. Among this there are sqrt(1000000000) almost 32000 numbers which are squares of natural numbers. Initially before processing the input, we need to write out all the full square number and store them somewhere. Then after reading the input, we need to loop over all the numbers and check if they are in the given range or not ( be attentive, we need to loop over the number which we found, and check whether they are in the range or not, not vice versa ).
HackerRank::Algorithms::Warmup::Taum and B'day
We will call the two types as "cheap" and "expensive", the cheap one obviously is the one which is cheaper than the other. If the prices are equal than there is no difference whether we name the first one as the "cheap" one or the second one. We need to buy all the required gifts off the cheap type. Then, if buying another cheap gift and converting it to the other type is still cheaper than the original price of the expensive gift, then we buy all the first with the "cheap" value and convert the necessary amount to the other type, otherwise we buy the expensive ones with their price.
Subscribe to:
Posts (Atom)