You are on page 1of 20

Today's agenda

man chunks to make bolted I


naan chunks to make bolted 2
Point boundary
Point spiral square matin
Point spiral rectangle matin
Q Man chunks to make sorted 1
Given an aorta containing Permutation of the
integers in the range to n t you have to split array
into maximum possible number chunks such that after individually
of
sorting eachchunk the array gets sorted

En arrest L i
4
i
ans
if if
4

o I 7 3 4 5 6 7 8

En arr 9 g2 0 1 4 3 6 7 5 8
bars

En arts Li 3 I I is
ans I

I idea and on 13

an assess c a p if p
obs man i is equal to valid chunk
if
o
IIPSuedo code

public int manchunkssostedone int Arak

int mantill now D


int Count 0
T.ci Ola
s c Oca int i og itt h
for mantillnow
icing
Math man Cmantillnow anti

mantillnow i counttt
g
if
return Count

racing assess c a s d
int mantill now D
int Count 0
i mantillnow count
for int ing icing itt o 2 0
mantillnow MathmanCmantillnow anti
I 2 O
counttt
3
if martinnow 2 2 I
return count 3 4 I
4 4 2
5 6 2
6 7 2
7 78 34
Q Man chunks to make sorted 2
Given an aorta containing Permutation of the
integers you have to split away into maximum possible number
of chunks such that after individually sorting eachchunk the
array gets sorted

assfg 23 it is 33527148 to 51
ans 3

arlo 13 É im 32 18 25
an 3

I idea
manco i min ite
if
a n

I valid chunk
3
i
ang 23 it is 3527 48 to toss
Polfinmana 23 223 23 35 35 48 60 60 60
Suffinminfs 10 10 18 27 27 40 40 4055 to

Count O AI AI tr
I PSuedoCode

int man chunkssorted 2 int assai

int CI Poefincaro How


Prefiaman
int f Suffinmin ans How
suffin

7C Ola int Count o

s c Old

fide
ifCroefinman
Count At
suffinminfiti

g
g
Count At
return count
a Point boundary
Given math n Point boundary in clockwise
direction
d I 2

o 1 2 3 1 2 3 4 5

I 4 5 6 6 7 8 9 10

2 7 8 9 11 12 13 14 15

I 2 3 6 9 16 17 18 19 20

21 22 23 24 25
8 7 4
I 2 3 4 5 10 1520

2524 23 22 21 16 116

Hidea
O 1 2 33 4

I 2 3 4 5
o 6 4
of 0th
no sow
6 7 8 9 10
a G 4 no
of last Col
11 12 13 14 15
As 4
of last
2 no row inreverse
3 16 17 18 19 20
4 4 0th Col in severe
y 21 22 23 24 25
no
of
gag
0 I 2 3 4 5
0 I 2 3 4 5 6
a a no
of 0th
sow
7 8 9 10 11 12
of last Col
I no
n e
2 13 14 15 16 17 18
of last
re a no row inreverse
3 19 20 21 22 23 24 re I 0th Col in severe
y 25 26 27 28 29 30
no
of
g 31 32 33 34 35 36 6 6
O 1 2 33 4

I 2 3 4 5 00
t
t
6 I 8 9 10
01 1 4 43 30
e p p ie p 27th th y y 2 I o

p I if
g I
3 16 17 18 19 20
y y I 0
4 21 22 23 24 25
gas 10 j y try j 4 i uj o
Éoj O
I Puedo Code

void PointBoundary int matane


int 9 0

int
j o

Ko Ken I Kitt L
for Point matej
jtt
T.ci OCA
Ko Ken 1 Kitt L
SC Ola for Point matej
itte

Ko Ken I Kitt L
for Point matej
g

Ko Ken I Kitt L
for Point matej
i g

3
Boundary intmathias I
void Point
int O
8
intjog 0 I 2 3 4

for Ko Kent Kettle


pointmatrixD
jtt 6 7 8 9 10
A
till 11 12 13 14 15
for Ko Kent 2
man
itt 3 s 20

4 21 22 23 24 25
pmpointmatrixD
j

for Ko Keno till I 2 3 4 5 10 15 20


pointmatrix D
a 25 24 23 22 2216 11 6
Q Square matin spiral
Given match la Point the spiral form

i j steps
7 8 9 10 It 12 O O N 15
13 14 15 16 17 18
2
of Itt f 2

3 19 20 21 22 2324 1 1 3
25 26 27 28 29 30 2
It
y t
5 31 32 33 34 3536
g
do Pointboundary till

your Steps 7 1

0 I 2 3 4

1 2 3 45 9
o
j steps
I 6 7 8 9 10
O o 4
13 14 15 2
2 11 12
If 1H
3 16 17 18 19 20 2
1 I
4 21 22 23 24 25
gyp
2 2 O
I Psuedo code
void PointspiralSquare int math a h
int 9 0
int
j o

int steps a 1

while steps 1

Ko K Steps Kett h
for Point matej
TC OCA jtt
S C old
Ko K Steps Kitt L
for Point matej
itt

Ko k Steps Kitt L
for Point matej
j

Point matej
i g

g
III steps steps 2

steps o
Point matfilli
if
void PointspiralSquare intimate a L
int in
intjog
intsteps a t
i j steps
while steps a I I 5
forcingtesters HI
0 O 5
pointmatrixD
7 8 9 10 It 12
Itt 2 13 14 15 16 17 18 I 1 3

forcingnesters Ah 2 2 1
pointmatrixD
y 25 26 27 28 29 30
itt 3 3 1
5 31 32 33 34 3536 66 Gerrit
forcingnesters Ah
pointmatrixD

forcingnesters the
pointmatrixD
ig
mom

if steps o pointmatfilli
3
a Spiral matin
4 Given match return all elements
m
of the matin
in Spiral order

0 L 2 3 4 5 o

o 1 2 3 4 5 6 o 1 i
j osteps steps
I 7 8 9 10 It 12 I 7 O 0 4 0
2 13 44 15 16 17 18 2 13

3 19 20 21 22 23 24 3 19
4 25 26 27 28 29 30 4 25
5 6 51

0 L 2 3 4 5

o 1 2 3 4 5 6
I 7 8 9 10 It 12
2 13 14 15 16 17 18

o d 2

o I 2 3 i
j osteps steps
I 7 8 9 0 0 4 2
2 13 14 15 I O
1 2
3 19 20 21

4 25 26 2
53
void PointspiralSquare int match Em h
int O
int O
j
intrsteps n t
int csteps m 1

while steps I 22 esters a I


Ko Ke ester Kitt L
for Point matej
jtt

Ko Kersters Kitt L
for Point matej
itt

Ko Keisters Kitt L
Tc OCard for Point matej
s c old
j

Ko Kostas Kitt L
for Point matej
i g
steps steps 2
gtf Steps CSters 2
g

osteps o 1
if int k O Kc esters I Ktt
for
Point math j
jtt
esters
else
if o

int K k c steps at Ktt h


for og
Point math j
itt
g

3
Q Flip bits
anaoonio.ain
as p.gstatantins
the Subway when flipped cangive man I's in the entire

en assist I 6 I 8 j
1 4 I 1 O 1 1 4
0 2 O 1 O 3 4 I
2 4 1 O O 1 1 3

a a é é
O 4 I 1 O 1 I 1 0 5

I ideal
and choose the one which
Toy flipping every Subaslag
gives us the maximum
FC O d on 2063
I idea2

Obst net gain


SA É I 2

SAL 63 3
To

SAC I as
In

subarray with net


flip man no
of gain

net
gain
I o a

0 1 ta
assai o
H
asf AL AI 1 At I I 41

I
the Suballay with
find
man
gain
t
man Subaray fun
hkadane'salgo

asf Al AI 1 AI AI 1 AI
Chan 86212 1 141 24 3 1 201 3
Oman 011213
Ans S
I Puedo code

int man ones int assai d


int count O

int i o ica itt h


for Caroli h
if
o

an Ei 1g
3
else f
anti y
count it
T C OCN g
S C OCD
int Csu m o

int o sum D

Lint i ican its I


for
o

else sum asolid 3

OSum Math man Cosum Csun

s
l o sum h return osumt Count 3
if
o

else I return count 3


you didn't this to come
come
this
far only
far

You might also like