0% found this document useful (0 votes)
5 views

Arrays 2 Copy 5.pdf - Mpcgwu

Uploaded by

shakirali9581
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Arrays 2 Copy 5.pdf - Mpcgwu

Uploaded by

shakirali9581
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Today's agenda

reverse an
assay
Reverse a
given Partofarray
Rotate
away by K
greater than itself
Two Sum
a Reverse
array
Given length n Reverse the whole array
array of
en arris O 2 30 405 3
50 40 30 20 10

am 8 10 To 30 48 s 80

80 70 60 5 40 30 20 10

am 18 10 To 3048
501s 801
80 70 60 4030 20 10

sure L
swap
su
sw f3it
I PSuedo code

int main h
l input any sida
reverse ar

int i itt S O p arris


for O ic arolength
3

Public static void reverse int C arr 4


int n art length

int SP 0
TC OCN int eP n 1
S C OCI
while SP ep 4
int temp as sp
an SP an Iep
an Cep temp
SPH
ep 9
3
3
n 7
Public static void reverse int C an 4
int n arrolength
aorta 1 2 3 4 5
9
7 3
int SP 0
int ed n 1
SP EP SPC EP
while SPCep 4
int temp an Csp 0 6 T
arose aroled 1 5 T
aroCep temp
2 4 T
81
3
3 3 buenit
3
a Reverse Part
a
of array
Given a element and Cs e reverse
array
the array from s e

areas I 352835 2 io
3 4 2 2 6 9 3 8 8 10
swap 3
6
Swap 4

Public static void reverse int C art int s int e 4


int n art length
plenity
wife int SP s
T.CO
E DinteP nX e
c Oe

while SP ep 4
int temp arr sp
an SP an Iep
an Cep temp
SPH
ep 9
3
3
a Rotate the array Igoogle meta amazon
Given a elements Rotate away from last to

first by K times
KLA
area 13 I 6 5
1st not

d
485 2 Ii 5
C
expected 7 42ndout
O a
expected 5 C
29 8 3 2 1 4 63
Bodoot

6 9 8 3 2 1 43

area 13 Ii 6 5

6 9 8 3 2 1 43
area 13 I 6 5
Reverse the
array
is it
Retersethe
is
K elements
first
6 9 8 1 23

Refuse
the elements
ofter Kth element
6 9 8 3 2 1 43

6 9 8 3 2 1 43
I PSuedo Code
int main
I input aorta K

K K N
listen Reverse the
array
reverse ar O N 1
T C OCA 11 Steps Reverse the first K elements
S C O 1 reverse art 0 K 1

11Steps Reverse the elements


after
reverse far K N 1
3

Public static void reverse int C art int s inte


int n art length

int SP S
T.com int ed e
SCOe

while SP ep 4
int temp an sp
an SP an Iep
an Cep temp
SPH
ep 9
3
3
door I I 853
1041
9 4 1 6
10042
6 9 4 1
1003
1 6 9 4
10044
4 1 6 9
100 5

K 10

aol.is g
100 1
9 4 1 6
100 2 2045
6 9 4 1 00 6

100 3 00 7
00 8
1 6 9 4
100 4

4 1 6 9 4 1 69

no rotation K N
effective of
aorlength

N K effective rotation
7 22 22 7 15 7 8 7 1

2 7 1

7 31 31 7 3

7 3 3 97 3

Break till 10 50PM


Q Given a elements count total elements
array no
of
having atleast 1 element greaterthan itself

en aorta 14 i 9 3 54
ans 5

90018 3 4 11 8 2 10 9 113
ans 6

900157 47 7 7 7 7 3
ans 0

aorta 1 2 2 3 3 43
ans 5

I idea
obsi elements are not valid
man
of the array
0352 except man elements all the elements
for
are valid

no I count it man count


find man

ans no
of elements man count
I Psuedo Code

int countgreater int aora 4

int man arr To

int i ien it
for
if Caroli man man aorti
TC 0129201N 3
SC OCI
int mancount
09
int i O in it 72
for Carli man mancount 3
if
3

return N mancount

3
mancount 01 2
i

int man are areas 3 4 8 2 15 I


int i ien it 4
for mar 3 4 11
if Caroli man man aorti
460

int mancount
09
int i O in it 2
for Carli man mancount 3
if
3
a Two Sum
Given there exists
a
away elements check
if a

Pair i such that anti arolj K and i


j j
Note i and inden value K is given sum
j are

en aook 2 1 0 3 2 5 73
1 8

as 4 1 3 2 63
K 5

axis 124 3 I
1 8

0016 3 5 1 8 3 73
KG

You might also like