Smart Interviews Notes
Smart Interviews Notes
A) " fr (i= ben wt (Kid * ~ aliq) tn a 7 -lor( j=i+ jensj+s) Be f (ali)wl Apsum(int NT (w= =o7TIN) = Tln-3) 44 —0 (7 (N-2) 4 4) 4 4 = T(N-a)ea —@ Bar(N- 3) 49.5 N-k=! T(N-3) 43 —@ ee For k times :- T(M=E) 4p TODeae = Th) + N-4 V+n-y @ tn) (nN 4 Koy (+ Q+ a + No) tx gta £ o(o"”) OT(n)- a7" )an = weNleq Ns O(ntog.n) OTY)-ar("Z)+4 (ny OT(N)- (4) 40 @r(n)= 1/444 Tla)- c ( 72)Sthocle —for rec widen i— méthocts, Co a Substtlition ‘me aXr( N/ok) +KkN > Tue Ajier kK time a*t(1+knlu) —D SUN. j= T(NA) + TZ) sesample Oulpur ¢ 1g “19D iB 25. 85 1D. Wey. le et » sland with 4 are Lata), (4410), (FS), lugn) , [4+ 8) = 8 tw, 98, 19d. => Lum -fovined with 10 ane (orb) 4 (10710) 4 (10454), lig tu) y (10-48) = 1H, 20,180 52) te S sum formed voit By Me (4 +0), [64 +10), (54 +50) (Sv +), (Sy+9) 2 b& Wy) 108,65, 6o * 5 eum Lpiinéd? with a9 ane (44 +0), lu +to){N FBG) (w +I, (+8) = 15, 91, $6,232, 14 5 Sum Immed with < are (s+u),(8+i0), (s450), ( B+) (848) = 12, 18.69 fib > XR of ail the aboue Stuns = i (8A 1y 298A 1GA12) A 2h te ian (aya 20 ncunst ais) AOahol v2» Sasim-¢ Tweedy | 0 ? : > Backtracking a > Necloocteio * Backtracking ts algorithm technique {or soluagy Problems Mrecuaisiuely by trying te build a “lution tnvrementally yome piece at a time, we owing these Selutims that {oil te satisly the wnetrainte | the )>voblin at any point a time Fetmutations ancl Combination . SOlHor s > OVIy > K= Sum | avig-T5,-i0; 91% k= Qh 13 + eucry element haus heius @ p; PM The +wo. elementsoS vtetwsin Sum = =k; subsetsum (ax,k,n, eum+arLida), ideas 4) I Subseteum (a1,N, 4, cus , ida+1) by rue a(r(n-sea Subset- Pasian nthesis h cub Faun ay , . bli l r } [ N=6 N=¥ Hien N= print all va bee y'5 eee) PAXanth wi in lenivag 2 ((09)) Mey 383 order Be 0 Fy 690.2) PeLi> ¢)) elf Aenicoaraphical rider ben ()))—_— oor ace "Yo. puk (’ NG €C <0c _, put'y’ Void qn Fasanthesis ( chan a4 17, tnt N, tot ida, int Oc, int co)P if lider NIT Prt (Aiy1)- a , , (Mtetorn ul valid a : ; ‘| [oc< NY a WET mivogra phical ; Number WaLiday =") Poutar thesis a , Nn, 1a+4, 0C+4 »CC); ToDo if auTidas = 'y be Jen Paxanthais( ann, idasd, 0¢,Cc +4); 4, 1 nun USF ta, J You ane given input malra . Find minum nrg V Commute in te Magic Square d 1 buenerale all Pow @ For cack bil = G oi 4 i fe ii, r ¢ mar dor (int j"a Ahonen | 3to} 2025] re Smarticterwier Oe . he tSmarb, ¢ mart gm, inter, vi L » Sm, ler, views | interuiewe 2 d check ty Ll iss POSibk tp fem 2 ~~ | way {om String using L 9 Min de i. : J boo! l inl I th » endo 4 ind + +)5 2 Vielwin t Setter False ; of O mH ont Vord/ > Lnlerleaving pC [ptr sje BI ptray) x utes [ pr &.fo (sar, lenglb-4; i>-0;i-3 1 i ee stn (jao. fei sj a4) ; s least = cu Ci); { iplartjd > least) : oS -tor (k jo kK] k=) t ar Tk) = an tk-1] i a arly? . least ; t ae Eg*amyple : 10 30 5 60] 2% o t a arlj]> ay Ci] i a-alr) me: *4) i arti] = all; ie oo 8 4 alj) = “temp ; ay 6 up a BO orto i EF ded 3 |< ar.teng si++) Sorted tinsorted Cin ; 4 tor Cint j= i- or 0; |-—\am t > swap (ar, | i) s 7b VOR Aheca tion Sef (Bey A Void ineertionSort (int arld) 2 while Cant Nr N=ar d anTi +4) lj es J 10 39 20 6p ee atl | if (arty >ar lil)r oid insertion Sor (int art ib or An(int i-35 to int temp » auTiy; F nig ie oe a! while s-o 4a an Ci)» temp) t antit4) . ambi; t 1 ez) av Ty +4) = berop; 4) Th e v r r—» Cadiclate ay 3 5 5 tae a, g—4 oretum g Te Bat OC Mane) int wanVotcs (tot ct], nt N, int MDT imt mancnt=0 , ant ed: tn Cint iso, ie=M, 14 OT ink cut=o ; tov Cink fees jena pHeT i Ci= 2 alj))it cu +t); ui° Lae as hares eg Ss 2 ee Be oe oe capa are [o te [ int meagvinner (Cnt arf), ink N, ot mM) int cl f- new int Td: Fore fot fap; tem: i¢t) elijzo, ink maaboinne (int art], int n int cl] = muo int Tm] ; tov Cink i-0; icm: ite)y Cli l=o; ie akid r ctor (int io) jem eet h ( Ti > many ‘waa = CTids e One. F ue wduin cans; is. AGrnunt Loris ) Coumt Sort 0 1) 2 en 71. To am’ [oTs | 4 | t[o [s]o f E "i + 3) 3 Oe me! 2 8 ag 618g Sorted Leet. pe : a Void count Sort { int AtTd,int N. int m) 3 ; i ned itl], "+4 int Domes _ 7 for { ic me itt)y -or( int i-0; iemsi4e)y ibets sored blalitj++: 5 ercating count “ad + mr t-o; os Tims, terCint isteicemm;i+eyg > ™ onal Cit indice M144) 7 OCM+Ny im @-bTiJ; Cn Pe) las a lca alt ata iEm: a--'0 b=0 he (b-a +4) cable} * ~** gta m / ; cutlij] = -4 | cat [b-at+3) = 8 catT a 1 2j g ons Gam = ent [1] = 08 }asfocloors) merge fork 2B Menge. vtw0 Sorted, pink -un Sorted cadet meee Ik ig Be ore Mm -2 6 4 9 ; Me? 8 hb lk a 1 ig 2 Solution: | Gow Gite * Solution]. ty, (4? + Imilialise the aviay with ee inn Then. vopy ‘the elements jowm aT Cs } ‘Then use a Sorting algorithm. is i : ce CNM)", Nt 9. Na (NxM), ney cepy err 4 bir es £ ss) ' Me — oe Bis c Time conplone algorithm I Tech nei ue) GALT, EN, ing bill, inkM) int P41 -0, P2-0 ,K=0; int CIn+m] , a while ( p aoutny eo : > Void merge (int 1 Using Tmserbiin Sort, with the es : ' ‘ vile elee T "7 i AG TRe ST © py TP, ++]; Clk ++) -antr +e),Ss af =< antmtn] « 94 “br imd astae 69) ad) tH Sata Me Li apt. Solution: yma (m4N)%, 4 4 Copy bn ia rs|es|e¢ | O (am). wi @s Nt, Nam | ; 7 . te ‘ o : Cepy avi tec -Tnsesting bo lo pointere © elemenlé in ¢ °, ! SF ta tt aaa) 39 20 a2" on RR Pe “a - oo See 4, . 50 K=N+m 1 i Pye N~1 decremnenling porters S, i Pa=mM-4 by qetlouring condition 4 Te 5 NIM, 4 = Grits Bihary: way. BO ee eat i yt By AMOUR! 5 5 | cay @ii Meemoeely oo |, Such ‘that the Se eel Should decrease {rom nN Aolution:@n?, 1 [optimised @ y,4 (nta 4 ee I, Ts] s¢]B¢ Crk any Thane i arting Technigua. | Travesee Tae a ~*~ iY > bount => Count Sort: @0 taking +00 pointers in fucha way, .. D Py | th tt | ee > s ary | © Ooh’ Or Ota) rf Pointer 2 f ) Pej *P wilt 4 axe about O ie» it waith hebpilg oH ent, " platy them wv auiay . i bout 4 hey wall balp plang them wu auay TendJ. | q 7 { j ’ ” | ‘ n 999 t nN 4¢ P, 4s)t £ wap [anle,J, an lh, 1) ‘ Pyele (avi Pod 22 47 Fos =d3' ’ leit Cowl Ad > ary thd )4 ewap ( oulA), vo TRI); 1 ! Wy ( Find tount pa | lq: & , 4 } aX ( 9 i. 0 4 (u,4)) 15 le 10:2 f On Output’ Cant '- 23 wuntso -4 o ee ial » V : y iO” pein ‘| (avilid >a tj1) Solution « ) yetort +0 hima | 7: Fc sola P amen <2 wale toe .g ; y at Ss 4 ty AR ani ee Aa 2 5 00 9 2 oid , a ‘ " Ny Lad, hie 9 \ 10 J t pan ay wh 16.47 et is 3,1 9 4 sie Sa Sig oo ee 3 / a Y > Ss £ tate (8.47% J Cea Z x e fo) : 0 > Void ry dort (int Only, int +19; oo hi, int NE 1( lo == hi) 7 wietuan 5 int mid “Cori / amerge S01 Carry lo hid , ns; a» T{NZ 9 ) amerge Sort Carr, midts, hi si ~ yh hex merge $B (aur, lormid midi, hi), pr. ist merge co ( 8, pos | TC)» eT eaOE Cr =a ¢ avi [lord * oer lo 5 midti=& ae. . 15, 20) ctempr D9 6, mid - 9 hix 4 lo J BOE 09: Cae int terop'| hi-lb+1J, K=0 5 | tf Cart Leo <= au Ixy ) ALemplk++ Je awl tow+s); | t else T | “emp k++] -oulat+)- ) % = veid merge (int ait, int lo, tnt mid , ipt hi) | int temp Chi-to+a); WE a=mid+4, k=0 while (. toe mid 44 Hehi)7 i[lan tog <- avila) zx -lemp [k++J> an Lo+ 4], or l £ deci Count += (idl — lew + 4) : a alate), * = tohile (9 <= mid) Z errno cs Lesa1a wohon even -the -f 2 Simplified Maelere Theorem: Tlad= 21 pln) = at (™%)4 ab +a ae AG) = ue 7 Od cot o(we) oe tog Gh cer o (wt leg) ee aque Gi) cee OCNE) undion is in wecuytue -tuoction we use “mackere sheorenm” ae ee Seecion - S 4 wel 5 Stu of tio no'g Given” 20 elu Be t Oe ee Tuesday 3 15 1 oN 83 : B ouule f evee olution : ee -0 1 <|f lee # oe DN 4 or [ J 1 A ength +7): ' Cilepp ay: corked am 2 << ae Y(alil+alj1="K) yg 3S ee vteFuun the; [K: 20 a / vickurn Falee; golution ; Two pointer > 9 Nleg N+ Ns Ny mae a 4e:q int a0 —— “Workihg &-Poinker, (erate tba malh-4 : 5 Zend o te arnay. tohile sa: “A ‘|latal +A[b)==k) iteration, a4 victwin. Torus > >Bi bead siete! ae iteratim : 1545 <- 90=k = return serie. a + 182k pe Oma Mie mie gh "y ot by defa in 2 Wty! & ©. 8, 1m iN a #5 ae a | 3 38 56 ag 41 | | ki a3? is . De F Phreany sensch ) few - 0 ! T Therative J | highs n-4 J while (ee. high) sold low + high rz autted IM katbmids VC : maid a wetuan mid; elec i ( alad] > key )E high = We sa: | necun sine] & ; z eh tnt BS| int ania, Ut Tey ew ditah= mid +4 ; ue Oo mid + a i boosie ) | “ we bun Nebwin -4 y - e as Tis) = at(n4)4 a annua wusive Master ¢ Theorw t(N) . (NZ )+4 insorted arr unsorbed an (0-9) ee arr : (Q= _(a-4) J earch ye nay ee si atiisty., Nlog n+loqne4 NleqN+Gaaa loqnaQy i i ; z 2 J2 > = : carc e e — Df q Nad 5) > i ra ‘ ; a 3 6% > S ar: 12 8) 4S 6m int lows 7 i j int high= -4L i mano tohile (low < high) Tit mid - (ter0+rhigh i (an [mid Je: 4 We aaliated ‘ .t QO sort Cary i we ist low = 0 phigh *N- 45 ink as = INT min; while (16.9 < hi h) x lok amid = (Crew thigh, 3 ae | i (a1Tmid] ey ang = anlmid]; en loudel Vs toww= mid+4 ; é else i[ Can Tad J==) 7 ee mid J, Wekuin ame ; high mid -4 nebwin ans U 2 — alitd+ al) webu 1/ fF ~ ant J BSR( ano, } -4 yk-an tj) or MejtaN-2,K-arljl) POWN 5 10 ¢ IS ~ BSR | 110.10 -2.. (o> inieng a aaa Qn,i peiez' — oe 0-2 16 3 -5 re i Q = a<-anlil <=b eee al ' Bereinhs sn gue | 224 oe 4 CLT pra 4 eo CCITT Trt . > populate cat ay ia | a wa Sprotunt(a) oe oe) Q + to 424 w 4 Soy @ + @ -5 -5 -2 3 10 10 10 10 tp he 15 4 12-0 Desi ee PES (i) Sort usw ] merge Cort 5 ee Ci) Using ¢ oe dina 9 UW rom pe 1a mous elt wight te updalt nk of. Bt: tew-0, high=0 intr, --1) tol wlan: niaga <0 Cased, N while ( te high he Mar pe ee merge Biman amid = Yowi( nigh low); i cal tale . 'f au [mid] -=@ e me ede \ SP ‘ = etn amid/_ nea? 9 low=6, hig 4 . i hie id= LY mid=6 4 elge if avi Laid ] >a ae high = amid -4 3S DemiaBs, 3 ection | if Cour Pri] =) T NloqN + wlio + toy pa=ouid , ; | tow = mid +4, ie | Occunene Decury ase i] C at [mid] >a) | high-id -4 . zg alee 5 lew =mid+4 5 7 $ . vnetunn Pp, > y ® Pa bo ihe 1 n 12 48 . OWN i -6 -5 -2 333 3 10 t0 101040 toa BY y v z | Pid = 5 “a 4 N+NH [ RYN Y | eb 3 Bi is Ms, ( Sa NleqN +1) +a v Oh Puy, 6| elerse Ae es distenct elementi is ae Two pourter . cio Sort The qitun arvcay Ads W) ti tie Covecuys Al] Hor distinct 811 [4or fovequenyy a dlomuntel. C © pal eae, eRe eis 294 0 0 1 oe a. 338 10 0 10 Ip lo 15 1§ Be 3 e Lerneris] 2 C2 pointers) | lo 1a 15 20 3mm 0 © 8 oe ie be mm Qu: iQulorbing ancy ® se4ing all the queryits i» Am. ‘0 copy Qm to Sriqunab Ram anny . '® gort &™m ‘6 Use 2 pounter to updati tount vig ) US Oviqinal QM ard Be on gw qt tnequniy. JlogN +0[n 4 Ni i Q(N4+n4 NlogN + (cq) r | f / a < gN+n+Q. 2 12+ N+ @l0q mj af : "bee ot ut 1y¢ TWO poind 1 Twa (1, ' pomtue mi Hach wv | Hagan eit rar Hashn ap<=()) Prt . Hath “gO dictiong Z 2 mi le thi : a i mid % » ze[s Mid-=4 cli, arr Tiel) to-mi: alta} 2083 Tsatwiday J [session - 44] ; > Gran job ichich hae been diuidd ile vi tasks » Each takes g; Secs te tempi .& workers cellocated Only Continu take. B worker tan work on a Single task ak ; qiuen point o time corks pasate oD Ailfeneot tasks Minimap possille time to empl Job Each Worker Lan take Lontinupiy +0rks workers kik y . Oty, ! uo Ss | he Sh 4 3/6 1 5 . Pastis: — Ib 13 hi 2 Stag : ‘i . Sum { posite | al ‘ © ans «mf | ( back Hacking ) a int gans - INT.MAX; / qlebal ane Lees | veid sa me sink K, ine ide ink wn int cong) 2 Woke aA) T ‘ . | | Sum =0; Ma viz na | for(int i= iden sTeny l4a)T fi 4 ‘ Solution : Sum +> awiliz, ey 4 Cang = maa| um , cane), © Na K-1 a 4 gaps > iol cans, a) g ifGda = wil35 (valid) a (vad) 15 (wot wali) 19 (valid) m 19 Ib Cwok valid) 4 q 1+ (wok valid) # “4 > mid) Ee = rE valid ant s éo IX 18 14 1a a3 a0‘ Bea : 7 a T 2a T | pi ‘i mA 13\ ralec a ; {9 min (ans, | Srna); 10 bed aed tx , 40 4A, BOR: binary Seanh). 7 Be ydid (au, Nk» mid) 2a (EMME bs (int coord, i by OE NDT as jay . it lo = maalav, hi = sum Caxw) , ans ~. wohik (ve < hi) t int mid - (loo hy , i Cwalia (a1, n, 6, mid)) L ang smid} taDr reas, cs int k, ib md 7 Pky kis ent- 4; ter (int feo; den5 i++] Can Ti] >mid) wietwan Fale } re += anni]; iC Sum >mid)z Cnt+=4; 4 Sum awtiy, x x > i Le a (arr) meant = Yletwin Cont < k) 4 gf s Ken Minima possible Valid uncon > u've N houses ard yeu hawe k stelati | houses. Minimum chictame bebo le as large aS possible v © pultog. pointer at cai : ge N ‘—" , géplution wsing Binany Search. alow von be an loj Ttow = an loI} Gor) do abb etmid)yal > Median of no(@) ake aways: 3 Det 3 1B al as 45 6 9 zg Byb@-o % 8 fh -20 99 a5 tc c Nm —s odd, No duplication A Oring” Pp 4 moe ae me + tg - 17 10 " 2 ¥n Pee 2 yr ID Ig 13 16 18 20 21 aQ a5 aw oo iy Solution. CO! Ss th 1% a) a8 45 DN+m » Neng ereae se tf x Y 2 13 16 3 8a a5 *TwO pointers ia ; 2 Varulab le * By using ! by using Cony pointes twhich tnt and _ any COmpaste both avraye 2) N+nm 4 . cnt BI YUL ST yy ae . < v * using Bina Search ‘a mya ( id= Q 23 lex (hig 1G at i . a Pte “. - 23 ds loo +4): é fae tin Sp 4 si aid atten legsent U5 a3 lay 3 ine a4 QQ IF g to Q | a aa 12 i Ag 3