You are on page 1of 18

cOMPUTATIONALTHINKINGFOB

P IC
Date of the Session: / | Time of the
Session: RUCTURI
to
Problem 1:
searches for a value target in an m.
m xn
algorithm that
Write an efficient
matrix has the following properties: Integers in each row are sorted from integer mat
eft to right.Tho
matrix.
last integer of the previous row
of each row is greater than the he first integ
Web-Link: https://leetcode.com/problems/search-a-2d-matrix/
Sample Input & Output
Input
S.no
Output
Algorithm
Flowchart
Page 258 of 368
411ncude < S t d i o . h >
hMatrd
search Matri tnt
?nt*
ratri,
COMPUTATIONALHINKINGFORSTRUCTUREDDESIGN
in1 motrix s ze,
xecution: cho co st2e, int
int malvix,
tasget)
Ca C: o, i4 matrix sfze; i++ )
fo C o ; ie * m atix cdsfze, jrt)
( m a h y [t]lj J r : tasget)
xetuan true
rekun false;
nt matot)
mati too] {too], mati stze, matix colui ze (iool, teget, si;
tnt
Scanf (" -lod d ", matrix size, tasaet )
Y2e ;Tt+)
fa Ct zo , ie matrix
4 =os ic *matriz colsize ; jH)
Scanf ((. d", &matrixl i]lj]);
3
cha ch
ch: Search matri y (mahix, matrix, matnix colsfze, taget
fE( ch= - t)
rinf("true "};
Test case Table:
elbe
printf false");
2 detun 6,
Testcase# Testcase Result:
Test case Tyße Input Expected Output after
Output execution Pass/fail
1 arget :13|o, u, e Falye Pa
2
Tue TTue Pass
Page 259 of 368
P IC
Date ofthe Session:
TIONALTHINKINGFORs
Time of the
Problem 2
Session:
You are given a 0-indexed 1-dimensional (10) integer
array original,
n. You are tasked with
and tw vo
creating a 2-dimensional (2D)
all
array
the elements from original. The elements from indices 0
with m
rows and n ntegers, m
should form the first row of the constructed 2D array, the
to n 11 linel.
(inclusive)
columns
elements from indi es nto 2*n.using
(inclusive) should form the second row of the constructe
n 20 array constructed according to the above
and so on.
original
impossible
procedure, or an
empty 20
empty 2n
Return an E
array it is
Web-Link: https://leetcode.com/problems/convert-1d-array-into-2d-array/
Sample Input & Output
S.no
Input
Output
Algorithm
Flowchart
Page 260 of 368
COMPUTATIONALTHINKINGFORSTRUCTUREDDESIGN
fnto, ?nt ekaunse
nt digndsi ze, tnt m,
Erecution
construct 20 Aray(nt igred,
iot
' t rekan column za)
orñgindStze;
len =
tot ar
arr.len)
Cmn !:
f
r e t n Stze 0
retun NULL;
szeof (rt ):
dze> = (fnt *) malloc(m
retwoceluma
1=0, ikm;1t)
faCinr
(retncolumnsizes)trJ:n;
rehunze « m,
(int ))
fnt neo-2d = (tt*) malloc Cm* s ze
(int) malloctn° sizeof(int)) ;
neu-24Ctj »
a (tot J o Jen; j++)
slgtnad [tJ;
heu-21j1 -
3
vetan neo-2d
Test case Table:
Testcase# Test case Output after Testcase Result:
Type Input Expected
1 2 : 2 output execution Pass/fail
2
(Tati Ct.lsn) fa
LLmtT
cOMPUTATIONALTHINKINGFORSTRI
TRUCTURI D
Flowchart
fet J :o je<NISJt+)
af30] + blJY7;
Sut 11J)
priot fMatrix sum s \o " );
o Gro jNI;jH)
priote " Sum[iJCj3)s
3
printf(in");
3
cle
printf ( Invalid ");
tetun 0,
Page 266 of 368
fibo} (o0, ij,btidoJ to6|.
5um
COMPUTATIONALTHINKINGFORSTRUuCTUREDDESIGN
Int a
rOtf (" Entel no ob rows
lio Jiod)
P r
and ,MI,M2,NI,N 2
lG
Executlon:
S canf . "kM1,NI);Columns o motrix A A ");
prtn (Ente no oß Yows and
sconf / d °/d", M2, kN2) columns of motix B "
4 (M1 = M2 & N1: w2)
rint f ("¬nte he motrix elermernt of
A ")
sconf (d", Aa[t3CJJ );
pint ente he matiy demens o B ");
fol (oj<N2;j++)
scan (3", sb[iltji):
3
printf '2D Matrix A f s \ n ");
fe (ojeNIyj++)
ptintf ( 4d", afiiG);
printf n");
printf (20 Matrix 6 is n ");
fa izo iM2 it+)
fo jeoN2; jt)
Paintf ( " , bro);
Testcase Table:
Testcaset Test case
Type Input ExpectedOutputafter Testcase Result:
2m output execution Pass/fail
23y
2
x
187S4321 0 o 1d (D
Page 267 of 368
COMPUTATIONALTTHINKINGFORS
SIC
Date ofthe
Session:77
Time of the
Session: to
RUCTURED
Problem 2:
calculate the absolute difference between the sume
sums of its
Given a square matrix,
example, thesquare
123

matrix array is shown belowr


diagonals. .For
456
989
The left-to-right diagonal 1 +5+9 15. The right to left diagonal = 3 + 5 + 9 - -
g 17.Their absolute
difference is
T15-17| = 2.
Web-Link: https://www.hackerrank.com/challenges/diagonal-difference/problem
Sample Input & Output
Outp ut
S.no Input
Algorithm
Flowchart
Page 268 of 368
include math h>
n t matnC)
Execution:
nt afto6J[ido
1j, Jaum= o, 1
COMPUTATIONALTHINKINGFORSTRUCTUREDDE SIGN
prntf ("ente nd of rouss and sum= 0, n, dR4;
s canf (" /d", An), colU mns"):
print f * Cnt ea the matri x
elemen "):
seanf (**1 d", o(itji);
prentf *2D matri i \n");
f Co, <n,t++)
o -o ien;jt)
printf ld", agity1);
printf ( \n");
fo eoi<n;i++
j o , jen;j**)
um: daum 4 afiiijJ,
YSUM= TSumtatitjs,
3
dt- Asum-TSum
printf ( Absolute stteunce is d",
abs(diE));
etun 6
Testcase Table:
Testcase#| Test case
Type Input Expected Output after Testcase Result:
output execution Pass/fail
fan
Pom
Page 269 of 368
SIC
cOMPUTATIONALTHINKIN
Skill 2:
Date of the Session: lT
Time of the
Session: to
RUCTUREDDES
Problem 1:
Given an integer numRows, return the first num Rows of Pascal's triangle.
Web-Link: https://leetcode.com/explore/learn/card/array-and-string/202/introd.
array/1170/
ion-to-2d-
Sample Input & Output
S.no Input Output
Algorithm
Flowchart
Page 272 of 368
COMPUTATIONALTHINKINGFORSTRUCTUREDDESIGN
i n t *** g e n e r o f (int numfdus, int " retusnsize, i n t ** retunCokumnst z e )
Execution:
retusnstze : 0
tetncolumnsizes = NUL;
4nunRoDL=0)
e t u n NULL,
fnt ret= NUL;
*YetunStze = numloos
ret maIoc ( st2e of Cint *)* numous);
O, TOW <umMeus ToLo++)
Fo Cfnt row=
ret r o s = malloc (szeof ( t t ) * (roo+ 0);
ret froul Lrod)-3;
3
tetwn column size = ma0loc (slze of tim)* num oues);
F Cfnt rODZDj Too<numkouos Tow+4)
Cretuncolumnsezes) Irowl: row1
f (int rotd-2 T6oLnumkouos j rott))
i n t col= 1; col<row, colt+)
et (rousJ] =rer Crow-13Eo-jt ret[raa-(]{lj
3
retuin Yet
Testcase Table:
Testcase# Test case Type Expected Output after Testcase Result:
Input
output execution Pass/fail
C, t), tto, tuo,tul
Pa
2
Page 273 of 368
wME
cOMPUTATIONALTHINKINGFOD
s IC NGFORSTR
Time of the Session:
UCIURLD
Skill3: /
S e s s i o n :
Date ofthe illed cells need to b
Problem 1: Sudoku
board is
valid. Only the
validated
xC
Determin ifa 9 f o l l o w i n g r u l e s :

1-9 without repetition.


1-9
to th:
the digits without repetit
contain
1-9
according
Eac
row
column

must
must
contain
sub-boxes

the digits
of the grid r contain the digits 1-9 without
Lach
the
nine 3 x3
repetitio
be valid but is not necessarily solvable.
not
could
filled)
board
(partially according to
to the
the mentioned rules.
Note Sudoku to be
validated
A cells need
Web-Link:
Only
.
https://leetcode.com/problems/valid-sudoku/
filled the
Sample
Input &
Output
Output
Input
S.no
Algorithm
tincudez Ssting.h>
HfncludeL Stdloh board e sYe înto
bomd irt
boolsvolld sudoko (Choy «
Int row =o, Gumn -o, ldotk o j
for
(tnt J-oj jua ij+*)
4 (bord E1) C3 =1,
Flowchart
it numal2e (board CiIS)-'6')
num& 100 1elurm falye
oo numj
board $ 7 ( ( o )
nthuna4 faluej
(num& Coumn uturn"
Cokumn age of 363
COMPUTATIONALTHINKINGFORSTRUCTUREDDESIGN
Execution:
pfnt =i/3* 345(33
ot = 17: 3* 3+37. 3
t u m - | (bord [x][y - *
(num
BocE ) return folte
block | num
3
int main C)
Cha board [ioJ[too]
fnt bead ros stze, bonrd size
Scont
("d 7d "a boord Pouo Sta,k kooas sta)
Scn
Chor
s", loead ),
Stoe) loco
=
valtd sudoko
(lobad, boad Rous Sez
Paotf(s'
Detun o,
s), bod
Sta);
Testcase Table:
Testcaset Test case
Type input Expected Output after Testcase Result:
output execution Pass/fail
Page 279 of 368
OMPUTATIONALTHINKINGFORST
sIC
// ent is 0, set

Time of the
its ntire
Session:
row and
to
TRUCTUREODEr
of the
Session:
if an
elemen
column to o's
Web-Li
Date
nk: https://leetcode.com/problems/set-matrix-zeroes/
Problem 2:
Given an
mxn

integer
matrix
matrix,
Ouiput
Output
Input
&
Sample Input
S.no
Algorithm
Flowchart
COMPUTATIONALTHINKINGFORSTRUCTUREDDESIGN
#inctude< stdio.h
Execution:
t n c l u d e <stdlib.h>
t d S e t zerbesC n t matrix, int mattir stze, înt matrix Col size)
ne i , roud'
rouo marizaze/+ matrixcolstze
fok o K< mari zsize, k+)
toCo J<* matrixcolstze ij++)
e Cmatvix fkTj]= -6)
paint Cmatri, k,j matrixcolslze, matrixsi ze)
fe (fo 3<matrixcolsize ; Jt)
matir (r10J=0
Vold pant ( int **matii., îot rou, înt col, im matri» co lsize, int mamx
Row size)
o (20 te matrix Poudslze; *t)
Testcase Table: ttoi reatsixco re,tte)
Testcase#
Emaix (rou)tl]!0) matrix (o1ü)=*'j
Test case Type put Expected Output after Testcase Result:
output execution Pass/fail
Page 281 of 368
cOMPUTATIONONALI
IHINKINGE
Time of the
Sesslon:
ORSTRUCIUNL
Skill 4 Session: to
Dateofthe
matrix is Toeplitz. Other
erwise, retu
it the
Probelm
Given an
mxn
matrix,
return true
from top-left
to botton false.
same elements. Amatrix
everydiagonal
if
is Toeplit:
Web-Link: https://eetcode.com/problems/toeplitz-matrix/
& Output
Sample Input
Input Output
S.no
Algovithm ncludeestdioh>
#inc ude &Aalib.h>
Shuct matîx
nt n
void
set(sthust matix m, înt ?, ints, nt Y)
(te=)
mBs-1)-Y
Flowchart
t Get (shutt Mabix m,int , it 3)
netunn m.6 j-1J
3
Vekun mm.nti-U7
Page 284 of 368
COMP0TA
Mati m)
Notd Cspley (Struck
xecutlon
PRtf C\n matrfx is: Nn")3
kr Ci1 tee m.n itt)
Pia4 od , mB[-11);
ee f i5)
PrRtf . d , mB[mn+i-3- ))S
Pintf to")
Pratt C/n");
i t moin )
Sruct matriy m;
int ,3, matvBx : )
");
Testcase Table: of
(Entr Omensian
t
Sconf d& N) Output after
Testcase Result:
Input
Expected Pass/fail
Testcase# Test case Type output
execution
D" Sfae o (tot)) 55
mn-
MB(int ) mallo((2" \n}
au t e eloments of
ths maxt
PRt ("Ente
for Ci;ie m.níitt)
foY C=1; je mn3j*t)c
Sanf (/d", qy)
3eam, i, sXG 285 of 368
Dpleym)
S IC
OMPUTATIONAI
ALTHINKNGFOV
Date of the Session: 7
Problem 3:

Time of the
Session: ORSTRUC
to
Given a 20 integer array matrix, retun the transpose of matrix.
rix. The
The transposee
the matrix flippedover its main diagona, switching the matrix's
row and
coloof a mat.
a
matix dices
Web-link: hrtps://leetcode.com/problems/transpose-matrix/ is
Samr'e Input & Output
S.no Input
Output
Algorithm
int* transpode (int A, int Aze, int Ä
calsiLe, int
int retun coulszes)
retun h size
int zo; j#0;
nt temp =O
nt Aze
int c
Acoze fo1
nttarget Átr =
malloc (ze of ttnt)*Cc));
(tetuncostza): (int )malioc( c» tze of
Ctnt*)),
Flowchart
Ciozc;i++)
tagetAru3= malloc (size et Cint)» tr);
3
retsncolszes ) (I3:Y,
fr Ci-0er; î +)
COMPUTATIONALTHINKINGFORSTRUCTUREDDESIGN
Execution
etuun tataet ArrT
Testcase Table:
Testcase Result:
Output after
Expected
Testcase# Test case Type
Input execution Pass/fail
output
Pom
34
Pero
(ForEvaluator's useonly)
Evaluator'sObservation
o u t of
Commentof the Evaluator(if Any) Marks Secured:_
Full Name of the Evaluator:
Evaluation:
Evaluator Date of
Signature of the
Page 289 of 368

You might also like