Greater and Smaller Ones
Submissions: 778   Accuracy:


  Difficulty: Easy   Marks: 2
Associated Course(s):   Fork Java

Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array(including K as well if present in the array A), and print all the elements which are smaller than K in seperate lines. If the elements greater than K does not present in the array then print "-1". Similarly, in case of smaller elements print -1 if elements smaller than k doesn’t exist.

Input Format:
First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K seperated by space, next line contains N space seperated integers.

Output Format:
For each testcase, print the required elements(if any), else print "-1" (without quotes).

Your Task:
Since this is a function problem, you don't need to take any input. Just complete the provided greaterKSorted and smallerKSorted functions that takes two input one is array and second is K.

1 <= T <= 100
1 <= N <= 103
1 <= K <= 106
1 <= A[i] <= 106


5 1
2 1 5 7 6

1 2 5 6 7

Testcase 1 :
Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array.

** For More Input/Output Examples Use 'Expected Output' option **

Author: Dhiman Mayank

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.