After taking care of the last digit cases, I’m using a greedy approach to find the first number that on removal will lead to (sum of digits) %3=0 and has the next number greater than itself. If such a number doesn’t exist, I remove the lowest rightmost number that will lead to that result.

x < a[i+1]-‘0’ this condition is wrong because it doesn’t guarantee that the resulting number after deleting a digit will be greater than the one you found earlier.

I’m noob in java so I can’t help you with why your code gives no output but I can say that you’ve read the question wrong.
I see you’ve taken input as integer which is wrong because the input constraint says that input number can be of 10^5 digits long i.e input number can be 10^(10^5) which your long int input can’t handle.
Try implementing using string.

Can anyone give me a test case where my code fails? It’s working well for all the test cases I checked.

PLEASE HELP ME!!!

I’m storing the digits in an array from one’s place. Then I am iterating through all the digits and finding the new number by removing that particular digit. Now, I’m checking whether it is divisible by 6 or not and if it is then I check whether it is largest number possible which I initially set to -1. At last I’m printing the new number with k-1 digits where k is the total number of digits in the initial number. Leading zeros will be printed since I used %0*d and passed k-1 and maxnum to it.
LINK:- My Solution