2

I have come to the conclusion that I'm dumb as fuck.

I have been stuck on this trivial problem for 1 HOUR AND 46 MINUTES...

https://leetcode.com/problems/...

maybe, hopefully, just because i'm trying to do it in a "clever" way, maybe if i just did it the dumbest, most inefficient way i can think of, it would take me "only" like 15 minutes, but at this point i'm not so sure... :(

Comments
  • 0
    maybe you need a recess.
    No, really, take a small break.
  • 0
    @melezorus34 i already did after the first hour
  • 3
    I looked at the solutions page.

    All 3 solutions seem fine too me.

    Dumb as fuck not necessarily....

    ... But this problem is - imho - one of the better examples of why leet code sucks.

    I really couldn't find a practical use case for this. Maybe for stuff like a password tester, but that's ... All?

    Plus that the solution requires a bit of naivety - it is, after all, always collecting chars and looking if the chars repeat themselves.

    Wether you do it in a more sophisticated manner or not - it is a rather naive solution, hard to solve elegantly, as the task itself is stupid.
  • 0
    @Midnight-shcode how long was this break?
  • 2
    @IntrusionCM speaking of dumb tasks...

    Remember that Amazon's Hanging 80cm Cable Problem? Do I even need to beat in the heads of simplification evangelists that the problem isn't solved by proclaiming distance is zero? It doesn't even tell how cables are tied and their circumference. Idiotic task, I hate it with passion, even though nothing similar was a part of my interviews.
  • 0
    @IntrusionCM

    "Plus that the solution requires a bit of naivety - it is, after all, always collecting chars and looking if the chars repeat themselves."

    i don't look at the solutions before i actually solve it. or rather, usually ever.

    also, i can't shake the feeling there is some solution which DOESN'T require collecting all the characters, and that solution only narrowly eludes me, and i'm trying to find it.

    i'm probably wrong.
  • 0
    @vintprox the break was half an hour
  • 1
    @Midnight-shcode small difference in wording but an important one:

    I said "collecting chars"… not collecting *all* chars.

    What I meant was that the operations are rather trivial - which makes it hard(er) to optimize as a trivial operation is trivial...

    You are on the right track trying to find a different algorithm - but the operations the algorithm uses will always be pretty trivial.

    Complex operations have more "attack surface".
  • 1
    Track a start and end of the current substring/sliding window. Use a set to keep track of the characters in the current window. Move the front forward if the next char isn't in the set & add to the set, move the back forward if it is in the set. Track the longest window.

    This specific problem isn't that real world (although does come up), but I've had similar sorts of real world problems that I've had to solve efficiently. Mostly in the guts of ML/algo stuff.
  • 2
    For a hash set, that gets you linear time complexity. Can't beat it.
  • 0
    @IntrusionCM Strings are just arrays of characters, but this same approach works for all kinds of arrays.

    For example, if your array contains event log you can use this to find the maximum number of occurrences before an event repeats itself.
  • 1
    @hitko this isn't correct... At least not to me.

    Arrays are complex.

    What was once a single string with limited number of characters is now an array of strings with limited characters.

    Not only is this trickier, but you can do quite a few more nifty tricks as the complexity is an entirely different thing.

    Parallelization, divide and conquer, sorting, ... Suddenly a lot of operations that didn't make so much sense before make sense.

    To apply the algorithm of a simple problem to a complex problem is either ingenious or - and that's the 90 % - dumb, as it might work, but is incredibly inefficient as the solution was made for a trivial, non - complex problem.
  • 4
    well, i fucking did it, using two fucking dictionaries and two nested loops, still thinking i was somewhat clever, and fuck, no, slower than 93% of submissions, and memory footprint worse than 52% of people...

    also, I WAS FUCKING RIGHT. IT CAN BE DONE IN A COOL WAY. THIS IS THE FUCKING WAY I WAS TRYING TO ARRIVE AT, BUT I'M TOO DUMB TO HAVE SUCCESSFULLY DONE SO.

    I AM dumb as fuck :(
  • 2
    @melezorus34 @IntrusionCM

    see the comment above

    @atheist

    yes, you are correct. that's what I was trying to arrive at, but for the reason of being dumb couldn't wrap my head around it
  • 2
    @Midnight-shcode I do this sort of stuff a lot in my day to day, so I have an unfair advantage.
  • 1
    leet code and coding platforms are some of the most depressing places to be on the internet
  • 0
    @dotenvironment

    why?

    i disagree. when I'm depressed because I'm unable to do as well as I think i should be able to, it's not because the site is depressing, it's because the revelation that I'm dumb is depressing.
  • 0
    @Midnight-shcode I just tried this problem and my logic is very similar to yours. I opted to make a new string and created my own contains function though.
  • 1
    @Demolishun Well shit, mine has issues.
  • 1
    @IntrusionCM Sorry, I totally forgot you're trying to make low-level optimisations using higher-level data structures. Somehow I'm not surprised...
  • 1
    Obsessing over leetcode is dumb itself. Being good at leetcode is only an indicator of being good at leetcode.

    Want to make difference? Stop focusing on rat races and meaningless badges.
  • 0
    Sometimes flipping through the keystrokes to the type of crap solution described is indeed what is needed
  • 0
    @IntrusionCM I didn't say stop talking pretty lol
  • 0
    @aviophile no, being good at leetcode is a metric of general problem-solving ability, since the problems there require and test that.
  • 3
    @dotenvironment I agree, the problems are good enough to build some critical thinking skills. But all of the shit that I have ever produced there is absolutely 100% useless. The issue is that it is taken as "zomg he is awesome he should be hired into our institution!!!!" when there is still a lot.....aFUCKING LOT that I don't know.

    Put a leetcode writter to do something fruitfull and actually useful: zip

    This is why i hate that site, or leet code devs.

    To be fair, I just hate devs in general so I might be biased
  • 2
    @AleCx04 how dare you insult us geniuses! Nobody can add features to crud apps like we can! But let’s make the interview involve building Facebook in 45 mins or leetcode hard in half a millisecond. BC you’re not a senior crud app feature builder if you can’t build facebook in the time it takes me to poop. Excuse me, I have a sql query to refactor. To the fatmobile!
  • 1
    @Midnight-shcode no, it is a selfinflicted illusion. It has insignificant value in real life problem solving. It doesn’t also improve general problem solving, on the contrary it is specific problem solving. You are trying to solve fictional small problems, writing maybe 3 functions in total and that’s it.

    In real life, cutting edge algorithm skill is maybe 5th important skill. But unfortunately, lazy companies slap leetcode assignments so people who study leetcode and suck otherwise are successful.

    My student version just at second grade would have great success in those problems, only to brag to friends.
  • 0
    @aviophile

    "in real life problem solving"

    i meant programming/algorithm problem solving.

    i thought that would be obvious, due to the site we're discussing that on
  • 0
    @aviophile

    "In real life, cutting edge algorithm skill is maybe 5th important skill."

    ...so? that's not what i was talking about.

    i wasn't depressed that "i can't do moronic crud apps or moronic pages or moronic enterprise business apps"

    i was depressed that "i'm dumb". as in, not as intelligent as i thought, not as capable to solve actual semi-interesting, semi-challenging problems.

    those are completely two different cathegories, but i guess not many people realize, seeing how many crud/web codemonkeys think themselves awesome programmers because they can codemonkey crud/web.
  • 0
    What’s even more frustrating about leetcode is going to the discussion and seeing 200 plus posts from people with better solutions!! And is it me or is there some echo chamber thing going on there...every title is “my solution with clear explanation”. Then you feel even WORSE when you try reading their “clear” solution and still not getting it lol
  • 0
    I had one solution that worked. Then I improved upon that solution to be a little better. Last night my brain said "you can do this without a temporary buffer". I have not tried that way, but will play with this later. We shall see if my brain is lying.
  • 1
    @TeachMeCode

    you don't need to go into discussion for that.

    you just need to click whichever bar you're interested in on the performance graphs on the screen that shows when you submit a successful solution.

    i added the best solution to this problem to the comment to my solution, with the note "my solution is dumb. i KNEW this awesome one exists and tried to get to it, but was too dumb to do so."
  • 1
    @Demolishun yeah, so far on each i did i kinda started with knowing the trivial solution, like "yeah this one would be easy and would work, but would be inefficient, so let's skip that one and find a better one"

    same as do on interviews, i first say "well, the naiive solution that would work is [description], but that would be inefficient, so give me a moment to come up with something better and more interesting"
  • 0
    @Midnight-shcode

    So I used that code you posted as model. But tried to remove storing string. Required making my own function for checking for in string. Not sure I could figured out this on my own.
  • 0
    @Midnight-shcode and I meant, in real life problem solving as in reallife problems solved with software. I thought it was obvious by the website we are on.
  • 0
    @aviophile then it was my misunderstanding, sorry.

    i disagree.
    rat maze is an arbitrary problem which has little in common with real life navigation problems a rat faces.

    incorrect. rat maze is a great testing/measuring tool of real-life navigation abilities as well as their trainer, improver. same principle.

    if you are able to think well, you are able to think well about anything.
  • 0
    @Midnight-shcode last sentence is horribly wrong lol. Even if we limit it to software development, it is still wrong. Algorithm development skill doesn’t spill into other problem solving skills.

    Also, you are acting like only way of using algorithms is implementing them by scratch. If you know what type of algorithm you need, just steal the implementation from others. Remember that, you are solving a problem already solved million times before. You are not creating novel algorithm in leetcode.

    Note: you seem to misunderstand rat race also. Rat race is an exhausting, usually competitive, but ultimately not so useful routine.
Add Comment