HackerRank challenges with solutions (Rearrangement, Formula, Word sorting, Numbers, Sentence)

 1. Rearrangement

Given a list A elements of length n , ranging from 1 to n. All elements may not be present in the array. If the element is not present then there will be -1 present in the array. Rearrange the array such that A[i]=i
and if i is not present display -1 at that place.

Input format :
The first line contains a n numbers with each number separated by space.

Output format :
Print the elements of the list after modification.

Sample input :
-1 -1 6 1 9 3 2 -1 4 -1

Sample Output :
-1 1 2 3 4 -1 6 -1 -1 9

Explanation :
The modified list contains elements such that A[i]=i .

Code :

rearrangement in python












Output :


 




2. Formula
Write a program that calculates and prints the value according to the given formula , Q=square root of [(2*C*D)/H]. Following are the fixed values of C and H , C=50 ,H=30.
D is the variable whose values should be input to your program in a comma separated sequence.

Input format :
A sequence of values for D with each value
separated by comma.

Output format :
Print the sequence of Q values with each value separated by comma.

Sample input :
100,150,180

Sample Output :
18,22,24

Code :

formula in python











Output :









3. Word Sorting
Write a program that accepts a comma separated sequence of words as input and
prints the words in a comma separated sequence after alphabetically sorting them.

Input format :
The first line of input contains words separated by comma.

Output format :
Print the sorted words separated by comma.

Sample input :
world,bag, without,hello

Sample Output :
bag,hello, without,world

Code :

word sorting in python







Output :







4. Numbers
Write a program which will find all such numbers between m and n ( both included )
Such that each digit of the number is an even number.

Input format :
The first line contains value m and n separated by comma.

Output format :
The numbers obtained should be printed in a comma separated sequence on a single line.

Sample input :
1000,2024

Sample Output :
2000,2002,2004,2006,2008,2020,2022,2024

Code :

numbers in python





















Output :







5. Sentence
Write a program that accepts a sequence of lines as input and prints the line after making all characters in the sentence capitalised.

Input format :
The first line of input contains a number N which represents the number of lines. From second line there are statements which has to be converted. Each statement comes in a new line.

Output format :
Print the statements with each word in capital letters.

Sample input :
2
Hi everyone
Welcome world

Sample Output :
HI EVERYONE
WELCOME WORLD

Code :


sentence in python








Output :



Comments

Popular posts from this blog

Finding the percentage in python - HackerRank solution

ginortS in Python - HackerRank solution