Input taken in ques

how do we take input in this question.

@Zainul17192 wait bro giving ya reference

@Zainul17192 Bro this is the whole logic, with input and removing cycle.

Set map = new HashSet();
int inp = scn.nextInt();
for (; inp > -1;) {
if(!map.contains(inp)) {
list.addLast(inp);
map.add(inp);
} else {
list.tail = null;
}
inp = scn.nextInt();
}
See There is a cycle for sure in this question as mentioned and cycle can only start with a tail.
Now do one thing dry run it with sample ya will get it!
Also bro if ya query is clear mark it resolved and rate full!
Happy coding!