Professional Documents
Culture Documents
Poefin Sum
Sum in a
range formultiple query
Equilibrium in der
Product
of array except itself
number
of odd numbers in givenrange ETI
Rain water trapping Hardteletcode
a Given a
array
elements return
Pff where Pff Suharto
anti
assn
for all I
En assist T I i iz is
s 4 5 11 9 163
Pf
asscio L i 5 I 3 4 19
Go h 2 3 4 7 11 12 191113133
Pf
11 Brute force
h i loop
for every index from 0th
sun a to
assist T I i 3 is
Pf 15 14 5 11 9 63
Haneda code
into Prefinsum int array
int
Pfa
int i O ian itt l
for
int Sum o
for int j o
jai jtt l
SC Oct Sum Sunt asolj
gum
ppg
return
Pf
sit
Sum O 47176
assist i i i
Pf15 4 5 11
I optimal approach
axon
asolo
Pf lo
assist i i i i it
14 5 9 163
Pfg 11
return
Pf
3
a Given a assay elements and Q queries on an array for
each query calculate Sum all elements in given range
of
En and 2 5 I 3 i i i i s
Q 5 had Bouteforce
to 3 8 55 Literate in the range for
12 4 8 every query
2 o 3
3 f g void SunQuay int arm int aeries a D
g g g
int i O is a it K
for int L Queries fi fo
int R Queries i a
T C O Q N int Sum O
Oct I
forSum Suma jer jtt
int
S c
j L
asolj
g
Point sum
y
10Ptimal approach
and 25 I 3 i 828
2 3 4 7 11 12 19 11 13 13
Pf 10
Sum o 3
Pff
Simcoe
Saffo R stunCo L 1
Sum o R PIER
stumlo D
ifl o
I Psuedo code
int
PfCJ Prefinoptimal arr
lint i is a it K
for
O
int L Queries1703
int R Queries i a
T C o a HOLD h
TO Cata if c o
s c old point Pf r
Pfk 13
3
else f point
Pfr 3
3 3
ate Olata
N Q
0 N O Nta o 2nd IO n
p c
a Equilibrium Index
Given a
assay elements Count no
of equilibria
index An inden i is said to be equilibrium inden if
En a fu I 6 3 4
leftsum O ans a
sightsum 13 7 4
area i s i i 5
leftsum sans 3
sightsum
9
11optimal approach
45
a fu 2 6 3
4
Pfa 2 7 11
Sum i t i t
leftsum o
Pf
I Puedo Code
int ans o
Lint it is a a it k
forint
Pf i i
leftsum
int oightsum PfCn D Pf i
T.ci Ola told Ceeftsums sightsum fans tf
2nd IO a
if
SC Ocn 3
if o
Pf In D Pf o 9
ans t t
g
11last inden Check
PfCn 2 o ans tt 3
if
return ans
a Product Encept itself
of Array
Given area return an answer
array
Such that answer fi is equal to the Product all the
of
elements except numsfi
of mums
note
you can't use division operation
En any L I 3 I
ans 4 24 12 8 6
any L I 3 I
Poprad 14,4288443
Suffin 1 4 4 3
1222
24
PoefPrdfi PofPrdCi D Saffir
PrfPods PofPrd 2 1
PofPrd127 PofPrd 4
PofPrd f 3 PofPaolo 12
I Psuedo Code
Lint i n e i i K
for
o
PofProduct
fi PofProductCi D Saffin
Suffin Suffin anti
3
PofProductCo Suffin
return Poffooduct
3
Tracing
int PrfProducts Goofy L I 3 I
PofProduct o asolo
PofProduct11
for int it ice itt l 44 428 443
Pofpooductli PofProductCi D ascoli
Suffin 1 4 4 3 12 2 24
int Suffin t
int i n e i i K
for
o
PofProductCo Suffin
11Poefinman and Suffinman
psefinman
En a 623 I I 3 2 I 5 i 32 I j j
Pmano 2 2 3 3 3 3 4 4 4 4 4 4
Prefinmanli man o i
suffirmer
Suffinmanli man Li n t
a 423 i i 33 is i
Samanta 4 4 4 4 4 4 4 33 3 3 1
a Rain water trapping
Given a non negative integers representing an elevation
En assfiz 2 1 3 21 2 4 32 1 3 1
ans 8
O
is 11111111 ooo i 1111
2
3 2
2 2 2
o I 2 3 4 5 6 7 8 9 10 11
3
2 2 2
1
A
lb 2 3 lb 2 Jb min45,257 2
Yb
2b 2 amount 2 a a 66 3 amount 2 1 1
3 3 4
2 3
2 2
y I
of i
86 3 mindsog 3 lb 3 minds b 3
Jb Lb
ly 3 amount 3 1 2 y y Amount 3 1 2
5 4
3
0 I 2 3 4 5
64
7 8 9 10 11
e a 2 3 u g É 7 8 9 10 is
ANC 2 1 3 21 2 4 3 2 1 3 1
PmanC 2 2 33 3 3 4 4 44 4 4
Smart 4 4 44 4 4 4 33 3 3 1
anemones
gang
3
return amount
into
funds int arm I
int i i i D1
for n 2 o
return Sman