We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Try to solve in Java. Calculating all next lexicographical permutation using this logic. But Test#1, #2 says 4s Terminated due to time out. Any suggestion?
BufferedReaderin=newBufferedReader(newInputStreamReader(System.in));intnum=Integer.parseInt(in.readLine());Stringline="";for(inti=0;i<num;i++){line=in.readLine();// Do your stuff here}
@shraiysh Can you explain the logic here. The lexicographical permutation solution didnt work for me. It is giving me runtime error. But your code is working for me. I dont understand why.
Bigger is Greater
You are viewing a single comment's thread. Return to all comments →
Try to solve in Java. Calculating all next lexicographical permutation using this logic. But Test#1, #2 says 4s Terminated due to time out. Any suggestion?
test the case when input is just one letter (e.g. p), the output should be "no answer". This solved my problem.
no it didn't solved
first of all check if same letters are repeating
int main() {
}
}
Possible implementation from cppreference.com
thanks, it solved my problem.
Thanks. It helped to pass test cases #1 and #2
such a relief!!!
Try to use
to read the input. It has 100000 test cases so Scanner won't work
can you please tell how to BufferReader to scan multiple lines of Strings with Exception Handling
here is what i did:
Thanks buddy
didn't work, i still get timeouts
I did this.. Lengthy but worked.
@shraiysh Can you explain the logic here. The lexicographical permutation solution didnt work for me. It is giving me runtime error. But your code is working for me. I dont understand why.
For me it threw a runtime error when I was not concidereing w.length = 1 cases.
It did not work. It stuck in line 20348
Scanner will work in these cases. I submitted using scanner. The problem must lie elsewhere.
thanks! that is what I needed. Don't really know why Scanner is slower than buffreader though.
Simple java solution : algorithm n wikipedia
this logic is to rev the string in O(n) time and O(1) space. can u explain, how this iis working?
its actually n/2
Use this to find no answer without solving:
https://www.hackerrank.com/challenges/bigger-is-greater/forum/comments/595411
I am having the same TLE problem in test #1 and #2. Can someone help me out?