During the coding interview, the most important is don’t hesitate or afraid to ask questions about the task. It will not only make your understanding the task better, but it also shows your attitude towards solving challenging tasks.
I think it’s often OK to provide the simplest solution even if it’s not the most optimal. Especially if the goal of the interview is to test your coding skills, not your algorithmic knowledge. Commend down whatever you are doing, it will show how you think about the task.
To summarize, I would suggest you remain confident, know your language, and don’t be afraid to ask questions.
For most frequently asked Java questions, check out this Java Interview Questions blog by Intellipaat.