Why does everyone use an unordered set/hashmap for "jewels-and-stones" problem

google jewels-and-stones on the leet site. sorry cant give a link as reddit for reason wont allow me to post this as "I'm beaking rule 1"

Tldr: given 2 character lists, find all character in List 2 that are in List 1

All the "solutions" for this question seem to be only using sets but,

We can observe that the list is only limited to ASCII character, thus only having 256 possible character

Thus we initialize a fixed size array of 256 elements and just set the elements whose index matches to the filter characters to true

then we walk the list we and to check and just ask , "is the character true in our array?"

example implmentation

#include <string>
#include <array>
int numJewelsInStones(std::string jewels, std::string stones) {
      std::array<char, 256> jewels_set = {};
          for (const char &i : jewels) {
              jewels_set[(unsigned char)i] = true;
      }
    int count = 0;
    for (const char &i : stones) {
      if (jewels_set[(unsigned char)i]) {
        count++;
      }
    }
    return count;
  }

i dont get it. unordered set/hasmap has the overhead of hashing the elements, and the hash is usually less space efficient that just creating a 256 array holding all possible representations of the filter

reddit.com
u/Solomoncjy — 6 days ago

how to show no turning point exsists in curve?

given that $(2y+1)^6 = 3xy - x^3 -26$ and that $\frac{dy}{dx} = \frac{y-x^2}{4(2y+1)^5-x}$,

I have to show that dy/dx = 0 does not exsist (show that horzontal tangent does not exsist)

so far i have done:

observe that y -x^2 = 0 to evlaute fraction to 0

Thus, y = x^2

sub into first eqn to get $(2x^2+1)^6 = 2x^3 - 26$
then ppl in the math discord told me to pull out AM=GM to proof that dy/dx does not exixt, but there must be a faster way, right? esp we did not earn that in class

reddit.com
u/Solomoncjy — 13 days ago

For those that bought acrylic standees, what fo you do with the cardboard backing? I noticed it has pre torn lines, so it must be used for smth, right?

u/Solomoncjy — 14 days ago
▲ 2 r/Genshin_Impact+1 crossposts

Skirk joins the travellers party in 6.0. How would have the story gone if she was allowed to "tamper with fate"

Basically topic. Whould she have folded rerir, both detorrea and allowed bina to conserve enough power to go through moon prayers night without all the shenanigans we had to go through?

reddit.com
u/Solomoncjy — 22 days ago

how tf adding a proxy server packets need to bounce off of decrease ping times? If at all it will increase ping unless in missing smth

u/Solomoncjy — 29 days ago

That isnt what the card does… Lazada… who TF approved yhis narketing campaign?!

u/Solomoncjy — 1 month ago

How did the word for soap, “saboon” become the same in so many languages?

Its the same in 3 languages i have heard it from:

Hokkien
Malay
Arab.

How did it propagate?

reddit.com
u/Solomoncjy — 1 month ago