Here is a gfg problem I am not able to understand how elements are getting stored in map
when I print elements of the map I am getting
7 0
3 0
8 4
etc
here 8 is present in the map coz we added them earlier but why are 3 and 7 getting inserted into the map?
any help would be appreciated
In above example i added 3 with value of 8 and its get added to map
but in if condition I am just checking if 7 is present in map with value 2 its got added in map as i tried to access it using subscript operator
and curr map is {{3,8},{7,0}}
To avoid this
you can used count function which do not add any element in map and it returns 0 or 1 if element is present in map or not