samhackerrank
samhackerrank
SamHackerrank
11 posts
First, solve the problem. Then, write the code
Don't wanna be here? Send us removal request.
samhackerrank · 4 years ago
Photo
Tumblr media
G D01 - Rotate The Array 3
Given an array of integers of size n, rotate it's elements towards right K times.
Note: One rotation of the array (a0, a1, a2... an-1, an) results into (an, a1, a2...., an-2, an-1).
Explanation for a Sample i/o
Sample Input: 5 1 3 5 7 9 3
Sample Output: 5 7 9 1 3
Explanation: We have to perform 3 rotations : 1st rotation : 9 1 3 5 7 2nd rotation : 7 9 1 3 5 3rd rotation : 5 7 9 1 3
Input Format
First line contains an integer n. Second line contains n integers, denoting the array a[n]. Third line contains one integer k, the number of times the array is to be rotated.
Constraints
1 <= n <= 1000
Output Format
Output n integers, denoting the array a[n] after rotation.
Sample Input 0
5 1 3 5 7 9 3
Sample Output 0
5 7 9 1 3
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
Z 403 Sum of all Digits
You are given an integer I in the following format : You are given two integers P and Q. Integer I can be obtained by appending Q instances of P together. For example, if P = 619 and Q = 4, then I = 619619619619.
Your task is, given P and Q find the sum of all the digits of I. That sounds too simple, so lets take it up a notch. Lets say the sum of all digits is S, then run the following pseudocode :
int SumOfDigits(S) : K <- Sum of Digits of S    if K is a single digit number, return K    else return SumOfDigits(K)
INPUT
Input consist of two numbers P and Q separated by a space.
OUTPUT
Print a single digit, the final digit when the numbers of I are continuously added.
CONSTRAINTS
1 ≤ P ≤ 10100000 **1 ≤ Q ≤ **105
Sample Input 0
148 3
Sample Output 0
3
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
Number of digits in N!
As simple as the title, given a number N, print the number of digits in N!
N! is defined as : N! = 1*2*3...(N-1)*N
0! = 0 and 1! = 1.
No number ever contains any leading zeros.
Input Format
Input contains only one number, N.
Constraints
1 <= N <= 1000
Output Format
Output one number that is equal to the number of digits in N!
Sample Input 0
6
Sample Output 0
3
Explanation 0
6! = 1x2x3x4x5x6 = 720 which has 3 digits. So the answer is 3.
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
Z 412 The Slopes of Line Segments
In the town of line segments two line segments can only become friends if their slopes are equal. Line segments are not smart enough to calculate their own or some other line segment's slope so they use a machine called the slopeFinder to check their compatibility. Recently someone stole the slopeFinder and now the line segments are upset because they cannot make new friends. The Mayor of the town has hired you to write a code to fix the crisis that their town is facing.
Input Format
Input Contains two line segments each on a line of its own. Each line segment is denoted by four integers Xa, Ya, Xb and Yb where (Xa,Ya) and (Xb, Yb) denote the two end points of the line segment.
Constraints
0 <= |Xa|,|Xb|,|Ya|,|Yb| <= 100
Output Format
Output "yes" if both the line segments have the same slope and "no" otherwise. (without the quotes).
Sample Input 0
0 0 1 1 1 0 2 1
Sample Output 0
yes
Sample Input 1
0 0 1 1 2 1 3 0
Sample Output 1
no
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
I M16 - Exclusive Or
Find the XOR of two numbers and print it.
Hint : Input the numbers as strings.
Input Format
First line contains first number X and second line contains second number Y. The numbers will be given to you in binary form.
Constraints
0 <= X <= 2^1000 0 <= Y <= 2^1000
Output Format
Output one number in binary format, the XOR of two numbers.
Sample Input 0
11011 10101
Sample Output 0
01110
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
C D04 - Trouble with the Number System
Barua has developed his own Operating System known as "Barua OS" ( BOS ). One day while booting up his system he runs into a bug. You want to impress Barua so you jump in and offer to solve the bug yourself. Barua doesn't like binary numbers very much and his operating system uses a new number system called BNS ( Barua Number System ). The following are the properties of a number represented in BNS form :
The number can only be made up of 2 distinct digits, one or zero.
The number cannot start with zero.
The number can have any number of zeroes, but only one instance of the digit one.
For example 100, 1000, 10000 are Barua Numbers whereas 101, 502, 625 are not Barua Numbers. Unfortunately one decimal number has crept into a list of Barua Numbers and Barua OS cannot find its product. Can you?
Input Format:
First line contains an integer N, total number of elements in the list.
Next N lines contains a number a[i] <= 10^18.
NOTE : Out of the N numbers, there will be at most 1 decimal number and the remaining numbers will be Barua Numbers. There may be no decimal numbers at all.
Output Format: Print one number, the product of all the numbers.
Input Constraints:
1 <= N <= 10^6
1 <= A[i] <= 10^18
Sample Input 0
4 100 121 10 100
Sample Output 0
12100000
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
F D01 - Array as a Hill
Array of integers is a hill, if:
it is strictly increasing in the beginning;
after that it is constant;
after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arrays are a hill: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].
Write a program that checks if an array is a hill.
Input Format
The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of the array.
Output Format
Print "yes" if the given array is a hill. Otherwise, print "no".
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
Z 431 PaneerLove
Chappu is addicted to Paneer! Nikau wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly a[i] kilograms of Paneer.
There is a big shop uptown and Nikau wants to buy Paneer for her from there. In i-th day, they sell Paneer for pi dollars per kilogram.
Nikau knows all numbers a1,...,an and p1,...,pn. In each day, he can buy arbitrary amount of Paneer, also he can keep some Paneer he has for the future.
Nikau is a little tired from cooking Paneer, so he asked for your help. Help him to minimize the total money he spends to keep Chappu happy for n days.
Input Format
The first line of input contains integer n (1<=n<=10^5), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1<=ai, pi<=100), the amount of Paneer Chappu needs and the cost of Paneer in that day.
Constraints
1 <= n <= 10^5
Output Format
Print the minimum money needed to keep Chappu happy for n days, in one line.
Sample Input 0
3 1 3 2 2 3 1
Sample Output 0
10
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
Alice And Boat Trips 
Alice owns a company that transports tour groups between two islands. She has n trips booked, and each trip has pi passengers. Alice has m boats for transporting people, and each boat's maximum capacity is c passengers.
Given the number of passengers going on each trip, determine whether or not Alice can perform all n trips using no more than m boats per individual trip. If this is possible, print Yes; otherwise, print No.
Input Format
The first line contains three space-separated integers describing the respective values of n (number of trips), c (boat capacity), and m (total number of boats). The second line contains n space-separated integers describing the values of p0, p1, p2... pn-1
Constraints
1 <= n,c,m <= 100 1 <= pi <= 100
Output Format
Print Yes if Alice can perform all n booked trips using no more than m boats per trip; otherwise, print No.
Sample Input 0
5 2 2 1 2 1 4 3
Sample Output 0
Yes
Explanation 0
Sample Input 1
5 1 2 1 2 1 4 1
Sample Output 1
No
Explanation 1
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
T 114 - Equal Bases
Given a decimal number N, you need to find the number of bases 1 < b <= n such that when the number N is represented in base 'b', it ends in a zero.
Input Format
Input contains only one number, N.
Constraints
1 <= N <= 10000
Output Format
Output one number, the number of bases b such that when number N is represented in base b, the number contains a trailing zero.
Sample Input 0
12
Sample Output 0
5
Explanation 0
Base : Number : 2 1100 3 110 4 30 5 22 6 20 7 15 8 14 9 13 10 12 11 11 12 10
12 ends with a zero in 5 different number systems - 2,3,4,6 and 12. Hence the answer is 12.
0 notes
samhackerrank · 4 years ago
Photo
Tumblr media
A DO1 CUT THE FRUIT
One a hot summer day Aarti and her friend Anurag decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Aarti and Anurag are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal.
They are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Format
The first (and the only) input line contains integer number w — the weight of the watermelon bought by them.
Constraints
1 ≤ w ≤ 100
Output Format
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Sample Input 0
8
Sample Output 0
YES
Explanation 0
The boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos)
1 note · View note