Geeksforgeeks

Timer is Running

Given an array **A** of size **N**. Print all the numbers less than K in the array. The numbers should be such that the difference between every adjacent digit should be **1**.

**Note:** Print **'-1' **if no number if valid.

**Input:**

The first line consists of an integer **T** i.e number of test cases. **T** testcases follow. Each testcase contains two lines of input. The first line consists of two integers **N** and **K **separated by a space. The next line consists of **N** spaced integers.

**Output:**

For each testcase, print the required output.

**Constraints: **

1 <= T <= 100

1 <= N <= 10^{7}

1 <= K, A[i] <= 10^{18}

**Example:
Input:**

2

8 54

7 98 56 43 45 23 12 8

10 1000

87 89 45 235 465 765 123 987 499 655

**Output:**

43 45 23 12

87 89 45 765 123 987

**Explanation:
Testcase1: **43 45 23 12 all these numbers have adjacent digits diff as 1 and they are less than 54

Author: support3

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.

Pathak1899 | 436 |

yashdip123 | 380 |

kirtidee18 | 377 |

ykaushik | 261 |

_saswata | 232 |

kirtidee18 | 1057 |

ykaushik | 733 |

aggarwalvatsal5 | 709 |

pmr_3689 | 570 |

harbilassingh | 530 |

blackshadows | 5456 |

Ibrahim Nash | 5450 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4823 |

Login to report an issue on this page.