Hash Set Notes
Hash Set Notes
eleme kt t
5, ,
Insertion Delstion
'ou) oti)
* Too Sum:
[1,234 5,6,] "Target s
ole: (, 4),(,3)
Brut Force: forl int izo, i <arr. lengh; l++)!
o)
S.0 pl (ar ei] ar J)
for (Pot izo, i<o, it){
nt num z arr C
int res target -num,
f(set: contaios (es) oln) oln)
## Contains Dupleato:
Ie: ,i,, 2,3, 2,2,4,4,s pTeaé"
add elementa, in the set bg tebtaating the
cheek if the elemeto is aheady avacle in the set.
TL avalable vetum True.
for Cint ie o, i<ar. lengh, et)
i(set- containa (areti)] £
retum rue,
return false:
# ## Jesels and Stores:
Jewel: "aa, stoner"aAAb66b
’ checkeach jeel in the stone
Brute Fora: heating thrng Jeolg ones andchek cash chaxache l
for (înt ie o, iz stones. lengthyit) found countt,
retum Count;
We Can ude Lndes of Appreeth
t. indexof(a) ’ o
t aA
t indexof (^) - |
for (iot ieo, ie store s. leng thuy, f)
char eh stone s. char Atei);
if( jevels. iodexof (eh)! -){
Counttt}
retum count
Uing kanh Seticor) D-A:T
Creat an Array diae ars.
return ount
##eppy Number
5+ happy hannbex
a)
Sating
) Repeat the precens uctil ie nmben ceyela i
) end witth, is kappy ulee
2 2=4
20
Algest:
-Add the elemen+ io the hashset
Mumee t the
2 Compute the Am 4 saqyuanes and as u sompcte, add hat
3- 3f conmputed nember is l etrn true
sL computod mmnbee akeady preuent in 'the set -’ rehutn flse;
while (truej' t h
whileln!=o)<
Sum t= Math pow(n210, 2 - 0 ) ; +
A
'Bi eired meey
fouud. aleeedy
’when al thekys. in the map have become 2os, wehave seahed
one potential a
In the above ppnoach, we need to iterote tthrongh the' mapto cheek
all the Volues
de we wiu have a new
proach with count vaiable
fnitialtae count = haskmap. sizeey
when any value Beoms Zre, eduee -the Count
lount be lomes ' e
Ohen
seask the potential windo.
S: TrttA + TA
To*- -3
A
Se potential windouw 5
ogot one potential window
windw
So
potentinl windao' e
2
pointee’ Windovw tant and Windo¡End.
Dumpthe elemert String
haskmap tale wcth he ocerence
3. oeot anethe vauiable
Called Count
4 yAtat
5 the tsuaveaingat iwingbeation i
element
, Deerement the present inthe map
valt of that kay . keay
b) T
i)
Count =0
shrink he oindo and cheek
beconne ze, Count-
thax at aoiaking we ane
qctit
G) tasct tuakouing ni ocatiom and check ethlue that
Pasticalas elmeut in yowe hahap
(hi) sink he winda iiL te Cout =0,
while tount == o)
iti-it t< ninlen)
minlen -i -iti,
toin dow tart Min =i:
Oplimiged -pproacl..
o ’ checking ate the elemesti thrgh
OO, 4, 200, I, 3, º
’hdd al elementt to theHash et
check it he previous num s aveilaßle
wthe hah t (becnuAe the pre ui
’Il te previous - incremeot the number
and check in the set, cont ains inere ment the nuwher
and length
’ Get the Max and max
L00,, 3,
7 Ato:
At : 4
(o ) wax leugth 4
lengh man retarn
tength, max( Matk:monlengthe
tjlengtht
containirum
t1)) (nun (set. kile
Corntains (set. it
length sot
num nt
[iD; lar ad4 set
Sbesc new set=
Hath Set<Intcqers
length
eo mar int
ength
9 ma
Co,
5: At
C, o, -, o, -2, 2]
dot
-2+ (-) +o+2 ’Surm -o
|-2, -, o, o, I, 2
left righkt
left +t and array cleft] =array[lett-i]:
ta again lefttfi toi)
[-2, -, , o,
lett ight -Add t the
right sintt)) :
Add to tpe list
C-2,o, o, J kftt, rigt--;
(-2,-, o, o,, 2] tett* iaht
tvight
So, increme nti
-1+0+ o+2 o
right - b hkril
[-2, -, o, o,,2.2 +ot
add to the lit
C-,o,o,)
So final Recalt Contains
[-a,,] E,9,0,2] [-,9,o,)
int n: amag. length;
lonq Surm
Su O
Set<ist <Inteqer>> set s new tash Set<>);
Arays sort (array);
for Cint is O i< n- , it+)
ift isö & amag ti) =s array lt-13 ) cotnue;
for l int je i, j<o-2it)f
it (i>& aray ti]=z array ti-)continue;
int lett = t
int right a n-l;
Sum= (long) arraylil aray Li] taray Cla) t aray igle]
if (Sum >target)
clue
List enteger , isteneo Anybites t;
Iistadd array til);
list-add Carray Csl);
istadd Carray ClePtl);
1 tist add
CarrayGigh] ;
Set add Cist);
(
arayc luft-))
ray brglt
retum new
-Araylit <> (set);