SlowLegendaryNoobMaster's blog

By SlowLegendaryNoobMaster, history, 6 months ago, In English

If we know the number of entries beforehand, lets say v, then is it optimal to initialise the hashmap in java with size v or v/load_factor???

If we donot intialize it then it will be of size 16 and many times rehashing would be done.

So, on an average in contests what size should be chosen for optimal solution??

  • Vote: I like it
  • +6
  • Vote: I do not like it

6 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

In my experience, it does not make a significant difference.

Perhaps it may be "optimal" but it likely won't be the difference between a TLE and AC.

Hope this helps.

Edit: Changed WA to TLE.

  • »
    6 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Why it would me Wrong answer, rather the chances are of tle when the solution is near the border of the time limit.

    There are some questions in which using array gives AC but using Hashmaps gives tle.My concern is for such type of questions!!