Posts

Showing posts from 2017

Sort 5 multiples in ascending order using java

For this challenge, you will be given an array and you are asked to find multiples of 5 in the given array, sort and put them first in the array. Rest all the elements will preserve their orders.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  print the required array to the STDOUT.  Sample Test Case:   Sample Input: - 6 9 14 15 10 8 5 Sample Output  -  5 10 15 9 14 8

Count triplet in java

Task  -  You will be given an array and a number and you need to find the number of triplet in the array whose sum is equal to given number in the input.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them. Next line should have a integer value.  Output Format  -  you need to print the number of triplet of integers in the array whose sum is equal to the given integer.  Sample Test Case:   Sample Input: - 4 2 5 7 -1 6  Sample Output  -  1 Explanation:   There is 1 triplet with sum 6 which is (2, 5, -1). So, output is 1.

Third Largest in java.

You will be given 4 numbers one on each line and you are asked to find the second largest number and print them to the STDOUT .  Input Format  -  You will take 4 integers as input from STDIN.  Output Format  -  print your result which will be the integer only to the STDOUT.  Sample Test Case:   Sample Input: - 234 213 666 879  Sample Output  -  234

Add occurrences of thrice in java

In this challenge you need to check for thrice occurrences in array and sum it up. Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  You need to print the sum of the numbers occurring Thrice.  Sample Test Case:   Sample Input: - 12 9 8 7 7 8 6 5 4 7 8 1 2  Sample Output  -  15 Explanation:   elements 8 and 7 occurring Thrice and their sum is 15.

Second to smaller and larger in java

You will be given an array and you need to find the second largest and second smallest numbers and add them.  Note:  the length of the array should not be less than 2.  Input Format  -  you will be taking a number as an input from stdin which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  you need to print the addition of second largest and second smallest elements to the stdout.  Sample Test Case:   Sample Input: - 7 48 77 7 11 49 99 78 Sample Output  -  89

Largest Even in java

Task - For this challenge, you will be given an array and you are asked to find the largest even number and print it to the STDOUT.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  print the largest even number to the STDOUT.  Sample Test Case:   Sample Input: - 6 78 92 44 63 71 97 Sample Output  -  92  Explanation:   In the given array, 78, 92 and 44 are the even numbers and we need to find the largest even number which is 92.

Multiply Negative numbers in java

For this challenge, you will be given an array and you are asked to count how many numbers are negative and multiply them and print the output to the STDOUT.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  print the multiplication to the STDOUT.  Sample Test Case:   Sample Input: - 7 -8 -7 6 0 7 -1 6 Sample Output  -  -56  Explanation:   There are three negative numbers present in the array and their multiplication comes out to be -56.

Check Occurrences in java

You will be given an array and you need to find the whether there is any element occurring thrice. If yes, then print 'True' else print 'False'  Input Format  -  You will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  You need to print the Boolean value.  Sample Test Case:   Sample Input: - 12 9 8 7 7 8 6 5 4 7 8 1 2  Sample Output  -  True  Explanation:   Elements 8 and 7 occurring Thrice and hence printing 'True'.

Second Odd Largest in java

You will be given an array and you need to find the second largest odd number and print it to the STDOUT.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  you need to print the second largest odd number to the STDOUT.  Sample Test Case:   Sample Input: - 7  25 26 7 8 10 11 79  Sample Output  -  25 

Squaring Every Index in java

You will be given an array and you need to square the elements of the array, add them and print them to the stdout.  Input Format  -  you will be taking a number as an input from stdin which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  You need to print the sum of the numbers.  Sample Test Case:   Sample Input: - 12  9 8 7 7 8 6 5 4 6 5 1 2  Sample Output  -  450 

Second Largest Even in java

For this challenge, you will be given an array and you are asked to find the second largest even number and print it to the stdout.  Input Format  -  you will be taking a number as an input from stdin which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  print the second largest even number to the stdout.  Sample Test Case:   Sample Input: - 6 78 92 44 63 71 97 Sample Output  -  78 

Leaders in Java

  Write a program to print all the LEADERS in the array. An element is leader if it is greater than all the elements to its right side. And the rightmost element is always a leader. For example int the array {16, 17, 4, 3, 5, 2}, leaders are 17, 5 and 2. Sample Test Case:  Sample Input:- 6 16 17 4 3 5 2 Sample Output -  17 5 2 

Finding Reverse in java

Task  -  For this challenge, you will be given an integer and an array and you are asked to find the reverse of the number in the array.  Input Format  -  you will be taking a number as an input from stdin which tells about the length of the array. On another line, array elements should be there with single space between them. Next line, there is an integer whose reverse need to be found.  Output Format  -  print 'True' if the reverse of the number is present in the array otherwise return 'False'.  Sample Test Case:   Sample Input: - 6 78 92 44 63 71 97 29 Sample Output  -  True  Explanation:   Given integer is 29 and the reverse of the number is 92 and it is present in the array. Hence, print 'True'.

Count In Range and Specific in java

Task  -  You will be given an array and a range and you need to count how many array elements lies in that range and not divisible by 3 and 5.  Input Format  -  You will take an integer as input from STDIN which represent the length of the array and on another line array elements will be there separated by single space. Another line will have the starting point of the range and end point separated by space.  Output Format  -  print the count to the STDOUT.  Sample Test Case:   Sample Input: - 6 16 17 4 3 5 2 2 10 Sample Output  -  2

Discard Specific Content in java

For this challenge, you will be given an array and you are  * asked to find multiples of 5 and 10 both in the given array,  * remove them from the array. Rest all the elements will  * preserve their orders.  *  * Input Format - you will be taking a number as an input from  * stdin which tells about the length of the array. On another line,  * array elements should be there with single space between them.  * Output Format - print the required array to the stdout.   Sample Test Case:   Sample Input:- 7 10 20 15 2 4 7 8 Sample Output - 15 2 4 7 8 Input: 7 10 20 15 2 4 7 8 Output: 15 2 4 7 8

War Between Even And Odd in Java

You will be given an array and you need to find odd numbers and add them, find even numbers and add them. Then compare the result, if the sum of even numbers found to be greater then print 'Even' to the output, if sum of odd number is greater than print 'odd' to the output. If sum of both found to be equal, then print 'Tied' to the output. Input 9 74 32 31 91 77 88 96 44 23 Output: Even Input: 5 2 3 4 9 6 Output: Tied

Equal to Zero in java

You will be given an array and you need to find those three elements whose sum are equal to 0.If found print True to the output else print False.Note: The length of the array should not be less than 3. Input 6 1 1 1 1 1 1 output: False Input: 6 79 60 -44 -16 22 33 Output: True  since(60+(-44)+(-16)=0)

Search Small Ones in Java

You are given with an array, now you need to find the small and second small element from the array and then show sum of small and second small output. Input 4 1 0 -1 2 Output: -1 Input: 7 1 2 3 4 5 6 7 Output: 3

Min and Max in java

Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. Sample Input 1 2 3 4 5 Sample Output 10 14 Explanation Our initial numbers are  ,  ,  ,  , and  . We can calculate the following sums using four of the five integers: If we sum everything except  , our sum is  . If we sum everything except  , our sum is  . If we sum everything except  , our sum is  . If we sum everything except  , our sum is  . If we sum everything except  , our sum is  . As you can see, the minimal sum is   and the maximal sum is  . Thus, we print these minimal and maximal sums as two space-separated integers on a new line. Hints:  Beware of integer overflow! Use 64-bit Integer.