CSES - Number Spiral - Java TLE
I assume you refer to https://cses.fi/problemset/task/1071/ .
Your Algorithm itself is fine as far is i can tell.
The Problem is the large amount of inputs that need to need to be read(Testcases=100000), which Scanner cant provide within the 1s time limit.
A BufferedReader should offer the performance needed for this.(See https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/ for more information).
The same might apply to System.out.println in which case it would be better to use a BufferedWriter