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.

**Constraints:**

1 <= T <= 100

1 <= N <= 10^{3}

1 <= K <= 10^{6}

1 <= A[i] <= 10^{6}

**Example:
Input:**

1

5 1

2 1 5 7 6

**Output:**

1 2 5 6 7

-1

**Explanation:
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.

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.

cs_abhi | 62 |

kya_bolti_public | 56 |

Shubhankar Sharma | 44 |

vermaankush14291 | 42 |

coderquill | 40 |

PiyushPandey4 | 856 |

john_wick | 757 |

ASWATHAMA | 565 |

akhyasharma01 | 547 |

UsfShilpa | 536 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.