Hi, In my opinion to excel in competitive programming you need to take one step at a time. Just list the topics that you need to work on eg.
Arrays
Dynamic programming
Recursion
Linked List
Then, start working on single topics at a time. When you cover all the topics then, start picking questions from any random topic and think to you apply the concepts that you have already studied. And this will boost your confidence. When you have all the tools in your bag-pack then, only your are able to solve any problem. Suppose you have study Recursion and Greedy algorithms topic very well. But I have given you the problem of dynamic programming then, you won’t able to solve it right ? So, when you have knowledge of every concept of CP then, you are able to solve any problem or start approaching a given problem with correct mind set.
Hey Shubham! Thanks for sharing this idea! I had used the same idea in the contest but was unfortunately getting wrong answer for the last test case. Can you please help me with my solution.
I am getting 3 WA in subtask3.
someone, please tell me where I am going wrong.
approach:
traversing from start
skip the index where value is correct.
else rotate the triplets (selection of triplet indexes is explained below)
In the end, If I find a pair (cycle of 2), and the rest of the elements are on their correct place then it is not possible to sort the array.
selection of triplets in the following way.
i1 i2 i3
i1 is the current index where value is on incorrect position
i3 is the index where that value is present which should be at i1.
i2 is the index where that value is present which should be at i3.
In the case of the cycle of 2.
I select i2 the next index where value is incorrect.