class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); // Number of test cases while (t-- > 0) { int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } HashMap<Integer, Integer> map1 = new HashMap<>(); HashMap<Integer, Integer> map2 = new HashMap<>(); for (int i = 0; i < n; i++) { if (map1.containsKey(arr[i])) { map2.put(arr[i], i); } else { map1.put(arr[i], i); } } HashSet<Integer> set = new HashSet<>(); int sum = 0; // Total cost for (int i = 0; i < n; i++) { int l = map1.get(arr[i]); int r = map2.getOrDefault(arr[i], l); while (l < r) { if (map2.containsKey(arr[l]) && map2.get(arr[l]) <= r) { l++; } else if (map2.containsKey(arr[l])) { r = map2.get(arr[l]); l++; } else { break; } } sum += r - l + 1; set.add(arr[i]); } System.out.println(sum - set.size()); } } } Why is this code failing?
@NeverLoose-v5iКүн бұрын
Very Nicely Explained C
@nithiishmakkena1984Күн бұрын
For 01 it can be done in 2 operations but according to ur code it is giving one operation
@nithiishmakkena1984Күн бұрын
X is 2 and k is 1
@pradyumnkejriwal3007Күн бұрын
You can directly remove 01 in one operation because it has 0 inversions and 0 ≤ x and 0 is divisible by k
@Thanos_i9Күн бұрын
Comefrom CF blog
@UCSAmitSinghBishtКүн бұрын
great explanation for D bro
@HarshitKumar-dj4evКүн бұрын
Perfect explanation both mathematically as well as intuitively. Really liked the approach to explain!!
@JIGARSINGTHAKOR-yy6qpКүн бұрын
For E ❤
@manpatel9654Күн бұрын
Crystal Clear explanation for D🔥 Thank You sir❤
@Nerds_KingКүн бұрын
sir, in problem E, you could have explained using binary numbers with a1, a2, a3, a4,... but nevertheless it was a great explanation. Really helpful.
@AvanagantiAkshathreddyКүн бұрын
Explanation for problem E is very clean and intuitive, thanks!
@master_26_10Күн бұрын
Usually, whoever linkdel profile has title of pupil. He is 3 star on codechef. But despite of having 1247 on cf, I am stuck on 2 star on codechef. For me it's like solving 2 q in 10 min of div3 and then being stuck. Maier time I have solved 3rd q early also. But many times, I do fail. Sugestion pls. It's been 8 month, I am 2 star. 😢
@naman.0316Күн бұрын
Just my 2 cents on it, focus more on Number theory and Bit Manipulation questions, and you'll easily breeze through 3 stars as well 😃
@vikash-sinhaCSКүн бұрын
@master_26_10 us bro us 😢😢
@HarshitKumar-dj4evКүн бұрын
@@naman.0316 Bro, give me advice as well for 4*. I am stuck on 3* and just advancing in each contest at an average pace of +5 (since I am getting and + and - rating alternatively contest). By this pace, reaching 1800 would take months. I am stuck on Div 2-D in codechef as well as codeforces.
@cse_48_niloyroy35Күн бұрын
In the same situation...😢
@TLE_EliminatorsКүн бұрын
Please fill the Feedback form for PCD: forms.gle/eKCcKwD9pQLTr9Xb8
@allmighty20002 күн бұрын
4th problem is the definition of a good problem
@Abhishek-e6d2c2 күн бұрын
what an explanation for E!!
@raisanjeeb422 күн бұрын
Nice explanation
@manoor08582 күн бұрын
so smart for odd one i just used like 10 testcases and it finally worked out
@rocktar64633 күн бұрын
best explanation
@juswanth.t1333 күн бұрын
For E1, I think you are mentioning we can achieve 'w' at the kth position if we have strictly less than k weights greater than 'w' in some path. I think we can only say we can achieve some weight <= w in that case. Since we are taking the minimum 'w', we end up getting the right answer. Correct me if it's wrong.
@nikhilprakash7293 күн бұрын
Great Explanation......
@why_code20233 күн бұрын
Good explanation for C! You broke things down very well. The first thing that we think for this problem is classic pick/ not pick -> dp( i , cur_difference, prev_element ). But this will TLE. And thinking top down for the correct approach is not super intuitive.
@KenOrSomething4 күн бұрын
TLE on test case 11 for problem B for your code
@TarunGupta-f7s3 күн бұрын
i think you use unordered_map
@KenOrSomething3 күн бұрын
@@TarunGupta-f7s I don't know how you knew that but thank you! although i don't understand how using a normal map doesn't exceed TLE as inserting elements in map takes more time than unordered maps ?
@namanlalwani80794 күн бұрын
s = "nrnrs" , p = "*nn" is this true or false ? ( basically its an edge case for me )
@NeverLoose-v5i4 күн бұрын
nice explanation.
@itzzRaghav4 күн бұрын
Thank you so much.
@ppl_call_me_tima4 күн бұрын
thanks for the easy editorial
@CE073_lakshkyada4 күн бұрын
Solution of D please
@dhruvsolanki44734 күн бұрын
Really good explanation helped in solving yesterday's LeetCode problem 2381. Shifting Letters 2, thank you.
@vatsaljain6622 күн бұрын
bro i didn't understand the technique priyanshj explained and also couldn't solve the yersterday's daily question.. can u plz explain the technique to me and how did u do it ??
@dhruvsolanki44732 күн бұрын
@@vatsaljain662 In yesterday's problem we just need to add +1 to i index and -1 to j+1 index if direction is 1 else do the reverse, add -1 to i index and +1 to j+1 index, skip adding to j+1 index if j+1 is out of length. And at last do the prefix sum of this array, it will give you how many shifts will each index have to do. In the beginning array will be of size word and all values will be 0.
@Abc-lr4bf4 күн бұрын
nice explanation soumojit
@KaviselvaramKathirvel4 күн бұрын
I was only able to solve 2 questions from the contest !!
@Travel-s5e4 күн бұрын
can anybody tell me why that l to r loop not giving tle
@setyourhandle29974 күн бұрын
we are breaking out of the loop as soon as we find a number that is neither equal to a nor equal to b , for example if l was 10 r was 100 , a was 11and b was 10 we would break out of the loop as soon as we reach 12
@Travel-s5e4 күн бұрын
@@setyourhandle2997 thanks bhai , one more question how can we say that after setting a and b like that then our max answer will be independent i hope you are getting like we if our l=50 and r=60 , and then if a was coming as =54 and b=58 (just consider) then our c will be coming as 50 right , but what the proof that like a^b will get maximise but we are not having any proof for b^c and c^a
@setyourhandle29974 күн бұрын
@@Travel-s5e if you work it out you will realize that if we choose a and b like this as stated in solution , then whatever our c will be , the final answer will be the same , only c has to be not equal to a and b
@Travel-s5e4 күн бұрын
can anybody tell me why when l is something of 00000 and r is something or 111111 then we know our a=100000.. and b=01111.... and if we are taking c as 0 then we can get a^b = max of all with all bit set and b^c = here we can get b c^a = here we can get a so answer looks like A^B + A + b any bhai or sir help please
@namanlalwani80794 күн бұрын
excited
@SubhRajShawIIEST4 күн бұрын
But if we consider a particular bit position and set it to 1 in all the three numbers then also for that Position after the xor the bit will be 1 hence it also maximizes. Because (1^1)^1=1.
@praveenkumar-pw8hy4 күн бұрын
great explaination for c1, thanks!!
@hindolroy55615 күн бұрын
Hi Raghav. Thanks for explaining the 4th one clearly, missed it in the contest as was unable to figure out the lexicographical catch.
@itzzRaghav4 күн бұрын
Glad to hear that.
@imPriyansh775 күн бұрын
Great explanation of C. Thank you Raghav bhaiya!! very helpful
@rickparamanik5805 күн бұрын
i solved A,B in 30 min for the next 2hr i tried C this logic came into my mind but still could not solve it.. btw nice explanation..
@jeeaspirant82824 күн бұрын
same 26 min for a,b but tried for 1 and half hour for c but didn't get any solid idea
@Travel-s5e4 күн бұрын
bhai the intutioh of third i also got but i have implememntation issue
@Mad_Monk295 күн бұрын
nice explanation
@jeevan-l5w5 күн бұрын
Thank you, very helpful.
@ronakpatel28265 күн бұрын
so near to c! didnt code but approach was almost same i just wasted my time so that i could choose c optimally but it wasn't even needed hahhaa
@KanhaiyaSahu015 күн бұрын
How can i buy TLE eliminator level 1 and 2 courses 12 version
@Ssanjay20045 күн бұрын
Like this Technique , plz Post more videos like this , it will be helpful for , to solve medium lvl problems on OA round with Time constraint . today date : 05-01-2025
@Abhishek-e6d2c5 күн бұрын
Awesome explanation for C!!
@HarshitKumar-dj4ev5 күн бұрын
good explanation.
@TLE_Eliminators5 күн бұрын
Please fill the Feedback form for PCD: forms.gle/GbcRiUTC5kqu6hjw5
@66sbjaygoti805 күн бұрын
do anyone know when will batch 13 of tle eliminators start??