why is the two for loop solution faster than 89% of C submissions?

why is the two for loop solution faster than 89% of C submissions? are hindus and pakis really this dumb that they find a way to fuck up two sum in c???

  1. 2 weeks ago
    Anonymous

    I wish something like this existed as a set of .c files with an edit_me.h rather than a shitty website that wants my email, name, and credit card details.

    • 2 weeks ago
      Anonymous

      it should be easy enough to take the problem descriptions and write a main function that initializes some test cases and runs some asserts? not knocking your ability, just stating how i would solve what you're asking

      but agreed, fuck this paki website

      • 2 weeks ago
        Anonymous

        It might be an interesting scrape job, but I just wanted to be lazy and git clone gitlab/someproblems.git
        Building up main from spec might work, but I'm also not sure if I have the patience to try and pound it out. Maybe over summer if I get bored

        • 2 weeks ago
          Anonymous

          it wouldn't be worth it to make a 1 for 1 clone of the site anyway, probably 75 diverse problems is good enough

          don't release it, itll just be appropriated by streetshitters and changs anyway 🙂

          • 2 weeks ago
            Anonymous

            Maybe I'll make it available on some temp file host, show it off to LULZ or something.
            I'm probably not the first guy to have the idea anyway

            • 2 weeks ago
              Anonymous

              most people with this idea won't do it, only maybe as an exercise. because to have this idea you need to be literate enough to not give a fuck about these nigher sites anyway

    • 2 weeks ago
      Anonymous

      why would you want to use this crap if you know how to program. this is for normie noobs trying to grind an interview to make a quick buck and change careers in 4 years when it crashes

      • 2 weeks ago
        Anonymous

        Puzzles can be fun
        I liked TIS-100 and Szehnzen I/O or however you spell it

        • 2 weeks ago
          Anonymous

          TIS-100 is a game for retarded brainlets

          • 2 weeks ago
            Anonymous

            It's a puzzle game with programming aesthetics.
            Actual programming puzzles allow for more freedom which is fun

            most people with this idea won't do it, only maybe as an exercise. because to have this idea you need to be literate enough to not give a fuck about these nigher sites anyway

            People do advent of code every year, this would just be more freeform and less time constraint

          • 2 weeks ago
            Anonymous

            >he got filtered by TIS-100

    • 2 weeks ago
      Anonymous

      the problems are on github just do them

  2. 2 weeks ago
    Anonymous

    because time complexity doesnt tell you how fast something is, just how the algorithm scales with huge inputs
    an O(1) algorithm might be slower than an O(n) algorithm as long as n is small

    • 2 weeks ago
      Anonymous

      n can be up to 10,000. you're saying that 89% percent of p*kis wrote a slow hash map?

      • 2 weeks ago
        Anonymous

        ... yes
        pakis tend to copy-paste solutions
        they copy the best time complexity because thats what they expect to be asked for in interviews
        you can do 2sum in O(n)

  3. 2 weeks ago
    Anonymous

    Stupid question, but it's been a long time since I did a data structures and algorithms course and I'd love to get back into stuff like this - what site is this?

    • 2 weeks ago
      Anonymous

      leetcode.com

      • 2 weeks ago
        Anonymous

        Thanks!

  4. 2 weeks ago
    Anonymous

    yes it should be a upper/ lower triangle matrix. It is same as double loop with i<j

    Programming has no soul. You know the answer instantly and the pain is to write it

    • 2 weeks ago
      Anonymous

      >you know the answer instantly
      this is a leetcode easy

    • 2 weeks ago
      Anonymous

      >Programming has no soul.
      Leetcode has no soul, it's just brownoids sharing answers and Western mental-brownoids copy pasting ChatGPT output.

  5. 2 weeks ago
    Anonymous

    >calling malloc in a hot loop
    these are the retards on LULZ who complain about GC latency btw

    • 2 weeks ago
      Anonymous

      Malloc is only called when the function returns, guaranteeing max 1 malloc per function call. So no, it's not a hot path.

    • 2 weeks ago
      Anonymous

      >attempts premature optimization
      >can't even intepret 4 lines of code correctly
      Every single time

    • 2 weeks ago
      Anonymous

      Malloc is only called when the function returns, guaranteeing max 1 malloc per function call. So no, it's not a hot path.

      >attempts premature optimization
      >can't even intepret 4 lines of code correctly
      Every single time

      lmao absolutely btfo. the problem explicitly states my implementation must malloc and expect the caller to free. maybe he just wanted me to return a stack allocated local array :>)

  6. 2 weeks ago
    Anonymous

    Most of these slower submissions literally did the same thing you did, but the runtime is variable between the same solution so yours is luckier.

  7. 2 weeks ago
    Anonymous

    >2Sum
    >6.21 MB
    >Still beats ~80% of candidates
    Bro... what the fuck?

  8. 2 weeks ago
    Anonymous

    brainlet here, what's the correct solution?

  9. 2 weeks ago
    Anonymous

    Most Leetcode users are absolute beginners.

  10. 2 weeks ago
    Anonymous

    The speed depends on your machine.

  11. 2 weeks ago
    Anonymous

    The speed can vary by things out of your control, it’s better to look at the distribution of speeds, to see what peak your solution lies in.

  12. 2 weeks ago
    Anonymous

    stop writing 'int* foo'. Write 'int *foo'. the former is misleading, because it looks like you should write 'int* foo, bar', but you should actually write 'int *foo, *bar'. The way C declarations work is that you write the type and then a declarator. *foo is a declarator. * is not part of the type.

    also stop using camelCase. It doesn't really matter, but it just looks weird to experienced C programmers. otherwise your code looks fine.

    • 2 weeks ago
      Anonymous

      > * is not part of the type.
      Wrong

      camelCase is fine as long as the code is consistent.

    • 2 weeks ago
      Anonymous

      I will not kneel to arbitrary whitespace preferences, pythonista!

    • 2 weeks ago
      Anonymous

      what about int * foo, * bar? :^)

    • 2 weeks ago
      Anonymous

      int* foo = NULL;
      int* bar = NULL;
      I agree with the second part, although I may be biased always use snake_case in every single language.

  13. 2 weeks ago
    Anonymous

    Because most likely don't use i+1 in the second loop. It's a less obvious optimization.

  14. 2 weeks ago
    Anonymous

    I'm surprised this even worked. Most O(n^2) solutions I've tried just time out

    • 2 weeks ago
      Anonymous

      If you want to further optimize, you should check target's parity. If target is even and i is even, j should be even. If target is even and j is odd, j should be odd.
      If target is odd and i is even, j should be odd. If target is odd and i is odd, j should be even.

      >O(n^2)
      You are a retard Sar. No offence in name of Kali. But there is no difference reading the entries from upper diagonal matrix than reading the entries from a vector, that is resultant from vectorizing this said matrix.

      • 2 weeks ago
        Anonymous

        Wrong guy retard

    • 2 weeks ago
      Anonymous

      my O(1) solution runs in 2ms, but no paki would understand whats happening

      • 2 weeks ago
        Anonymous

        I wonder if the compiler will optimize that hash map initialization into a memset.

        • 2 weeks ago
          Anonymous

          thanks for pointing that out, i was thinking that looping would be inefficient. a syscall is likely much better and probably -O1 and above produce it, that's like their main thing right, basically inlining everything it can (especially since it's all -1).

      • 2 weeks ago
        Anonymous

        I don't understand what's happening

        • 2 weeks ago
          Anonymous

          the possible input values are between -1000000000 and 1000000000
          there can be at most 10000 inputs
          so what we need to do is reduce the range from 2 billion to 10000, and furthermore we need to shift them all to be positive because arrays cant have negative indices (e.g hash[-1])
          so to do all that we use unsigned int and %
          and then the rest of the solution is just normal "check if i've calculated the diff before and if i have then return that index and the current one too"

          • 2 weeks ago
            Anonymous

            Why do you use a loop to initialize hash. Can't you just do it one line.

            • 2 weeks ago
              Anonymous

              i want to stack allocate hash[] instead of mallocing and freeing. plus i need to make sure everything is set to -1 and not something positive

              Nice memory leak and using % as a hash fuction lmfao

              let's see paul allen's solution. let me guess, malloc and struct node? good luck getting a job offer at dorsia now you stupid bastard

              • 2 weeks ago
                Anonymous

                Since size is defined can't you just do
                int hash[size] = {-1};

              • 2 weeks ago
                Anonymous

                based i didn't know that syntax, tyvm. it's like stack allocated calloc with a value that isnt 0 ^>^

          • 2 weeks ago
            Anonymous

            So... it's just a nagger rigged hash table?

            • 2 weeks ago
              Anonymous

              if by nagger rigged you mean performant, mr runtime polymorphism heap allocated fagbag

              • 2 weeks ago
                Anonymous

                I wasn't being critical, I was just confused initially.

              • 2 weeks ago
                Anonymous

                my bad sorry for ragging on you

      • 2 weeks ago
        Anonymous

        how is this solution O(1)?

        • 2 weeks ago
          Anonymous

          sorry i totally apologize, it's O(n) worst case. typing too fast

      • 2 weeks ago
        Anonymous

        not too bad. but you can do a lot better: https://nullprogram.com/blog/2023/06/26/

      • 2 weeks ago
        Anonymous

        >doesn't handle collisions

        • 2 weeks ago
          Anonymous

          handling collisions with a linked list of nodes is orders of magnitudes slower than stack allocating 20000 int array goofy

          not too bad. but you can do a lot better: https://nullprogram.com/blog/2023/06/26/

          ty for the link even though hes using (allah yaghfirli) g*

  15. 2 weeks ago
    Anonymous

    >sort
    Alternatively...
    >use a map
    Did I get it right?

    • 2 weeks ago
      Anonymous

      if the input is already sorted, two pointers is the best solution

      "use a map" is the best in the unsorted case, but not if you use a pig disgusting OOP language of course

  16. 2 weeks ago
    Anonymous

    No one wants to write a fucking hashset from scratch in c

    • 2 weeks ago
      Anonymous

      LMFAO IT'S LITERALLY 2 LINES OF CODE YOU BRAINLET L00000000L

      see

      my O(1) solution runs in 2ms, but no paki would understand whats happening

      • 2 weeks ago
        Anonymous

        Nice memory leak and using % as a hash fuction lmfao

        • 2 weeks ago
          Anonymous

          wheres the memory leak homosexual?

  17. 2 weeks ago
    Anonymous

    I had the same reaction, did the first problem (or maybe it was the first problem in the neetcode list, determine if all entries are unique) for shits and giggles.
    >check all against all O(n^2)
    >can't even submit
    >do the included sort, just check the next entry
    >suddenly, faster than 90% of all entries
    It MUST be getting spammed by thirdies.

    • 2 weeks ago
      Anonymous

      plz ser my copy paste twosum solution is wery fastest plsz GIB H1B at yuor soonest convenience

Your email address will not be published. Required fields are marked *