I’ve been attempting the CF problem “An impassioned circulation of affection”. I came up with a solution in Java, but it gives me TLE. I thought the time complexity of my program was O(n*q), which I thought should pass the constraints of the problem, but it gives me TLE. Therefore, I was wondering what I was doing wrong. Here is the link to my code: https://replit.com/@NehaMetlapalli/C-An-impassioned-circulation-of-affection#Main.java
I appreciate all help. Thanks!