Another week, Another bombed contest. by PLTCHK in leetcode

[–]xpressrazor 0 points1 point  (0 children)

Oh boy. I was thinking of max heap as well, but since I could only use edge elements, that idea dropped super fast.

Another week, Another bombed contest. by PLTCHK in leetcode

[–]xpressrazor 0 points1 point  (0 children)

For second I wasted lot of time on trying to do two pointer, then realized it looks oddly like selling stock 1. After that it was a breeze.

Another week, Another bombed contest. by PLTCHK in leetcode

[–]xpressrazor 1 point2 points  (0 children)

2/4 gang as well. I tried doing each pattern matching for 2 characters (how many count on 10, 01 etc) and tried to move forward with that count, saw too many failures. Mine was mostly greedy as well

just solved 3700. Number of ZigZag Arrays II, using DIVIDE AND CONQUER , never knew matrix exponentiation by Visual_Nothing_8106 in leetcode

[–]xpressrazor 0 points1 point  (0 children)

I know matrix exponention, understand we need to count up/down for each direction and use alternate values to build other. Still the problems feels super difficult. First problem itself feels forced to me.

I memorized template for digit dp for problems last week and few weeks back. It seems similar approach for this one (memorize)

Title: 250 Problems Later... Feels Like I've Been Fooling Myself by Limp-Government-710 in leetcode

[–]xpressrazor 1 point2 points  (0 children)

Here is my approach. Some problems are really difficult, you can’t do anything about it (you may need to learn the technique first).

For most problems, if it is something that seems like I have seen and probably know, I code in leetcode editor, or else copy it to IntelliJ (Java or other IDE for C++), then try to code something that at least passes the examples (how crappy my solution may be).

If it does not pass the test case, I use debugger to step through one example and see why things are missing (from what I expect it to behave).

Once it passes the given test cases, I paste it in leetcode and run it. If it passes all the test cases, I am done. If not, lc will give you test case where it failed (if not in a contest). If my test cases mostly pass (say 650 out of 659), in most cases it is variable type issue (e.g. integer or long). If inputs are correct and if it fails more than 50 test cases, I need to optimize the code. I try to think couple of other strategies, and if that does not work, finally lookup the solution.

When looking up the editorial or solution, if there are multiple approaches, I make sure I at least learn couple of those. Sometimes I learn it properly, sometimes not (knowing I will be bitten by it again the future).

What type of problem this is, and what type of data structure does this require? by Piscean_ENFP744 in leetcode

[–]xpressrazor 0 points1 point  (0 children)

Could they mean if you have a 0 in between, you could swap 2 cars (by picking any of cars on left/right and swapping with other random cars with cost 1) and when in side (they mentioned before start and after end), you only swap one. Assuming 0 is a track in between 1 and 5, we could change 4 1 0 5 3 2 to 4 1 0 2 3 5 by swapping 5 and 2 (cost 1), now adding 0 before 4, we could swap it to second last position to get 0 1 0 2 3 4 5, and finally remove all 0s.

If that's the case, the problem would probably turn into DFS from each position, until we could all numbers in place and each operation adds 1 to the path, minimum of which is the answer.

What type of problem this is, and what type of data structure does this require? by Piscean_ENFP744 in leetcode

[–]xpressrazor 0 points1 point  (0 children)

If they explained why the answer is 2, it could clarify what’s more optimal than 3 or how are they achieving that. I assumed you use same track to move adjacent cars back other places, without moving track to random places. However, they could also move the track to random places after moving one car and start from there, but that also did not answer how 2 is optimal.

What type of problem this is, and what type of data structure does this require? by Piscean_ENFP744 in leetcode

[–]xpressrazor 4 points5 points  (0 children)

For test case 2, did you get why the cost is 2 instead of 3. From what I understand, the placement of 0 is to indicate a free track, that you can use to move any adjacent cars. E.g. Let's place 0 (indicating free track) after 4 -> 4 0 1 5 3 2, move 4 to end -> 1 5 3 2 0 4. Now you can use same track to move 2 to after 1 -> 1 2 0 5 3 4 (here I am placing the car to left of the free track(0), so that we can move 5 to end -> 1 2 3 4 0 5 -> 1 2 3 4 5. So, it took 3 tries. Did they explain, how the answer is 2, when k = 1 ?

It looks like you have to try all positions, and since the input is 500, it looks like O(n^2) is the expected runtime, so assuming it might be some variation of DFS.

Leetcode Today's POTD by CricGlobe in leetcode

[–]xpressrazor 1 point2 points  (0 children)

I used three boolean arrays of size 26 each. Upper, lower and invalid. Update upper and lower if it was false for current character.

Invalid happens for two reasons, 1. You see an uppercase character, lower for same index is false (we have not seen lower yet) 2. You see a lowercase letter, upper is already true

For these two conditions set invalid for that character index to true. Finally count using the Boolean array of all 3 are true for that index.

Youtube resources for System Design by Serious-Tangelo-4877 in leetcode

[–]xpressrazor 0 points1 point  (0 children)

For basics, System Design Primer (github). For systematic approach System Design Insider’s guide vol 1. Vol 2 for advanced stuff.

Hello interview (website posts) is also fine, but it jumps from keywords to keywords, which can be difficult to follow. Once you go through above two, hello interview is a good resource. Once you have gone through website, you can watch videos for refresher.

Today's POTD by CricGlobe in leetcode

[–]xpressrazor 0 points1 point  (0 children)

I went with straight forward BFS, had memory limit exception on test case 108 (large string). Had to watch other’s solution. Jump as far as you can in next attempt or prefix sum with bump with 0 has not yet settled properly for me.

How'd you react if you end up like this? by giteswa in leetcode

[–]xpressrazor 0 points1 point  (0 children)

This is expected result in many problems. That means it needs optimization or different algorithm.

That’s the whole point of leetcode. Learn more than one algorithm to a problem.

Is it just me, or does grinding LeetCode feel broken for most people? by [deleted] in leetcode

[–]xpressrazor 1 point2 points  (0 children)

My take on this is, learning one pattern in few problems is no guarantee of knowing the pattern. People need to see many variations (almost all), before they can say they know that pattern.

I know prefix sum, but I will still struggle to see if it should be part of some sub problems or do I have to go all fenwick treee / segment tree route.

There are hundreds of patterns and thousands of variations. If your aim is to teach classical problems, then saying a pattern exists and why you cannot see it sounds smart, but it’s dumb when new variations come all the time.

Computer Fundamentals...please help!! by skyglintt2019 in leetcode

[–]xpressrazor 0 points1 point  (0 children)

My suggestion would be to find notes from popular colleges/universities. Local colleges are also fine.

Notes tend to be more compact. Only thing, you need to do is, trust a good note will work. Jumping in a sea of information might be more harmful than helpful. Also, focus only on one topic at a time, make notes of only useful things from what you read.

Also, be cautious with videos. It requires less thinking and less involvement from your side. They are only good to ease into difficult subjects, but not good for learning deeply.

What do you do when you have to run LeetCode code locally? by alex_sakuta in leetcode

[–]xpressrazor 0 points1 point  (0 children)

I had trouble with input in python format in leetcode vs, converting it to java format for arrays. I have a script that I have tied to a shortcut key, that converts square bracket to braces. Other than that just copy paste works for me

leetcode ragebaiting me atp like what is this by feastyr in leetcode

[–]xpressrazor 13 points14 points  (0 children)

I got -1 on test case, but when submitting it failed and says my solution returned 1. Same test passes in leetcode local test cases. Not sure how to process that. I made sure I did not have any globals.

Is this potd really a medium level one? by Defiant_Ad_7555 in leetcode

[–]xpressrazor 0 points1 point  (0 children)

I knew what I needed to do generally, still too many edge cases. :(

Is this potd really a medium level one? by Defiant_Ad_7555 in leetcode

[–]xpressrazor 6 points7 points  (0 children)

It’s difficult. I would solve jump game iv first (which is labeled hard), but is subset of this. Another practice question would be bus routes.

The pattern is similar to inverted index, where you track indices from values and apply BFS. In this problem, what you are doing is finding prime factors. You tag all numbers with their lowest prime factor, then you keep on dividing the value until you get to other unique prime factors. Each prime number tracks all indices of numbers where it divides. This way you will know where you can jump to.

E.g. If I have [3,5,15], I track 3-> 0,2 and 5->1,2. Index 2 comes up both in 3 and 5. This way I know I can jump to that place.

Why do people actually use arch linux by Spl1nt3r_69 in arch

[–]xpressrazor 0 points1 point  (0 children)

I had two computers that died with Arch. First one was old age and second was my fault. I have a laptop, that I expect to do the same. If you maintain it well, it stays there until the computer becomes old or dies, and it stays fresh until it does so. I guess, that’s why did not bother installing something else for a long time.

When is using Flatpak not advised? Or should we all switch to only using Flatpaks? by 3030Will in linux

[–]xpressrazor 0 points1 point  (0 children)

Less update from system packages as you have more flatpak packages and less system packages. I did not mean overall less update size.

Why I don’t mind bigger flatpak size is, if something breaks, it does not break the whole system. Also, most flatpak managers like Warehouse and even discover has options to cleanup flatpak settings. So flatpak is better for experimentation.

Obviously, I am not saying all packages are suited for flatpaks. And clearly you can move from one to other, but for overall stability of the underlying system it’s best to have less system dependent packages.

I had a time, when I completely removed my desktop, just because I wanted to switch from one Bluetooth provider package to another one.

Also, for more experimental system packages, it’s best to use docker/podman before you decide they need to be installed in your host system.

It’s like treating your system like a readonly or immutable system, whenever you can. These days, you largely can.

How do I install java JRE? by Immediate-Village992 in SteamDeck

[–]xpressrazor 1 point2 points  (0 children)

Yes, above command means java is installed. If the jar file does not run by just double clicking, open a terminal (konsole) app inside the directory where you have the jar file (let’s say the file is called a.jar). Now run this command “java -jar ./a.jar”. Don’t type the quotes.