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 : 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