<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1570382885092564234</id><updated>2026-07-03T07:02:59.919+03:00</updated><category term="C"/><category term="java"/><category term="50dsa"/><category term="Paradigme de programare"/><category term="Linux"/><category term="Python"/><category term="angular"/><category term="Structuri de date"/><category term="javascript"/><category term="prezentari"/><category term="interviu"/><category term="sortari"/><category term="Principles of Programming Languages"/><category term="Proiectarea algoritmilor"/><category term="Scheme"/><category term="online course"/><category term="Algoritmi paraleli si distribuiti"/><category term="Programare dinamica"/><category term="Protocoale de comunicatie"/><category term="assembly language"/><category term="grafuri"/><category term="Baze de date"/><category term="Cracking the code interview"/><category term="off-topic"/><category term="php"/><category term="video"/><category term="Arhitectura sistemelor de calcul"/><category term="Programare web"/><category term="Sisteme de operare"/><category term="bioinformatics"/><category term="boomblebee"/><category term="PL/SQL"/><category term="Udacity"/><category term="graduate studies"/><category term="kotlin"/><category term="tests"/><category term="CLIPS"/><category term="Haskell"/><category term="MPI"/><category term="OpenMP"/><category term="Structuri multiprocesor"/><category term="practica 2011"/><category term="utile"/><category term="Android"/><category term="SQL"/><category term="codejam"/><category term="e-book"/><category term="lucru pe biti"/><category term="C++"/><category term="GIT"/><category term="OpenCL"/><category term="Retele de calculatoare"/><category term="Verilog"/><category term="maven"/><category term="pluralsight"/><category term="sockets"/><category term="tutorial"/><category term="windows"/><category term="work"/><category term="Aplicatii integrate pentru intreprinderi"/><category term="Automated reasoning"/><category term="Calculatoare numerice"/><category term="Google App Engine"/><category term="POO"/><category term="information retrieval"/><category term="spring"/><category term="training"/><category term="AI planning"/><category term="Backtracking"/><category term="Elemente de grafica"/><category term="Inteligenta artificiala"/><category term="Limbaje formale si automate"/><category term="MIPS/SPIM"/><category term="OpenGL"/><category term="Proiectarea retelelor"/><category term="Prolog"/><category term="SML"/><category term="catalog"/><category term="html"/><category term="html5"/><category term="intrebari interviu"/><category term="jpa"/><category term="kafka"/><category term="strings"/><category term="struts"/><category term="technical task"/><category term="ACS UPB"/><category term="C#"/><category term="Cell"/><category term="Cellular network"/><category term="Electronica"/><category term="Invatare automata"/><category term="JVM"/><category term="Matlab"/><category term="Modelare de date"/><category term="Nachos"/><category term="Principles of Compiler design"/><category term="Ruby on rails"/><category term="Servicii distribuite"/><category term="Silverlight"/><category term="Trie"/><category term="ajax"/><category term="arduino"/><category term="batch"/><category term="blogosfera"/><category term="brain teasers"/><category term="chat"/><category term="cognitive science"/><category term="concurrency"/><category term="conferinte"/><category term="crawl"/><category term="cuda"/><category term="de-ale internetului"/><category term="docker"/><category term="excel"/><category term="gRPC"/><category term="gem5"/><category term="grind75"/><category term="hadoop"/><category term="javaFX"/><category term="jdk8"/><category term="jeem"/><category term="json"/><category term="klee"/><category term="laptop"/><category term="lisp"/><category term="minimax"/><category term="nlp"/><category term="otter"/><category term="perl"/><category term="pipes"/><category term="poza zilei"/><category term="profiling"/><category term="pthread"/><category term="regex"/><category term="review"/><category term="soft educational"/><category term="software engineering"/><category term="software security"/><category term="solr"/><category term="spyware"/><category term="string search"/><category term="summer school"/><category term="swing"/><category term="uml"/><category term="virusi"/><category term="vlsi"/><category term="workshop"/><category term="xml"/><title type='text'>BoomBleBee</title><subtitle type='html'>Am deschis acest blog pentru aducere aminte.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>394</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-7551370213878279659</id><published>2025-11-08T12:12:00.001+02:00</published><updated>2025-11-08T12:12:00.120+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="blogosfera"/><title type='text'>Top 6 API Architecture Styles (repost)</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtXB9cwOuI-sFZqwIxpIc-ikONJldlpV5t8txACoggaUXT8dc_3o4tiiIIEW7vODkzCmGsCfRu1Us3lpbQkWRFEpjwQPMHZ_UNcKL0XP6FjdmccTPEn8xt6PwTb6rDTJzSdVO_YCHAa-91ytdeA1-i2lXf7HoKIoTMQO-BUNnAjF5NLiAW8LPl_7qtaA0/s1100/top6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;722&quot; data-original-width=&quot;1100&quot; height=&quot;391&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtXB9cwOuI-sFZqwIxpIc-ikONJldlpV5t8txACoggaUXT8dc_3o4tiiIIEW7vODkzCmGsCfRu1Us3lpbQkWRFEpjwQPMHZ_UNcKL0XP6FjdmccTPEn8xt6PwTb6rDTJzSdVO_YCHAa-91ytdeA1-i2lXf7HoKIoTMQO-BUNnAjF5NLiAW8LPl_7qtaA0/w596-h391/top6.png&quot; width=&quot;596&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;text-align: center;&quot;&gt;Articol disponibil&amp;nbsp;&lt;a href=&quot;https://blog.algomaster.io/p/top-6-api-architecture-styles&quot;&gt;AICI&lt;/a&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/7551370213878279659/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/7551370213878279659?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/7551370213878279659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/7551370213878279659'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2025/11/top-6-api-architecture-styles-repost.html' title='Top 6 API Architecture Styles (repost)'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtXB9cwOuI-sFZqwIxpIc-ikONJldlpV5t8txACoggaUXT8dc_3o4tiiIIEW7vODkzCmGsCfRu1Us3lpbQkWRFEpjwQPMHZ_UNcKL0XP6FjdmccTPEn8xt6PwTb6rDTJzSdVO_YCHAa-91ytdeA1-i2lXf7HoKIoTMQO-BUNnAjF5NLiAW8LPl_7qtaA0/s72-w596-h391-c/top6.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-2948174843403539897</id><published>2025-11-06T10:23:00.025+02:00</published><updated>2025-11-06T10:23:00.145+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="training"/><title type='text'>Training Java performance - Ziua 3 (microservicii)</title><content type='html'>NFR = non functional requirements&lt;br /&gt;&lt;br /&gt;reteaua Google - sa nu depinda de alte cabluri; 6 x 9 availability pt Google Login&lt;br /&gt;&lt;br /&gt;Sistem neperformant:&lt;br /&gt;Throttling: ex. rate limiting&lt;br /&gt;Queuing &lt;br /&gt;Auto-scaling&lt;br /&gt;&lt;br /&gt;Startup time: rau pe Java &amp;gt; mai rau Spring &amp;gt; si mai rau EJB&lt;br /&gt;&lt;br /&gt;Conexiune persistenta Browser-BE: websocket/grpc/http2; pt multe request-uri/zi de la putini useri&lt;br /&gt;&lt;br /&gt;Disintegrator - spargere cod mare in bucati mici&lt;br /&gt;avantaje: decuplare, refolosire, izolare bug, versiune java la zi (CVE, Spring), testabil mai usor (pe bucati), scaleaza independent, deploy independent (faster cycle time)&lt;br /&gt;&lt;br /&gt;Spring AI, Spring MCP&lt;br /&gt;&lt;br /&gt;Integrator: motive sa nu spargi codul&lt;br /&gt;latenta, cuplare stransa, microserviciile sunt scumpe; consistenta datelor (ACID in loc de eventual consistency)&lt;br /&gt;&lt;br /&gt;https://www.infoq.com/news/2023/03/stop-cloud-zombies-qcon/&lt;br /&gt;&lt;br /&gt;enum in Dtos pt REST compatibility: cand modifici/scoti din enum strici; daca faci rename pe un camp din Dto; camp din required in optional;&lt;br /&gt;&lt;br /&gt;test care verifica ca nu ai facut breaking change pe contract;&lt;br /&gt;&lt;br /&gt;subjson in json &quot;metadata&quot; pt alte adaugiri&lt;br /&gt;&lt;br /&gt;Clientii v1 identificati prin header-ele Authorization, X-Api-Key, X-Client-Id, Traceparent (incl timp)&lt;br /&gt;&lt;br /&gt;OpenTelemetry Java Agent- pus in JVM pt tracing (userv)&lt;br /&gt;&lt;br /&gt;swagger-ts-generator&lt;br /&gt;&lt;br /&gt;isaqb.org - certificare arhitect&lt;br /&gt;&lt;br /&gt;Get id repetat - eroare 429 Too Many Requests -&amp;gt; use batch API&lt;br /&gt;&lt;br /&gt;Request multiplexing - astepti sa vina mai multe req, le pui in asteptare (sincron) ~ batching&lt;br /&gt;&lt;br /&gt;Netflix: grpc + graphQL&lt;br /&gt;&lt;br /&gt;CQRS - segregare responsabilitati command / query&lt;br /&gt;&lt;br /&gt;POST/PUT return data?&lt;br /&gt;&lt;br /&gt;Caz RM creare programare in 2 pasi -&amp;gt; ret. patientId -&amp;gt; GET alte patientId -&amp;gt; afli date despre alti pacienti&lt;br /&gt;&lt;br /&gt;202 Accepted (dupa validare request)&lt;br /&gt;200 OK [Retry-after] - prea lung, nu e gata, dar totul e ok, ruleaza async; clientul face polling&lt;br /&gt;200 OK {status: DONE}&lt;br /&gt;302 Redirect - pt rezultate mari&lt;br /&gt;&lt;br /&gt;SAU: serverul creeaza un topic la care clientul se aboneaza&lt;br /&gt;&lt;br /&gt;SAU: clientul primeste un HTTP callback (webhook) pe care sa faca polling&lt;br /&gt;&lt;br /&gt;SAU: websocket&lt;br /&gt;&lt;br /&gt;Agregator - face batching&lt;br /&gt;&lt;br /&gt;Proxy - ruteaza orbeste&lt;br /&gt;API proxy - la intrare in system&lt;br /&gt;Service proxy - la iesire, spre API externe&lt;br /&gt;&lt;br /&gt;Gateway: caching, compresie date, rutare requests, load balancing, service registry, http access log, metrici, tracing, &lt;br /&gt;agrega date din mai multe API-uri == NOK ca implica business logic in Gw&lt;br /&gt;autentifica request-uri (cu ajutorul unui serviciu), fara autorizare&lt;br /&gt;rate limiting&lt;br /&gt;&lt;br /&gt;Connect timeout &amp;lt; Response timeout  -- trebuie setate, altfel infinite&lt;br /&gt;&lt;br /&gt;Lock.tryLock(timeout)&lt;br /&gt;&lt;br /&gt;Eroare 500 + header Retry-After - daca e din cauza unui serviciu extern (nu 500 propriu-zis)&lt;br /&gt;&lt;br /&gt;resilience4j&lt;br /&gt;&lt;br /&gt;health probe: aliveness &amp;amp; readiness (capabil de trafic)&lt;br /&gt;unalive: conexiuni agatate permanent, disc corupt, OOME, deadlock&lt;br /&gt;&lt;br /&gt;LB poate evita o instanta daca e slow/are erori.&lt;br /&gt;&lt;br /&gt;Inbox table = store then process&lt;br /&gt;Outbox table pattern = store and fwd&lt;br /&gt;- pune mesajul in SQL cu un status, apoi luat si trimis extern, actualizat status&lt;br /&gt;&lt;br /&gt;Operatii idempotente = retryable: GET, DELETE, PUT (overwrite)&lt;br /&gt;&lt;br /&gt;POST: idempotent daca la retry trimite acelasi idempotency key (poate fi timestamp la ms); sau serverul sa tina un hash(comanda), salvat intr-un map cu comenzile din ultimele 30 minute -&amp;gt; daca primeste aceeasi comanda va face reject&lt;br /&gt;&lt;br /&gt;PUT cu IK (UUID)&lt;div&gt;&lt;br /&gt;server.tomcat.max-connections&lt;br /&gt;server.tomcat.accept-count&lt;br /&gt;server.tomcat.threads.max&lt;br /&gt;&lt;br /&gt;Bulkhead = apeluri simultane per JVM&lt;br /&gt;Rate limiter = apeluri intr-un interval de timp&lt;br /&gt;Quartz - orchestrare timers prin DB&lt;br /&gt;&lt;br /&gt;Compartimentalizare -&amp;gt; izolare serviciu picat&lt;br /&gt;&lt;br /&gt;Cache - for latency or for data replication &lt;br /&gt;&lt;br /&gt;App de baza are un SLA (99.99) -&amp;gt; e ok sa chemi alt API cu SLA mai mare (99.999)&lt;br /&gt;&lt;br /&gt;Istio: construieste un mic scut in jurul unui serviciu (throttling etc - il face ca un gateway)&lt;br /&gt;&lt;br /&gt;Strategii de deployment: canary (ex. FB release in Argentina), blue/green (gradually transfer traffic), deploy in staging pt testeri si clienti timp de _; &lt;br /&gt;&lt;br /&gt;release notes, feature flags&lt;br /&gt;&lt;br /&gt;shadow deploy=rutezi input din prod si verifici ca da la fel, in paralel cu versiunea veche&lt;br /&gt;&lt;br /&gt;Ex. connection pool starvation:&lt;br /&gt;&lt;br /&gt;@Transactional&lt;br /&gt;method() {&lt;br /&gt;&amp;nbsp; synchronized(b) {&lt;br /&gt;&amp;nbsp; // call a slow api&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Cache miss 99%: e prea mic, a expirat, nu este gasita cheia (lipseste hashCode, equals in clasa cheii)&lt;br /&gt;Teste pe cache!! --&amp;gt; AgencyCacheTest&lt;br /&gt;Cache hit prea mare: key collision? (chei trunchiate, sunt mereu gasite)&lt;br /&gt;&lt;br /&gt;@TimeAspect&lt;br /&gt;@Timed&lt;br /&gt;MeterRegistry - raporteaza metrici&lt;br /&gt;&lt;br /&gt;@Observed&lt;br /&gt;&lt;br /&gt;Monolit (risc: cod complex) -&amp;gt; microservicii (risc: integrarile)&lt;br /&gt;=&amp;gt;&lt;br /&gt;Mockito -&amp;gt; WireMock (care nu reflecta realitatea din prod)&lt;br /&gt;Monolit: multe unit teste; uS: multe teste de integrare&lt;br /&gt;uS: mai multe bug-uri in yaml config decat in cod&lt;br /&gt;&lt;br /&gt;@FeignClient - pt apel rest dintr-un uS la altul&lt;br /&gt;&lt;br /&gt;Jeff Bezos manifesto for externalization (2002)&lt;br /&gt;&lt;br /&gt;ZoomIt- timer (gong)&lt;br /&gt;&lt;br /&gt;Surse:&lt;br /&gt;video: https://www.youtube.com/watch?v=arUOVFUKt6s&lt;br /&gt;drive: https://drive.google.com/open?id=1A2WIOb6tZvkzkHwDEAQSfFCKQAIG4imt&amp;amp;usp=drive_fs&lt;br /&gt;https://victorrentea.ro/slides/&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/2948174843403539897/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/2948174843403539897?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/2948174843403539897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/2948174843403539897'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2025/11/training-java-performance-ziua-3.html' title='Training Java performance - Ziua 3 (microservicii)'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-8713424692547771326</id><published>2025-11-04T10:23:00.001+02:00</published><updated>2025-11-04T10:24:13.319+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jpa"/><category scheme="http://www.blogger.com/atom/ns#" term="training"/><title type='text'>Training Java performance - Ziua 2 (JPA)</title><content type='html'>&lt;p&gt;&amp;nbsp;SOLR/ES/Lucene - full text search&lt;/p&gt;&lt;p&gt;Vector search - next thing&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Brian: paginare N rezultate, apoi N/2 , N/4 ... dar intr-o singura tranzactie&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Query-uri dinamice:&lt;/p&gt;&lt;p&gt;1. concat string-uri: WHERE 1+1&quot; (ca apoi sa poti concatena alte conditii, if criteria)&lt;/p&gt;&lt;p&gt;2. Query DieSL: JpaQuery&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;- Diesel genereaza entitatile (ex. QMaterial)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;3. CriteriaAPI&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Planul de executie uraste &quot;OR&quot;&lt;/p&gt;&lt;p&gt;- face cache la planul construit anterior&lt;/p&gt;&lt;p&gt;- query diferit: alt plan&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Index: ideal e sa ai distributie buna pe date (nu prea multe valori repetitive)&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;AskTom - (Oracle) - intrebari tuning etc&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@Id&lt;/p&gt;&lt;p&gt;@GeneratedValue(strategy = _ )&lt;/p&gt;&lt;p&gt;- SEQUENCE: trebuie creata; la rollback tranzactie nu se poate recupera (da impresia ca e un rand sters in table)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;INCREMENT BY 50: tragi din baza 50 id-uri odata&lt;/span&gt;&lt;/p&gt;&lt;p&gt;- IDENTITY = auto-increment; ceri de fiecare data din baza&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;- PK violation daca inserezi id-uri &#39;cunoscute&#39;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;- UUID - greu de ghicit, poate fi generat de client; dar urat&lt;/p&gt;&lt;p&gt;- TABLE&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@Embedded pe un obiect din entity -&amp;gt; muti anumite attribute din clasa (coloane) pt a-i scurta marimea&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@Entity to Domain Model - vezi notele&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@Transactional pe metoda - nu poti face face try/catch pe query&lt;/p&gt;&lt;p&gt;- interzise tranzactiile manuale&lt;/p&gt;&lt;p&gt;Write behind: JPA amana scrierile pana inainte de commit (flush)- pt a insera/update in batch-uri&lt;/p&gt;&lt;p&gt;em.flush() - grabeste flush, dar nu comite; crapa de la erori&lt;/p&gt;&lt;p&gt;+ un select ar putea grabi flush&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Carte: &quot;Release it!&quot;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Entitate gasita cu find pe o metoda @Transactional:&lt;/p&gt;&lt;p&gt;.set...() face update (auto-save)&lt;/p&gt;&lt;p&gt;alt .set nu face / nu se mai potriveste equals&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;em.detach(obj); // scoate din urmarire&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;em.clear(); // elimina din context toate entitatile (detach la tot), goleste 1st level cache al lui Hibernate&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;flush vs clear:&lt;/p&gt;&lt;p&gt;- flush scrie tot ce avea de scris; util: inainte sa chemi un PL/SQL, Trigger sau native query.&lt;/p&gt;&lt;p&gt;- goleste fara sa scrie nimic&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@DynamicUpdate - modifica coloana din entitate doar daca chiar se modifica&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;1st level cache = transaction-scoped; find se uita in cache&lt;/p&gt;&lt;p&gt;2nd level cache = intre request-uri diferite (optional @Cacheble pe @Entity sau query hint)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;- util: primul select ia din baza, al doilea select identic intr-un TTL=5 min ia din cache&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Persistence context&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@Cache pe entity class&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;em.merge(entity); // update fara auto-save, fara @Transactional, cand construiesti cu new entitatea Venita de la client (nu mai faci find)&lt;/p&gt;&lt;p&gt;Merge = suprascriere entitate veche&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;select parinte, copii si apoi update&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;cascade&lt;/p&gt;&lt;p&gt;- DETACH ~ detaseaza copiii odata cu parintele&lt;/p&gt;&lt;p&gt;- REFRESH ~ git reset&lt;/p&gt;&lt;p&gt;- MERGE - copiii se ins/upd/del&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@Transactional cand doar citesti din BD: lazy init (entitatile-copii ca lista nu sunt dispo pt un framework gen Jackson)&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@OneToMany(cascade = ALL, fetch = EAGER, orphanRemoval = true)&lt;/p&gt;&lt;p&gt;entitate parent.getChildren().remove(1) =&amp;gt; UPDATE copil set parent null =&amp;gt; cu orphanRemoval omoara copiii cu FK = null&lt;/p&gt;&lt;p&gt;( valabil la em.merge )&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Cand un camp nu trebuie sa fie modificat pe un flux (ajuta cu merge side effects):&lt;/p&gt;&lt;p&gt;1) @Column(updatable = false) String createdBy; // eroare daca incerci sa modifici din cod&lt;/p&gt;&lt;p&gt;2) setCreatedBy - ignora/arunca eroare daca e deja setat campul&lt;/p&gt;&lt;p&gt;3) suprascrii cu valoarea care era initial in baza&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Concurenta la modificare entitate:&lt;/p&gt;&lt;p&gt;Optimistic lock: te lasa sa scrii, cand salvezi iti da eroare daca cineva a salvat inaintea ta&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;@Version&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;private Long version; // sau LocalDateTime&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;// la em.merge(entity) se adauga o conditie suplimentara: AND version = 1 (cat era pe entity)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Pessimistic lock: pus lock in baza = intarzie a doua tranzactie pana comite prima&lt;/p&gt;&lt;p&gt;cu row lock: SELECT ... where version=7 FOR UPDATE [NO WAIT - la nivel de rand]&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;- face lock pe randurile returnate de SELECT&lt;/span&gt;&lt;/p&gt;&lt;p&gt;tx2 va astepta pana tx1 comite; = default in postgres/H2&lt;/p&gt;&lt;p&gt;adaugare coloane IN_EDIT_BY, IN_EDIT_SINCE cand materialul incepe sa fie editat de un user (lock pe linia din tabel)&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Nu folosim synchronized in EJB&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Monitorizare &quot;connection acquisition time&quot; = metrici - Grafana, Kibana, New Relic&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@Transactional:&lt;/p&gt;&lt;p&gt;persist, flush nu duc la commitment daca apare exceptie in metoda tranzactata&lt;/p&gt;&lt;p&gt;- orice metoda chemata in thread-ul curent e parte din aceeasi tranzactie&lt;/p&gt;&lt;p&gt;- thread async: NU, si acopera exceptia; pt ca se pierde conexiunea JDBC care avea tranzactia pornita; nu merge nici daca pasezi EntityManager-ul de pe thread-ul gazda&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Metoda @Transactional care cheama alta metoda @Transactional = e aceeasi tranzactie (parinte)&lt;/p&gt;&lt;p&gt;Propagation.REQUIRES_NEW ca sa fie distincta&lt;/p&gt;&lt;p&gt;TxType.REQUIRED = este default&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;throw checked exception intr-o metoda @Transactional nu impiedica commit-ul, doar unchecked (runtime) impiedica (!!!)&lt;/p&gt;&lt;p&gt;=&amp;gt; metoda @Transactional nu se recomanda cu throws! - faci try/catch/throw RuntimeException&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;@Transactional cu Propagation.REQUIRES_NEW pe o metoda-copil din acelasi serviciu = ca si cum nu are @Transactional&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;! nu se da API-call din @Transactional&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Deadlock:&lt;/p&gt;&lt;p&gt;synchronized(x) din java + SELECT FOR UPDATE id=7 in parallel cu&amp;nbsp;&lt;/p&gt;&lt;p&gt;SELECT FOR UPDATE id=7 + synchronized(x) din java&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;View materializat pe disc si actualizat periodic;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Rainbow brackets- plugin IntelliJ&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;DbUnit&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Tuning tips:&lt;/p&gt;&lt;p&gt;- EXISTS (SELECT...) in loc de SELECT COUNT() sau id=(SELECT id...)&lt;/p&gt;&lt;p&gt;- Evita SELECT DISTINCT pe mai multe coloane = multe comparatii&lt;/p&gt;&lt;p&gt;- WHERE in loc de HAVING&lt;/p&gt;&lt;p&gt;- INNER JOIN ON &amp;lt;cond&amp;gt; in loc de WHERE&amp;lt;cond&amp;gt;&lt;/p&gt;&lt;p&gt;- LIMIT&lt;/p&gt;&lt;p&gt;- UNION ALL nu UNION (=DISTINCT)&lt;/p&gt;&lt;p&gt;- A UNION B in loc de WHERE... OR..&lt;/p&gt;&lt;p&gt;- GROUP BY in loc de OVER PARTITION BY&lt;/p&gt;&lt;p&gt;- tabele auxiliare&lt;/p&gt;&lt;p&gt;- IN si = in loc de != si &amp;lt;&amp;gt; si NOT IN&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/8713424692547771326/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/8713424692547771326?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/8713424692547771326'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/8713424692547771326'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2025/11/training-java-performance-ziua-1-jpa.html' title='Training Java performance - Ziua 2 (JPA)'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-6777018530180876098</id><published>2025-10-25T11:05:00.000+03:00</published><updated>2025-10-25T11:05:06.628+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jpa"/><category scheme="http://www.blogger.com/atom/ns#" term="training"/><title type='text'>Training Java performance - Ziua 1 (JPA)</title><content type='html'>Hibernate - performanta down, magie&lt;br /&gt;&lt;br /&gt;Orice @Entity trebuie sa aiba @Id (Integer, Long sau String - cheie naturala, ideal)&lt;br /&gt;&lt;br /&gt;@OneToMany(mappedBy=&quot;numele companiei in cealalta clasa&quot;)&lt;br /&gt;&lt;br /&gt;@Inheritance(strategy=TABLE_PER_CLASS, SINGLE_TABLE, JOINED)&lt;br /&gt;&lt;br /&gt;Exemplu: 2 tabele Pisica/miaunat &amp;amp; Caine/latrat&lt;br /&gt;SINGLE_TABLE: simplu, unele coloane sunt degeaba, nu poti pune NOT NULL pe coloanele specific; se foloseste daca dif dintre clase sunt minime; @DiscriminatorValue &amp;amp; @DiscriminatorColumn&lt;br /&gt;TABLE_PER_CLASS (2 tabele): nu poti face select pe Animal; faci UNION (scump)&lt;br /&gt;JOINED (3 tabele): join la orice query (ca sa incluzi si Animal) ---&amp;gt; nu se foloseste in practica&lt;br /&gt;&lt;br /&gt;PARTITION BY - sparge datele in datafile separate (dupa an sau luna de obicei);&lt;br /&gt;se face dupa cum vei face cautarea&lt;br /&gt;daca cauti dupa altceva, merge rau&lt;br /&gt;- nu ocupa spatiu in plus, precum indecsii&lt;br /&gt;&lt;br /&gt;INDEX e ceva complementar (~ hashMap); prea multi afecteaza performanta&lt;br /&gt;&lt;br /&gt;Employee si EmployeeDetails - pot avea shared primary key (FK al lui Details sa fie si PK)&lt;br /&gt;- datele masive pot fi tinute in alt loc daca nu sunt frecventate des&lt;br /&gt;&lt;br /&gt;Evitare referinte reciproce Employee si EmployeeDetails - depinde de caz - daca selectezi details si vrei si employee-ul initial, pui&lt;br /&gt;altfel @OneToOne pt details, in Employee; daca modifici unul poti uita de celalalt&lt;br /&gt;&lt;br /&gt;@ManyToMany&lt;br /&gt;@JoinTable&lt;br /&gt;&lt;br /&gt;@Enumerated - cand campul este un enum&lt;br /&gt;&lt;br /&gt;ProjectType { LIB(&quot;L&quot;) } - in db ajunge &quot;L&quot;, nu 0 sau LIB&lt;br /&gt;&lt;br /&gt;XML/JSON - salvat ca CLOB (character large object)&lt;br /&gt;- editare xml din clob risca stricaciuni&lt;br /&gt;- poti selecta bucati din XML cu instr speciale Oracle&lt;br /&gt;- poate fi prea mare, ocupa discul -- OOME (out of memory error)&lt;br /&gt;Trebuie citit/scris in BD via fisier (cu InputStream/OutputStream)&lt;br /&gt;Best practice: nu incarcat in BD, ci arhivat si salvat pe disc (ftp sau pe acelasi disc), cu referinta in BD;&lt;br /&gt;&lt;br /&gt;like pe coloana CLOB: dureaza f mult pt ca CLOB nu e indexabil&lt;br /&gt;&lt;br /&gt;https://github.com/victorrentea/jpa/tree/systematic25&lt;br /&gt;run StartDatabase, JpaApplication&lt;br /&gt;JpaPlayground - cu Lombok&lt;br /&gt;fol. EntityManager in loc de Repository (EE)&lt;br /&gt;em.persist(new Teacher());&lt;br /&gt;&lt;br /&gt;@Transactional in Spring &amp;amp; Jakarta&lt;div&gt;&lt;br /&gt;Creare 2 entitati inrudite: trebuie legate both-way - daca uiti?&lt;br /&gt;Relatiile bidirectionale sunt greu de intretinut.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Design mai bun: getter sa fie unmodifiable - blochezi get/add; faci o metoda de add in care legi dublu;&lt;br /&gt;in cealalta clasa setter-ul e de tip default (nivel de package) - sa nu poti accesa set din afara pachetului&lt;br /&gt;&lt;br /&gt;@OneToOne (cascade = CascadeType.ALL)&lt;br /&gt;- TeacherDetails nu are ref la Teacher&lt;br /&gt;&lt;br /&gt;CascadeType.ALL intre parinte si copiii exclusivi ai lui (creare, stergere automata)&lt;br /&gt;&lt;br /&gt;campuri List vs Set&lt;br /&gt;- ordonare cu @OrderBy(&quot;type ASC, value desc&quot;) pt List, sortare din query JPA&lt;br /&gt;@OrderColumn(name = &quot;INDEX&quot;)  - salveaza in DB ordinea manual setata de user in UI&lt;br /&gt;altfel ordinea nu e garantata&lt;br /&gt;&lt;br /&gt;hashCode/equals pe:&lt;br /&gt;- id?&lt;br /&gt;- campuri?&lt;br /&gt;- id + campuri? - situatie campuri identice si unul are id=null; ambele circula&lt;br /&gt;=&amp;gt; nu impl hashCode/equals pe entitati, facem propriul equals; mai tricky la HashSet&lt;br /&gt;&lt;br /&gt;@NotNull - previne sa inserezi prin java (Jakarta validation la persist)&lt;br /&gt;nullable = false - previne sa inserezi &quot;pe sub mana&quot; -- folosit in POC, nu in proiecte mature (nu creezi DB din java); pot ramane out of sync&lt;br /&gt;&lt;br /&gt;@AssertTrue pe metoda ~ @NotNull cand validarea e doar pe campul unui copil&lt;br /&gt;&lt;br /&gt;@OneToMany poate fi def unidirectional, cu @JoinColumn(name = &quot;loanerId&quot;)&lt;br /&gt;&lt;br /&gt;constructor in entity:&lt;br /&gt;protected cu constructor gol - ca sa nu planga Hibernate&lt;br /&gt;public cu parametri - este cel relevant&lt;br /&gt;&lt;br /&gt;getter/setters: nu neaparat necesare, Hibernate foloseste reflectie pt a popula campurile&lt;br /&gt;&lt;br /&gt;--&amp;gt; BalanceEntityListener ??&lt;br /&gt;--&amp;gt; @Transient in BalanceEntity?&lt;br /&gt;&lt;br /&gt;http://annas-archive.org/ -- book &quot;sql performance explained&quot;&lt;br /&gt;&lt;br /&gt;URL BD: jdbc:mssql ----&amp;gt; jdbc:p6spy:mssql , cu username, parola, dependency la p6spy&lt;br /&gt;-&amp;gt; alternativa mai buna la show-sql=true&lt;br /&gt;&lt;br /&gt;@OneToMany&lt;br /&gt;N+1 queries = 1 pt parinte, N pt copii (loading lazy info)&lt;br /&gt;fetch = FetchType.LAZY by default (doar pe colectii); la fel si pt @ManyToMany&lt;br /&gt;EAGER daca eviti N+1 queries -&amp;gt; incarca tot dinainte - a nu se folosi aproape niciodata&lt;br /&gt;@BatchSize(size=20) - este Hibernate specific - incarca entitati inrudite in calupuri&lt;br /&gt;&lt;br /&gt;Ia toate info odata (pt @ManyToOne)&lt;br /&gt;select p from Person p&lt;br /&gt;LEFT JOIN FETCH p.children&lt;br /&gt;LEFT JOIN FETCH p.country ---- nu este colectie&lt;br /&gt;&lt;br /&gt;@ManyToOne - si asta aduce N+1 queries&lt;br /&gt;&lt;br /&gt;fetch = EAGER by default&lt;br /&gt;&lt;br /&gt;entityManager.createQuery(&quot;SELECT pFROM errorProne&quot;); // app porneste, vezi bug-ul tarziu&lt;br /&gt;@NamedQuery (name = &quot;&quot;, query = &quot;&quot;) ; // detecteaza devreme, nu compileaza&lt;br /&gt;&lt;br /&gt;Sub-select: select doar anumite campuri&lt;br /&gt;@Subselect(&quot;query...&quot;)&lt;br /&gt;public record....  - in spring&lt;br /&gt;&lt;br /&gt;@NamedNativeQuery - pt EE&lt;br /&gt;(query= &quot;&quot;, resultClass = , resultSetMapping = )&lt;br /&gt;- cu COALESCE&lt;br /&gt;- to VIEW ----&amp;gt; declari un nou @Entity in Java cu @Table(&quot;VIEW_NAME&quot;)&lt;br /&gt;&lt;br /&gt;Teste pe query-uri&lt;br /&gt;&lt;br /&gt;FetchGraph - sa incarci partial entitati&lt;br /&gt;&lt;br /&gt;Paginare: ORDER BY, LIMIT __, OFFSET __&lt;br /&gt;- in BD, in Java sau pe client&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Problema: daca se insereaza/sterge in timpul frunzaririi (cached)&lt;br /&gt;problema: el face select tot dar iti da numai ce ceri&lt;br /&gt;Nu poti pagina in DB daca faci FETCH, pt ca se strica cardinalitatea&lt;br /&gt;pe doua directii: iese produs cartezian&lt;br /&gt;&lt;br /&gt;LEFT JOIN FETCH ALL PROPERTIES - ia in cascada&lt;br /&gt;&lt;br /&gt;@ManyToOne private Country country; ==&amp;gt; private Long countryId; // pastreaza FK&lt;br /&gt;-&amp;gt; pune numeric/string ref in loc de object reference&lt;br /&gt;&lt;br /&gt;entityManager&lt;br /&gt;.createNamedQuery(..)&lt;br /&gt;.setFirstResult(0) // offset&lt;br /&gt;.setMaxResults(2) // limit&lt;br /&gt;.getResultList();&lt;br /&gt;&lt;br /&gt;@ElementCollection -- entitati-copii fara id&lt;br /&gt;&lt;br /&gt;Cross join: N x N x N results&lt;br /&gt;&lt;br /&gt;Intrerupere query in timpul rularii - exista api de jdbc &quot;abort&quot; - nu din JPA, doar JDBC (statement.cancel())&lt;br /&gt;sau: timeout in JPA&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/6777018530180876098/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/6777018530180876098?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/6777018530180876098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/6777018530180876098'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2025/10/training-java-performance-ziua-1-jpa.html' title='Training Java performance - Ziua 1 (JPA)'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-2917247927362888492</id><published>2025-09-13T18:23:00.006+03:00</published><updated>2025-09-13T18:26:00.456+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="tests"/><title type='text'>Jupiter Parameterized Test</title><content type='html'>&lt;div style=&quot;background-color: #1e1f22; color: #bcbec4;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 10,5pt;&quot;&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;io.grpc.Status;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;io.grpc.StatusRuntimeException;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.junit.jupiter.api.Assertions;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.junit.jupiter.params.&lt;span style=&quot;color: #b3ae60;&quot;&gt;ParameterizedTest&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.junit.jupiter.params.provider.Arguments;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.junit.jupiter.params.provider.&lt;span style=&quot;color: #b3ae60;&quot;&gt;MethodSource&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;java.util.stream.Stream;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;ServerStreamingInputValidationTest &lt;span style=&quot;color: #cf8e6d;&quot;&gt;extends &lt;/span&gt;AbstractTest {&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@ParameterizedTest&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    @MethodSource&lt;/span&gt;(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;testData&quot;&lt;/span&gt;)&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;testBlockingInputValidation&lt;/span&gt;(&lt;b&gt;WithdrawRequest request, Status.Code code&lt;/b&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;var &lt;/span&gt;ex = Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertThrows&lt;/span&gt;(StatusRuntimeException.&lt;span style=&quot;color: #cf8e6d;&quot;&gt;class&lt;/span&gt;, () -&amp;gt; &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;blockingStub&lt;/span&gt;.withdraw(&lt;span style=&quot;color: #c77dbb;&quot;&gt;request&lt;/span&gt;).hasNext());&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertEquals&lt;/span&gt;(code, ex.getStatus().getCode());&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@ParameterizedTest&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    @MethodSource&lt;/span&gt;(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;testData&quot;&lt;/span&gt;)&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;testAsyncInputValidation&lt;/span&gt;(&lt;b&gt;WithdrawRequest request, Status.Code code&lt;/b&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;var &lt;/span&gt;observer = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ResponseObserver&amp;lt;Money&amp;gt;();&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;asyncStub&lt;/span&gt;.withdraw(request, observer);&lt;br /&gt;        observer.await();&lt;br /&gt;&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertTrue&lt;/span&gt;(observer.getItems().isEmpty());&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertNotNull&lt;/span&gt;(observer.getThrowable());&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertEquals&lt;/span&gt;(code, ((StatusRuntimeException) observer.getThrowable()).getStatus().getCode());&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private &lt;/span&gt;Stream&amp;lt;Arguments&amp;gt; &lt;span style=&quot;color: #56a8f5;&quot;&gt;&lt;b&gt;testData&lt;/b&gt;&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;Stream.&lt;span style=&quot;font-style: italic;&quot;&gt;of&lt;/span&gt;(&lt;br /&gt;                &lt;span style=&quot;color: #7a7e85;&quot;&gt;// input, expectation&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;                &lt;/span&gt;Arguments.&lt;span style=&quot;font-style: italic;&quot;&gt;of&lt;/span&gt;(WithdrawRequest.&lt;span style=&quot;font-style: italic;&quot;&gt;newBuilder&lt;/span&gt;().setAccountNumber(&lt;span style=&quot;color: #2aacb8;&quot;&gt;11&lt;/span&gt;).setAmount(&lt;span style=&quot;color: #2aacb8;&quot;&gt;10&lt;/span&gt;).build(), Status.Code.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;INVALID_ARGUMENT&lt;/span&gt;),&lt;br /&gt;                Arguments.&lt;span style=&quot;font-style: italic;&quot;&gt;of&lt;/span&gt;(WithdrawRequest.&lt;span style=&quot;font-style: italic;&quot;&gt;newBuilder&lt;/span&gt;().setAccountNumber(&lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;).setAmount(&lt;span style=&quot;color: #2aacb8;&quot;&gt;17&lt;/span&gt;).build(), Status.Code.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;INVALID_ARGUMENT&lt;/span&gt;),&lt;br /&gt;                Arguments.&lt;span style=&quot;font-style: italic;&quot;&gt;of&lt;/span&gt;(WithdrawRequest.&lt;span style=&quot;font-style: italic;&quot;&gt;newBuilder&lt;/span&gt;().setAccountNumber(&lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;).setAmount(&lt;span style=&quot;color: #2aacb8;&quot;&gt;120&lt;/span&gt;).build(), Status.Code.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;FAILED_PRECONDITION&lt;/span&gt;)&lt;br /&gt;        );&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/2917247927362888492/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/2917247927362888492?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/2917247927362888492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/2917247927362888492'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2025/09/jupiter-parameterized-test.html' title='Jupiter Parameterized Test'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-2227983401240545590</id><published>2025-08-07T11:19:00.002+03:00</published><updated>2025-08-07T11:19:10.353+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="windows"/><title type='text'>Kill process in Windows &amp; Linux</title><content type='html'>&lt;p&gt;&lt;b style=&quot;background-color: #ead1dc;&quot;&gt;Windows:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;gt; netstat -ano | findstr :8080&lt;/p&gt;&lt;p&gt;&amp;gt; taskkill PID &amp;lt;pid&amp;gt; /F&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b style=&quot;background-color: #ead1dc;&quot;&gt;Linux:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;gt; sudo lsof -i 8080&lt;/p&gt;&lt;p&gt;&amp;gt; sudo kill -9 &amp;lt;pid&amp;gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/2227983401240545590/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/2227983401240545590?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/2227983401240545590'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/2227983401240545590'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2025/08/kill-process-in-windows-linux.html' title='Kill process in Windows &amp; Linux'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-4987725093377789637</id><published>2025-08-02T14:12:00.005+03:00</published><updated>2025-08-02T14:14:15.582+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gRPC"/><category scheme="http://www.blogger.com/atom/ns#" term="json"/><title type='text'>Proto vs Json performance test</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style=&quot;background-color: #1e1f22;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace;&quot;&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;PerformanceTest {&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private static final &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;Logger &lt;/span&gt;&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;LOGGER &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;= LoggerFactory.&lt;/span&gt;&lt;span style=&quot;color: #bcbec4; font-style: italic;&quot;&gt;getLogger&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(PerformanceTest.&lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private static final &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;ObjectMapper &lt;/span&gt;&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;MAPPER &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;ObjectMapper();&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public static void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(String[] args) &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;throws &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;Exception {&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;protoPerson = Person.&lt;/span&gt;&lt;span style=&quot;color: #bcbec4; font-style: italic;&quot;&gt;newBuilder&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;()&lt;br /&gt;                .setLastName(&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;T&quot;&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;)&lt;br /&gt;                .setAge(&lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;)&lt;br /&gt;                .setEmail(&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;t@email.com&quot;&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;)&lt;br /&gt;                .setEmployed(&lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;)&lt;br /&gt;                .setSalary(&lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;123004.5&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;)&lt;br /&gt;                .setBankAccountNumber(&lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;38495959093040944L&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;)&lt;br /&gt;                .setBalance(-&lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;)&lt;br /&gt;                .build();&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;LOGGER&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;.info(&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;how many bytes protoPerson has? {}&quot;&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, protoPerson.toByteArray().&lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;// 41&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;jsonPerson = &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;JsonPerson(&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;T&quot;&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;t@email.com&quot;&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;123004.5&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;38495959093040944L&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, -&lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;);&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;bytes = &lt;/span&gt;&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;MAPPER&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;.writeValueAsBytes(jsonPerson);&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;LOGGER&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;.info(&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;how many bytes jsonPerson has? {}&quot;&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, bytes.&lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;// 130 = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;3x more!&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;for &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;i=&lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;; i&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;; i++) { &lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;// first run to be ignored (warmup JVM)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #bcbec4; font-style: italic;&quot;&gt;runTest&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;json&quot;&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, () -&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #bcbec4; font-style: italic;&quot;&gt;json&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;jsonPerson&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;));&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;color: #bcbec4; font-style: italic;&quot;&gt;runTest&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;proto&quot;&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, () -&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #bcbec4; font-style: italic;&quot;&gt;proto&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;protoPerson&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;));  &lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;// &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;7x faster!&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;}&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private static void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;runTest&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(String testName, Runnable runnable) {&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;start = System.&lt;/span&gt;&lt;span style=&quot;color: #bcbec4; font-style: italic;&quot;&gt;currentTimeMillis&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;();&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;for &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;i=&lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;; i&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;5_000_000&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;; i++) {&lt;br /&gt;            runnable.run();&lt;br /&gt;        }&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;end = System.&lt;/span&gt;&lt;span style=&quot;color: #bcbec4; font-style: italic;&quot;&gt;currentTimeMillis&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;();&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;LOGGER&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;.info(&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;time taken for {} = {} ms&quot;&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;, testName, (end - start));&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private static void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;proto&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(Person person)  {&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;try &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;{&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;bytes = person.toByteArray();&lt;br /&gt;            Person.&lt;/span&gt;&lt;span style=&quot;color: #bcbec4; font-style: italic;&quot;&gt;parseFrom&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(bytes);&lt;br /&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;catch &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(InvalidProtocolBufferException e) {&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;throw new &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;RuntimeException(e);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private static void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;json&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(JsonPerson person) {&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;try &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;{&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;var &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;bytes = &lt;/span&gt;&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;MAPPER&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;.writeValueAsBytes(person);&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;MAPPER&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;.readValue(bytes, JsonPerson.&lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;);&lt;br /&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;catch &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;(IOException e) {&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;throw new &lt;/span&gt;&lt;span style=&quot;color: #bcbec4;&quot;&gt;RuntimeException(e);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/4987725093377789637/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/4987725093377789637?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/4987725093377789637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/4987725093377789637'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2025/08/proto-vs-json-performance-test.html' title='Proto vs Json performance test'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-7120976461045230077</id><published>2024-12-04T11:47:00.002+02:00</published><updated>2024-12-06T18:46:04.624+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Implementarea unui Rate Limiter </title><content type='html'>&lt;div style=&quot;background-color: #1e1f22; color: #bcbec4;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 10,5pt;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;font-family: &#39;JetBrains Mono&#39;,monospace; font-size: 10,5pt;&quot;&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;RateLimiter {&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private static final int &lt;/span&gt;&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;ONE_SECOND &lt;/span&gt;= &lt;span style=&quot;color: #2aacb8;&quot;&gt;1000&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private final &lt;/span&gt;Map&amp;lt;String, List&amp;lt;Long&amp;gt;&amp;gt; &lt;span style=&quot;color: #c77dbb;&quot;&gt;requests&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private boolean &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;enabled &lt;/span&gt;= &lt;span style=&quot;color: #cf8e6d;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private int &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;requestsPerSecond&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;RateLimiter&lt;/span&gt;(Environment environment) {&lt;br /&gt;        &lt;span style=&quot;color: #c77dbb;&quot;&gt;requests &lt;/span&gt;= &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;HashMap&amp;lt;&amp;gt;();&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(environment.getProperty(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;enable.rate.limiter&quot;&lt;/span&gt;) != &lt;span style=&quot;color: #cf8e6d;&quot;&gt;null&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;enabled &lt;/span&gt;= Boolean.&lt;span style=&quot;font-style: italic;&quot;&gt;parseBoolean&lt;/span&gt;(environment.getProperty(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;enable.rate.limiter&quot;&lt;/span&gt;));&lt;br /&gt;        }&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;enabled&lt;/span&gt;) {&lt;br /&gt;            String property = environment.getProperty(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;max.requests.per.user.per.second&quot;&lt;/span&gt;);&lt;br /&gt;            Assert.&lt;span style=&quot;font-style: italic;&quot;&gt;notNull&lt;/span&gt;(property, &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Max requests per second not defined!&quot;&lt;/span&gt;);&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;requestsPerSecond &lt;/span&gt;= Integer.&lt;span style=&quot;font-style: italic;&quot;&gt;parseInt&lt;/span&gt;(property);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public boolean &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;allows&lt;/span&gt;(String ipAddress) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(!&lt;span style=&quot;color: #c77dbb;&quot;&gt;enabled&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return true&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(!&lt;span style=&quot;color: #c77dbb;&quot;&gt;requests&lt;/span&gt;.containsKey(ipAddress)) {&lt;br /&gt;            &lt;span style=&quot;color: #c77dbb;&quot;&gt;requests&lt;/span&gt;.put(ipAddress, &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        Long now = System.&lt;span style=&quot;font-style: italic;&quot;&gt;currentTimeMillis&lt;/span&gt;();&lt;br /&gt;        cleanup(ipAddress, now);&lt;br /&gt;        &lt;span style=&quot;color: #c77dbb;&quot;&gt;requests&lt;/span&gt;.get(ipAddress).add(now);&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;requests&lt;/span&gt;.get(ipAddress).size() &amp;lt;= &lt;span style=&quot;color: #c77dbb;&quot;&gt;requestsPerSecond&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;cleanup&lt;/span&gt;(String ipAddress, Long now) {&lt;br /&gt;        List&amp;lt;Long&amp;gt; markedForDeletion = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;for &lt;/span&gt;(Long timestamp : &lt;span style=&quot;color: #c77dbb;&quot;&gt;requests&lt;/span&gt;.get(ipAddress)) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(now - timestamp &amp;gt; &lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;ONE_SECOND&lt;/span&gt;) {&lt;br /&gt;                markedForDeletion.add(timestamp);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        &lt;span style=&quot;color: #c77dbb;&quot;&gt;requests&lt;/span&gt;.get(ipAddress).removeAll(markedForDeletion);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/7120976461045230077/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/7120976461045230077?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/7120976461045230077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/7120976461045230077'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/12/implementarea-unui-rate-limiter.html' title='Implementarea unui Rate Limiter '/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-3094735079854395161</id><published>2024-11-20T14:22:00.003+02:00</published><updated>2025-10-31T12:13:37.704+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interviu"/><category scheme="http://www.blogger.com/atom/ns#" term="work"/><title type='text'>Din interviurile anului 2024 si o experienta de munca mai putin fericita</title><content type='html'>&lt;p&gt;--- Experienta &lt;b&gt;NTT Data&lt;/b&gt; ---&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;M-a abordat pe LinkedIn o doamna draguta din Brasov, foarte vorbareata si dezghetata. Nu imi doream neaparat sa lucrez pentru o companie de consultanta, dar cumva m-a convins ca sediul era mai aproape de casa (si mare avantaj ca nu era lipit de Pipera), dar si ca aveau sedii in mai multe orase din tara, unde as fi putut oricand sa vin sa lucrez, chiar si in Serbia, unde aveau &lt;i&gt;piscina&lt;/i&gt;. Am terminat interviul tehnic, am fost evaluata, urma sa fiu incadrata intr-unul din proiectele lor, dar doamna draguta mai avea nevoie de cateva detalii (era in plina activitate intelectuala, ma suna inopinat, se vedea ca muncea din greu sa faca lucrurile sa mearga pentru mine). Mi-a trimis o grila de completat cu informatii ceva mai mult decat se gaseau in CV, cu mentiunea ca trebuie AZI, cat mai REPEDE, NEAPARAT. Mi-am rupt din timp ca sa scriu cat mai multe detalii de care imi aduceam aminte, sa fie totul la timp, sa avem sansa la discutie cu clientul. Apoi? &lt;span style=&quot;font-size: medium;&quot;&gt;GHOSTING&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Morala: ???&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;--- Experienta &lt;b&gt;Spirent&lt;/b&gt; ---&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Spirent a poposit&amp;nbsp;&lt;span style=&quot;text-align: justify;&quot;&gt;in casuta mea postala de pe&lt;/span&gt;&amp;nbsp;LinkedIn printr-o angajata a TechTalent. Planul era ca Spirent nu angajeaza oamenii direct asa, ci ca ii trece printr-un an de proba la TechTalent, cu aceleasi beneficii si conditii. Dupa discutia de la telefon cu HR, primesc un test pe email - o &lt;a href=&quot;https://github.com/voulpit/spirent&quot;&gt;implementare&lt;/a&gt;. Accept cu bucurie, fiind un mod diferit de a desfasura un interviu, fara presiunea de a fi fata in fata si de a da raspunsurile rapid. Am stabilit ca termen o saptamana. Am lucrat in ritmul meu, dar vream sa mai cer o zi de gratie. HR-ul m-a zorit ca trebuie azi, ca sunt si altii, ca altii au trimis deja in doua zile. Incerc sa termin cat mai repede si sa trimit tema, ca sa raman in grafice. In cele din urma trimit repede si astept&amp;nbsp; programarea urmatorului interviu, si astept. Mi se comunica ca pozitia respectiva a fost inchisa, ei gasind intre timp pe cineva, &lt;i&gt;dar&lt;/i&gt; mai exista o pozitie asemanatoare, pentru care se cere acelasi test, cu inca o cerinta adaugata ( come on, inca putin, esti practic deja acolo ) - dezvoltarea unui plugin de Eclipse. Nu mai facusem asta inainte, ma gandeam poate sa invat, dar ca cineva care lucreaza in IntelliJ lasand de mult in urma Eclipse, mi s-a parut a fi ca o intoarcere in timp. Si aici m-am oprit.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Morala: fusesem un backup de la inceput, ei cautau pe cineva care dezvolta plugin-uri Eclipse.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;--- Experienta &lt;b&gt;Thales&lt;/b&gt; ---&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Thales a poposit in casuta mea postala de pe LinkedIn propunand un rol in industria aeriana cu ultimele tehnologii de Cloud. Cand i-am intrebat daca este o problema ca n-am mai lucrat cu unele dintre ele pana acum, mi s-a raspuns: nicio problema. Foarte bine, am acceptat un scurt apel telefonic cu un HR, i-am trimis CV-ul si am fost de acord sa merg mai departe cu interviul tehnic. A doua zi, mi se comunica faptul ca pozitia a fost inchisa, &lt;i&gt;dar&lt;/i&gt; exista o pozitie similara pentru care as putea fi potrivita si primesc un JD pe email. M-am holbat de cateva ori si am cerut un alt JD mai detaliat. HR-ul mi-a transmis imediat varianta actualizata (o avea la indemana), dar nici de data asta n-am putut sa ma lamuresc: ce tehnologii sunt folosite? Ca sa ma lamuresc pe deplin, accept un interviu tehnic. La interviu au loc cateva prezentari, despre Thales si despre divizie, dupa care managerul vrea sa treaca la intrebarile pentru mine. Il opresc sa intreb cate ceva despre ce ma apasa, tehnologiile folosite. &lt;i&gt;Plain Java, nimic special. Spring Framework, dar nu Boot.&lt;/i&gt; Aflu ca proiectul are si o componenta importanta de UI, dar managerul nu mentioneaza cu ce este realizata. Intreb explicit: &lt;i&gt;ce tehnologii folositi pentru partea de UI&lt;/i&gt;? Raspunsul, atat de mult evitat, este:&amp;nbsp;&lt;span style=&quot;font-size: medium;&quot;&gt;JAVA SWING&lt;/span&gt;. Ok, suntem deja in interviu, hai sa-l terminam. Inca o intrebare, &lt;i&gt;ce baza de date folositi&lt;/i&gt;? Trebuia sa ii scot informatiile cu clestele din gura. &lt;i&gt;SQL, nimic special&lt;/i&gt;. Vag. Trecem la intrebarile pentru mine, cate ceva despre biografia mea, cate ceva despre comportamentul meu ipotetic. Managerul are grija de cateva ori sa ma tachineze cu America: oare nu imi pare rau ca n-am ramas acolo? Oare ce as fi facut acum? Dar oare care e cea mai mare realizare a carierei mele? Dar oare unde vreau sa ajung cu programarea, ar avea sens sa programez cot la cot cu proaspat absolventi chiar si la 50 ani? Si astfel de intrebari care ii framantau mult in universul lor inchis :-) ne luam la revedere si sa aiba succes cu Java Swing.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Morala: m-au atras cu o pozitie smechera ca sa aiba candidati la o pozitie neatragatoare. Au mintit prin omisiune in JD, au continuat sa ascunda si la interviu lucruri importante. Au lasat impresia de pierde-vara putin frustrati, dar in cautare de seniori seriosi care sa puna lucrurile pe roate. N-am idee ce se intampla in proiectul ala, dar Thales nu imi mai suna la fel de bine ca inainte. Iar faptul ca lucreaza cu francezi... nu suna incurajator.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;--- &lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Experienta reala de munca&lt;/span&gt;&lt;/b&gt; @&amp;nbsp;&lt;b&gt;SII / Allianz-Trade&lt;/b&gt;&amp;nbsp;---&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Una dintre fetele de la compania de fete si femei SII m-a abordat pe LinkedIn cu o pozitie pentru clientul lor, Allianz-Trade (fostul Euler Hermes). Nu am luat anuntul foarte in serios si am tratat oportunitatea ca pe un interviu de proba, adica de incalzire. La interviu, am cunoscut TL-ul de la Allianz care mi-a pus cateva intrebari scolaresti despre Java (el cauta un senior), la care am raspuns mai mult sau mai putin bine (nici el nu stia sigur daca e bine). La al doilea interviu, intra viitorul manager de la SII, un pusti care era pe langa cu subiectul, impreuna cu managerul de la Allianz, fara camera pornita, care a inceput sa turuie despre business. Chiar explica pe inteles si eram uimita de generozitatea sa, dar si un pic plictisita, nu ma interesa cata vreme interviul era de proba. Ca sa fiu draguta, m-am aratat entuziasmata la final. Cred ca asta mi-a adus, surprinzator, oferta. La momentul ofertei nu mai tineam bine minte ce presupunea jobul, dar sigur nu presupunea dezvoltare, ceea ce era regretabil. Totusi, fiind singura oferta pe masa si cu salariu bun, am acceptat.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Nu mi-a placut nimic de la inceput pana la sfarsit. La SII totul era fake si nu intelegeam ce rost are SII cand aveam sa lucrez 100% la Allianz. Pe masura ce treceau zilele si saptamanile, primeam mesaje din senin pe Whatsapp in care diferite fete din SII ma intrebau ce mai faci, cum esti, &lt;i&gt;cum esti tu&amp;nbsp;pe proiect. &lt;/i&gt;&quot;Pe proiect&quot; este efectiv sintagma lor preferata la care am devenit, intre timp, alergica.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;La Allianz nu am avut nimic de lucru timp de aproape 2 luni. Era si perioada de concedii in care sefii francezi plecau cu saptamanile si lunile si nu exista volum de munca. Intr-adevar, proiectul nu presupunea dezvoltare, aia se facea in Franta. La noi se trimiteau bug-urile si se faceau configurarile, in mare parte manuale. O mai dadeau ei ca ar trebui sa scriem si noi cod, dar nu aveai ce sa scrii mai mult decat niste utilitare care sa mai reduca putin din munca manuala.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Initial m-au plasat intr-o echipa in care aveam &quot;sa invat&quot;. Cumva, colegii mei aveau de lucru (doar eu nu) si tot ce puteam sa fac e sa le cer sa ne uitam impreuna din cand in cand. In zilele cand lucram de acasa acest lucru era mai incomod, asa ca bagam mainile in buzunar cand nu existau task-uri care mi se adresau direct si faceam altceva. Ulterior, am inceput sa fac acelasi lucru si la birou, unde era extrem de plictisitor. Citeam articole pe Medium, stirile, sau scriam scripturi care nu foloseau la nimic. Nu a existat training, nu au existat tichete in afara de: &lt;i&gt;file reupload&lt;/i&gt; (muuuulte, banale si plictisitoare, terminate rapid) sau &lt;i&gt;endorsement config&lt;/i&gt;&amp;nbsp;(cateva, dar nedemne pentru un senior). La file reupload, faceam copy-paste si executam cateva comenzi de Git, iar la endorsement config faceam un copy paste mai generos, modificam cateva campuri cu ceva mai multa atentie si comparam cu alte fisiere de config in vederea consistentei. Apoi aceleasi comenzi de git. Chiar daca ma bucuram mult sa fac ceva mai &lt;i&gt;exciting&lt;/i&gt;&amp;nbsp;decat file reupload, acele tichete erau putine. Iar alte tipuri de tichete, mai complexe, reveneau colegilor. Unii dintre ei (tot consultanti SII) uneori imi promiteau ca o sa lucram impreuna, dar lucrau singuri. Altii ma amanau. In teorie, oricine era disponibil pentru intrebari, dar in practica deranjam.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;La doua luni de la angajare am fost pusa in echipa in care fusesem destinata de la inceput. A inceput sa ploua cu bug-uri, m-am speriat. Am cerut ajutor. Am rezolvat cum am putut. Am gresit. Am reparat. Ploua cu bug-uri tot mai mult. Dupa o saptamana, primesc veste de la SII ca mi-au terminat contractul. Din partea Allianz nicio discutie, nicio avertizare. Explicatia oficiala: nu corespunde nivelul de senioritate. Neoficial: taieri de buget si o experienta a lor anterioara cu un baiat care s-a chinuit 5 luni la ei in aceeasi echipa. Nu voiau sa se intample din nou; dar nici ca faceau mai bine.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Morala: au tratat angajatul fix ca o resursa intr-un fisier Excel, netransparenta totala prin comunicarea deciziei doar firmei de consultanta, neimplicare in a face training-uri, neintroducere de la inceput in echipa corecta, lipsa existentei unui plan de imbarcare transparent si agreat de ambele parti.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/3094735079854395161/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/3094735079854395161?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/3094735079854395161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/3094735079854395161'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/11/din-interviurile-anului-2024-si-o.html' title='Din interviurile anului 2024 si o experienta de munca mai putin fericita'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-5781804602805577234</id><published>2024-10-31T18:07:00.004+02:00</published><updated>2024-10-31T18:07:00.115+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="kafka"/><category scheme="http://www.blogger.com/atom/ns#" term="tests"/><title type='text'>Test de integrare pt Kafka Consumer</title><content type='html'>&lt;div style=&quot;background-color: #1e1f22; color: #bcbec4;&quot;&gt;&lt;pre style=&quot;font-family: &#39;JetBrains Mono&#39;,monospace; font-size: 10,5pt;&quot;&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;@EmbeddedKafka&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;@SpringBootTest&lt;/span&gt;(properties = &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;spring.kafka.consumer.bootstrap-servers=${spring.embedded.kafka.brokers}&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;ProductCreatedEventHandlerTest {&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@MockBean&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;ProcessedEventRepository &lt;span style=&quot;color: #c77dbb;&quot;&gt;processedEventRepository&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@Autowired&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;KafkaTemplate&amp;lt;String, Object&amp;gt; &lt;span style=&quot;color: #c77dbb;&quot;&gt;kafkaTemplate&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@SpyBean &lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;// true object, its methods can be intercepted&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;    &lt;/span&gt;ProductCreatedEventHandler &lt;span style=&quot;color: #c77dbb;&quot;&gt;productCreatedEventHandler&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@Test&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;testHandle&lt;/span&gt;() &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throws &lt;/span&gt;Exception {&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Arrange&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;ProductCreatedEvent event = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ProductCreatedEvent(UUID.&lt;span style=&quot;font-style: italic;&quot;&gt;randomUUID&lt;/span&gt;().toString(), &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;iPhone SE&quot;&lt;/span&gt;, BigDecimal.&lt;span style=&quot;font-style: italic;&quot;&gt;valueOf&lt;/span&gt;(&lt;span style=&quot;color: #2aacb8;&quot;&gt;24.5&lt;/span&gt;), &lt;span style=&quot;color: #2aacb8;&quot;&gt;12&lt;/span&gt;);&lt;br /&gt;        ProducerRecord&amp;lt;String, Object&amp;gt; record = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ProducerRecord&amp;lt;&amp;gt;(&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;PRODUCT_CREATED_EVT_TOPIC&lt;/span&gt;, event.getProductId(), event);&lt;br /&gt;        String messageId = UUID.&lt;span style=&quot;font-style: italic;&quot;&gt;randomUUID&lt;/span&gt;().toString();&lt;br /&gt;        record.headers().add(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;messageId&quot;&lt;/span&gt;, messageId.getBytes());&lt;br /&gt;        record.headers().add(KafkaHeaders.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;RECEIVED_KEY&lt;/span&gt;, event.getProductId().getBytes());&lt;br /&gt;&lt;br /&gt;        ProcessedEventEntity processedEventEntity = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ProcessedEventEntity();&lt;br /&gt;        &lt;span style=&quot;font-style: italic;&quot;&gt;when&lt;/span&gt;(&lt;span style=&quot;color: #c77dbb;&quot;&gt;processedEventRepository&lt;/span&gt;.findByMessageId(&lt;span style=&quot;font-style: italic;&quot;&gt;any&lt;/span&gt;())).thenReturn(processedEventEntity);&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Act&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;kafkaTemplate&lt;/span&gt;.send(record).get();&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Assert&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;ArgumentCaptor&amp;lt;String&amp;gt; messageIdCaptor = ArgumentCaptor.&lt;span style=&quot;font-style: italic;&quot;&gt;forClass&lt;/span&gt;(String.&lt;span style=&quot;color: #cf8e6d;&quot;&gt;class&lt;/span&gt;);&lt;br /&gt;        ArgumentCaptor&amp;lt;String&amp;gt; messageKeyCaptor = ArgumentCaptor.&lt;span style=&quot;font-style: italic;&quot;&gt;forClass&lt;/span&gt;(String.&lt;span style=&quot;color: #cf8e6d;&quot;&gt;class&lt;/span&gt;);&lt;br /&gt;        ArgumentCaptor&amp;lt;ProductCreatedEvent&amp;gt; eventCaptor = ArgumentCaptor.&lt;span style=&quot;font-style: italic;&quot;&gt;forClass&lt;/span&gt;(ProductCreatedEvent.&lt;span style=&quot;color: #cf8e6d;&quot;&gt;class&lt;/span&gt;);&lt;br /&gt;        &lt;span style=&quot;font-style: italic;&quot;&gt;verify&lt;/span&gt;(&lt;span style=&quot;color: #c77dbb;&quot;&gt;productCreatedEventHandler&lt;/span&gt;, &lt;span style=&quot;font-style: italic;&quot;&gt;timeout&lt;/span&gt;(&lt;span style=&quot;color: #2aacb8;&quot;&gt;5000&lt;/span&gt;).times(&lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;))&lt;br /&gt;                .handle(eventCaptor.capture(), messageIdCaptor.capture(), messageKeyCaptor.capture());&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertEquals&lt;/span&gt;(messageId, messageIdCaptor.getValue());&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertEquals&lt;/span&gt;(event.getProductId(), messageKeyCaptor.getValue());&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertEquals&lt;/span&gt;(event.getProductId(), eventCaptor.getValue().getProductId());&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/5781804602805577234/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/5781804602805577234?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/5781804602805577234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/5781804602805577234'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/10/test-de-integrare-pt-kafka-consumer.html' title='Test de integrare pt Kafka Consumer'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-8504688033977595476</id><published>2024-10-30T16:43:00.003+02:00</published><updated>2024-10-30T16:43:23.261+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="kafka"/><category scheme="http://www.blogger.com/atom/ns#" term="tests"/><title type='text'>Test de integrare pt Kafka Producer</title><content type='html'>&lt;p&gt;1. Testarea serviciului care trimite mesaje Kafka&lt;/p&gt;&lt;div style=&quot;background-color: #1e1f22; color: #bcbec4;&quot;&gt;&lt;pre style=&quot;font-family: &#39;JetBrains Mono&#39;,monospace; font-size: 10,5pt;&quot;&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;package &lt;/span&gt;com.hanul.pis.ProductsMicroservice;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;com.hanul.pis.ProductsMicroservice.rest.NewProductDto;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;com.hanul.pis.ProductsMicroservice.service.ProductService;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;com.hanul.pis.core.event.ProductCreatedEvent;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.apache.kafka.clients.consumer.ConsumerConfig;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.apache.kafka.clients.consumer.ConsumerRecord;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.apache.kafka.common.serialization.StringDeserializer;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.junit.jupiter.api.*;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.beans.factory.annotation.&lt;span style=&quot;color: #b3ae60;&quot;&gt;Autowired&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.boot.test.context.&lt;span style=&quot;color: #b3ae60;&quot;&gt;SpringBootTest&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.core.env.Environment;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.core.DefaultKafkaConsumerFactory;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.listener.ContainerProperties;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.listener.KafkaMessageListenerContainer;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.listener.MessageListener;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.support.serializer.ErrorHandlingDeserializer;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.support.serializer.JsonDeserializer;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.test.EmbeddedKafkaBroker;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.test.context.&lt;span style=&quot;color: #b3ae60;&quot;&gt;EmbeddedKafka&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.test.utils.ContainerTestUtils;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.test.annotation.&lt;span style=&quot;color: #b3ae60;&quot;&gt;DirtiesContext&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.test.context.&lt;span style=&quot;color: #b3ae60;&quot;&gt;ActiveProfiles&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;java.math.BigDecimal;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;java.util.Map;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;java.util.concurrent.BlockingQueue;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;java.util.concurrent.LinkedBlockingQueue;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;java.util.concurrent.TimeUnit;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;@DirtiesContext                                 &lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;// it will corrupt the application context -&amp;gt; each test will start with a clean state&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;@TestInstance&lt;/span&gt;(&lt;span style=&quot;color: #b3ae60;&quot;&gt;TestInstance&lt;/span&gt;.Lifecycle.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;PER_CLASS&lt;/span&gt;) &lt;span style=&quot;color: #7a7e85;&quot;&gt;// one instance for all test methods, for expensive setup code&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;@ActiveProfiles&lt;/span&gt;(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;test&quot;&lt;/span&gt;)                         &lt;span style=&quot;color: #7a7e85;&quot;&gt;// look for application-test.properties&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;// use embedded Kafka server&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;@EmbeddedKafka &lt;/span&gt;(partitions = &lt;span style=&quot;color: #2aacb8;&quot;&gt;3&lt;/span&gt;, count = &lt;span style=&quot;color: #2aacb8;&quot;&gt;3&lt;/span&gt;, controlledShutdown = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;true&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;@SpringBootTest&lt;/span&gt;(properties = &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;spring.kafka.producer.bootstrap-servers=${spring.embedded.kafka.brokers}&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;ProductServiceImplTest {&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@Autowired&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private &lt;/span&gt;ProductService &lt;span style=&quot;color: #c77dbb;&quot;&gt;productService&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@Autowired&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private &lt;/span&gt;EmbeddedKafkaBroker &lt;span style=&quot;color: #c77dbb;&quot;&gt;embeddedKafkaBroker&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@Autowired&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private &lt;/span&gt;Environment &lt;span style=&quot;color: #c77dbb;&quot;&gt;environment&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private &lt;/span&gt;KafkaMessageListenerContainer&amp;lt;String, ProductCreatedEvent&amp;gt; &lt;span style=&quot;color: #c77dbb;&quot;&gt;container&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private &lt;/span&gt;BlockingQueue&amp;lt;ConsumerRecord&amp;lt;String, ProductCreatedEvent&amp;gt;&amp;gt; &lt;span style=&quot;color: #c77dbb;&quot;&gt;records &lt;/span&gt;= &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;LinkedBlockingQueue&amp;lt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@BeforeAll&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;setUp&lt;/span&gt;() {&lt;br /&gt;        Map&amp;lt;String, Object&amp;gt; consumerProperties = getConsumerProperties();&lt;br /&gt;        DefaultKafkaConsumerFactory&amp;lt;String, Object&amp;gt; consumerFactory = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;DefaultKafkaConsumerFactory&amp;lt;&amp;gt;(consumerProperties);&lt;br /&gt;        ContainerProperties containerProperties = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ContainerProperties(&lt;span style=&quot;color: #c77dbb;&quot;&gt;environment&lt;/span&gt;.getProperty(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;product-created-evt-topic-name&quot;&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: #c77dbb;&quot;&gt;container &lt;/span&gt;= &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;KafkaMessageListenerContainer&amp;lt;&amp;gt;(consumerFactory, containerProperties);&lt;br /&gt;        &lt;span style=&quot;color: #c77dbb;&quot;&gt;container&lt;/span&gt;.setupMessageListener((MessageListener&amp;lt;String, ProductCreatedEvent&amp;gt;) &lt;span style=&quot;color: #c77dbb;&quot;&gt;records&lt;/span&gt;::add);&lt;br /&gt;        &lt;span style=&quot;color: #c77dbb;&quot;&gt;container&lt;/span&gt;.start();&lt;br /&gt;        ContainerTestUtils.&lt;span style=&quot;font-style: italic;&quot;&gt;waitForAssignment&lt;/span&gt;(&lt;span style=&quot;color: #c77dbb;&quot;&gt;container&lt;/span&gt;, &lt;span style=&quot;color: #c77dbb;&quot;&gt;embeddedKafkaBroker&lt;/span&gt;.getPartitionsPerTopic());&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@AfterAll&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;tearDown&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: #c77dbb;&quot;&gt;container&lt;/span&gt;.stop();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@Test&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;testCreateProduct_validProduct_success&lt;/span&gt;() &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throws &lt;/span&gt;Exception {&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Arrange&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;NewProductDto newProductDto = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;NewProductDto();&lt;br /&gt;        newProductDto.setPrice(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;BigDecimal(&lt;span style=&quot;color: #2aacb8;&quot;&gt;1200&lt;/span&gt;));&lt;br /&gt;        newProductDto.setQuantity(&lt;span style=&quot;color: #2aacb8;&quot;&gt;10&lt;/span&gt;);&lt;br /&gt;        newProductDto.setTitle(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Philips monitor 40&lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Act&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;String productId = &lt;span style=&quot;color: #c77dbb;&quot;&gt;productService&lt;/span&gt;.createProduct(newProductDto);&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Assert&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertNotNull&lt;/span&gt;(productId);&lt;br /&gt;        ConsumerRecord&amp;lt;String, ProductCreatedEvent&amp;gt; message = &lt;span style=&quot;color: #c77dbb;&quot;&gt;records&lt;/span&gt;.poll(&lt;span style=&quot;color: #2aacb8;&quot;&gt;3&lt;/span&gt;, TimeUnit.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;SECONDS&lt;/span&gt;);&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertNotNull&lt;/span&gt;(message);&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertNotNull&lt;/span&gt;(message.key());&lt;br /&gt;        ProductCreatedEvent event = message.value();&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertNotNull&lt;/span&gt;(event);&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertEquals&lt;/span&gt;(newProductDto.getTitle(), event.getTitle());&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertEquals&lt;/span&gt;(newProductDto.getPrice(), event.getPrice());&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertEquals&lt;/span&gt;(newProductDto.getQuantity(), event.getQuantity());&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private &lt;/span&gt;Map&amp;lt;String, Object&amp;gt; &lt;span style=&quot;color: #56a8f5;&quot;&gt;getConsumerProperties&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Brokers&#39; port numbers will dynamically change during executions of this test&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        // Therefore, they should be dynamically retrieved in configuration&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;Map.&lt;span style=&quot;font-style: italic;&quot;&gt;of&lt;/span&gt;(&lt;br /&gt;                ConsumerConfig.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;BOOTSTRAP_SERVERS_CONFIG&lt;/span&gt;, &lt;span style=&quot;color: #c77dbb;&quot;&gt;embeddedKafkaBroker&lt;/span&gt;.getBrokersAsString(),&lt;br /&gt;                ConsumerConfig.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;KEY_DESERIALIZER_CLASS_CONFIG&lt;/span&gt;, StringDeserializer.&lt;span style=&quot;color: #cf8e6d;&quot;&gt;class&lt;/span&gt;,&lt;br /&gt;                ConsumerConfig.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;VALUE_DESERIALIZER_CLASS_CONFIG&lt;/span&gt;, ErrorHandlingDeserializer.&lt;span style=&quot;color: #cf8e6d;&quot;&gt;class&lt;/span&gt;,&lt;br /&gt;                ErrorHandlingDeserializer.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;VALUE_DESERIALIZER_CLASS&lt;/span&gt;, JsonDeserializer.&lt;span style=&quot;color: #cf8e6d;&quot;&gt;class&lt;/span&gt;,&lt;br /&gt;                ConsumerConfig.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;GROUP_ID_CONFIG&lt;/span&gt;, &lt;span style=&quot;color: #c77dbb;&quot;&gt;environment&lt;/span&gt;.getProperty(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;spring.kafka.consumer.group-id&quot;&lt;/span&gt;),&lt;br /&gt;                JsonDeserializer.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;TRUSTED_PACKAGES&lt;/span&gt;, &lt;span style=&quot;color: #c77dbb;&quot;&gt;environment&lt;/span&gt;.getProperty(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;spring.kafka.consumer.properties.spring.json.trusted.packages&quot;&lt;/span&gt;),&lt;br /&gt;                ConsumerConfig.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;AUTO_OFFSET_RESET_CONFIG&lt;/span&gt;, &lt;span style=&quot;color: #c77dbb;&quot;&gt;environment&lt;/span&gt;.getProperty(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;spring.kafka.consumer.auto-offset-reset&quot;&lt;/span&gt;)&lt;br /&gt;                );&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;2. Testarea configurarilor - ex. ca producatorul este idempotent&lt;/p&gt;&lt;div style=&quot;background-color: #1e1f22; color: #bcbec4;&quot;&gt;&lt;pre style=&quot;font-family: &#39;JetBrains Mono&#39;,monospace; font-size: 10,5pt;&quot;&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;package &lt;/span&gt;com.hanul.pis.ProductsMicroservice;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;com.hanul.pis.core.event.ProductCreatedEvent;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.apache.kafka.clients.producer.ProducerConfig;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.junit.jupiter.api.Assertions;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.junit.jupiter.api.&lt;span style=&quot;color: #b3ae60;&quot;&gt;Test&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.beans.factory.annotation.&lt;span style=&quot;color: #b3ae60;&quot;&gt;Autowired&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.boot.test.context.&lt;span style=&quot;color: #b3ae60;&quot;&gt;SpringBootTest&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.core.KafkaTemplate;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;org.springframework.kafka.core.ProducerFactory;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;java.util.Map;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;@SpringBootTest&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;IdempotentProducerItTest { &lt;span style=&quot;color: #7a7e85;&quot;&gt;// it will test based on real configuration&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;@Autowired&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;KafkaTemplate&amp;lt;String, ProductCreatedEvent&amp;gt; &lt;span style=&quot;color: #c77dbb;&quot;&gt;kafkaTemplate&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #b3ae60;&quot;&gt;@Test&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;test_enabledIdempotence&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Arrange&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;ProducerFactory&amp;lt;String, ProductCreatedEvent&amp;gt; producerFactory = &lt;span style=&quot;color: #c77dbb;&quot;&gt;kafkaTemplate&lt;/span&gt;.getProducerFactory();&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Act&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;Map&amp;lt;String, Object&amp;gt; config = producerFactory.getConfigurationProperties();&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// Assert&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertEquals&lt;/span&gt;(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;true&quot;&lt;/span&gt;, config.get(ProducerConfig.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;ENABLE_IDEMPOTENCE_CONFIG&lt;/span&gt;));&lt;br /&gt;        Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertTrue&lt;/span&gt;(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;all&quot;&lt;/span&gt;.equalsIgnoreCase((String) config.get(ProducerConfig.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;ACKS_CONFIG&lt;/span&gt;)));&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(config.containsKey(ProducerConfig.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;RETRIES_CONFIG&lt;/span&gt;)) {&lt;br /&gt;            Assertions.&lt;span style=&quot;font-style: italic;&quot;&gt;assertTrue&lt;/span&gt;(Integer.&lt;span style=&quot;font-style: italic;&quot;&gt;parseInt&lt;/span&gt;(config.get(ProducerConfig.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;RETRIES_CONFIG&lt;/span&gt;).toString()) &amp;gt; &lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/8504688033977595476/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/8504688033977595476?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/8504688033977595476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/8504688033977595476'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/10/test-de-integrare-pt-kafka-producer.html' title='Test de integrare pt Kafka Producer'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-7154347207968054877</id><published>2024-08-16T20:32:00.004+03:00</published><updated>2024-08-18T20:54:27.765+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="grind75"/><title type='text'>Grind75</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#57. Insert Interval (&lt;a href=&quot;https://leetcode.com/problems/insert-interval/description/&quot;&gt;link&lt;/a&gt;)&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #dcdcaa;&quot;&gt;insert&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;newInterval&lt;/span&gt;) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;start&lt;/span&gt; = newInterval[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;], stop = newInterval[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// case: newInterval contains all intervals&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; == &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; || start &amp;lt;= intervals[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] &amp;amp;&amp;amp; stop &amp;gt;= intervals[&lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;]) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            result[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] = newInterval;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; result;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        }&lt;/div&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;insertion&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// What should insertion[0] be?&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        insertion[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] = start;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (start &amp;gt; intervals[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;]) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (start &amp;gt;= intervals[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] &amp;amp;&amp;amp; start &amp;lt;= intervals[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;]) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                    insertion[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] = intervals[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                    &lt;span style=&quot;color: #c586c0;&quot;&gt;break&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        }&lt;/div&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// What should insertion[1] be?&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        insertion[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] = stop;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (stop &amp;lt; intervals[&lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;]) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (stop &amp;gt;= intervals[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] &amp;amp;&amp;amp; stop &amp;lt;= intervals[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;]) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                    insertion[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] = intervals[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                    &lt;span style=&quot;color: #c586c0;&quot;&gt;break&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        }&lt;/div&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// Place insertion&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;added&lt;/span&gt; = &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;[]&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;ArrayList&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (insertion[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] &amp;lt;= intervals[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;]) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                &lt;span style=&quot;color: #dcdcaa;&quot;&gt;addToList&lt;/span&gt;(insertion, result);&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                added = &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; &amp;amp;&amp;amp; intervals[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] &amp;lt;= insertion[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;]) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                    i++;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                &lt;span style=&quot;color: #dcdcaa;&quot;&gt;copyRest&lt;/span&gt;(i, intervals, result);&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;break&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            } &lt;span style=&quot;color: #c586c0;&quot;&gt;else&lt;/span&gt; {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;                &lt;span style=&quot;color: #dcdcaa;&quot;&gt;addToList&lt;/span&gt;(intervals[i], result);&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (!added) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            &lt;span style=&quot;color: #6a9955;&quot;&gt;// add at the end&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            &lt;span style=&quot;color: #dcdcaa;&quot;&gt;addToList&lt;/span&gt;(insertion, result);&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        }&lt;/div&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// List to arrays&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;array&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[&lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;size&lt;/span&gt;()][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;size&lt;/span&gt;(); i++) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            array[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(i)[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            array[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(i)[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; array;&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;    }&lt;/div&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;copyRest&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;from&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;[]&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;list&lt;/span&gt;) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=from; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;intervals&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;            &lt;span style=&quot;color: #dcdcaa;&quot;&gt;addToList&lt;/span&gt;(intervals[i], list);&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;    }&lt;/div&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;addToList&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;interval&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;[]&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;list&lt;/span&gt;) {&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;pair&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;[&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        pair[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] = interval[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        pair[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] = interval[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;list&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(pair);&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;    }&lt;/div&gt;&lt;div style=&quot;font-size: 13px;&quot;&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Pt. restul &lt;a href=&quot;https://github.com/voulpit/grind75&quot;&gt;LINK&lt;/a&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/7154347207968054877/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/7154347207968054877?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/7154347207968054877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/7154347207968054877'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/08/grind75-week-1.html' title='Grind75'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-1144889625519324277</id><published>2024-08-09T14:31:00.006+03:00</published><updated>2024-08-09T15:11:17.250+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="concurrency"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Exemple Deadlock &amp; Livelock</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Deadlock&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Cand doua sau mai multe fire de executie sunt &lt;u&gt;blocate in asteptarea&lt;/u&gt; eliberarii unor resurse de care au nevoie. Solutie: &lt;a href=&quot;https://www.developer.com/java/java-prevent-thread-deadlock/&quot;&gt;how to prevent deadlock in Java&lt;/a&gt;.&lt;/p&gt;&lt;div style=&quot;background-color: #1e1f22; color: #bcbec4;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 10,5pt;&quot;&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private static void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;deadlock&lt;/span&gt;() {&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;final &lt;/span&gt;String res1 = &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Resource_1&quot;&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;final &lt;/span&gt;String res2 = &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Resource_2&quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    Thread t1 = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Thread(() -&amp;gt; {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;synchronized &lt;/span&gt;(&lt;span style=&quot;color: #c77dbb;&quot;&gt;res1&lt;/span&gt;) {&lt;br /&gt;            System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;[t1] acquired access to res1&quot;&lt;/span&gt;);&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;try &lt;/span&gt;{&lt;br /&gt;                Thread.&lt;span style=&quot;font-style: italic;&quot;&gt;sleep&lt;/span&gt;(&lt;span style=&quot;color: #2aacb8;&quot;&gt;5000&lt;/span&gt;);&lt;br /&gt;            } &lt;span style=&quot;color: #cf8e6d;&quot;&gt;catch &lt;/span&gt;(InterruptedException e) {&lt;br /&gt;                &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throw new &lt;/span&gt;RuntimeException(e);&lt;br /&gt;            }&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;synchronized &lt;/span&gt;(&lt;span style=&quot;color: #c77dbb;&quot;&gt;res2&lt;/span&gt;) {&lt;br /&gt;                System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;[t1] Yay! escaped deadlock.&quot;&lt;/span&gt;); &lt;span style=&quot;color: #7a7e85;&quot;&gt;// not happening&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;            &lt;/span&gt;}&lt;br /&gt;        }&lt;br /&gt;    });&lt;br /&gt;    Thread t2 = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Thread(() -&amp;gt; {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;synchronized &lt;/span&gt;(&lt;span style=&quot;color: #c77dbb;&quot;&gt;res2&lt;/span&gt;) {&lt;br /&gt;            System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;[t2] acquired access to res2&quot;&lt;/span&gt;);&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;try &lt;/span&gt;{&lt;br /&gt;                Thread.&lt;span style=&quot;font-style: italic;&quot;&gt;sleep&lt;/span&gt;(&lt;span style=&quot;color: #2aacb8;&quot;&gt;5000&lt;/span&gt;);&lt;br /&gt;            } &lt;span style=&quot;color: #cf8e6d;&quot;&gt;catch &lt;/span&gt;(InterruptedException e) {&lt;br /&gt;                &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throw new &lt;/span&gt;RuntimeException(e);&lt;br /&gt;            }&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;synchronized &lt;/span&gt;(&lt;span style=&quot;color: #c77dbb;&quot;&gt;res1&lt;/span&gt;) {&lt;br /&gt;                System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;[t2] Yay! escaped deadlock.&quot;&lt;/span&gt;);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    });&lt;br /&gt;&lt;br /&gt;    t1.start();&lt;br /&gt;    t2.start();&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Livelock&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Doua sau mai multe fire de executie isi cedeaza dreptul de a rula in favoarea celorlalte astfel ajungand sa nu ruleze niciodata, iar aplicatia nu progreseaza. Solutie: schimbarea logicii.&lt;/p&gt;&lt;div style=&quot;background-color: #1e1f22; color: #bcbec4;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 10,5pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 10,5pt;&quot;&gt;&lt;div&gt;&lt;pre style=&quot;font-family: &#39;JetBrains Mono&#39;,monospace; font-size: 10,5pt;&quot;&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;static class &lt;/span&gt;Spoon {&lt;br /&gt;    Diner &lt;span style=&quot;color: #c77dbb;&quot;&gt;owner&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;Spoon &lt;/span&gt;(Diner firstOwner) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;owner &lt;/span&gt;= firstOwner;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;synchronized void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;setOwner&lt;/span&gt;(Diner owner) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;owner &lt;/span&gt;= owner;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;synchronized void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;use&lt;/span&gt;() {&lt;br /&gt;        System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #c77dbb;&quot;&gt;owner&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;name &lt;/span&gt;+ &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; just ate!&quot;&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;static class &lt;/span&gt;Diner {&lt;br /&gt;    String &lt;span style=&quot;color: #c77dbb;&quot;&gt;name&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;boolean &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;isHungry&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;Diner &lt;/span&gt;(String name) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;name &lt;/span&gt;= name;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;isHungry &lt;/span&gt;= &lt;span style=&quot;color: #cf8e6d;&quot;&gt;true&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;eatWith &lt;/span&gt;(Spoon spoon, Diner spouse) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;while &lt;/span&gt;(&lt;span style=&quot;color: #c77dbb;&quot;&gt;isHungry&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(spoon.&lt;span style=&quot;color: #c77dbb;&quot;&gt;owner &lt;/span&gt;!= &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: #7a7e85;&quot;&gt;// wait for a while for the spoon to be released&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;try &lt;/span&gt;{&lt;br /&gt;                    Thread.&lt;span style=&quot;font-style: italic;&quot;&gt;sleep&lt;/span&gt;(&lt;span style=&quot;color: #2aacb8;&quot;&gt;3000&lt;/span&gt;);&lt;br /&gt;                } &lt;span style=&quot;color: #cf8e6d;&quot;&gt;catch &lt;/span&gt;(InterruptedException e) {&lt;br /&gt;                    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throw new &lt;/span&gt;RuntimeException(e);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span style=&quot;color: #7a7e85;&quot;&gt;// after wait, try to give the spoon to the spouse if she&#39;s hungry&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(spouse.&lt;span style=&quot;color: #c77dbb;&quot;&gt;isHungry&lt;/span&gt;) {&lt;br /&gt;                System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;[&quot; &lt;/span&gt;+ &lt;span style=&quot;color: #c77dbb;&quot;&gt;name &lt;/span&gt;+ &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;] Eat, baby, eat!&quot;&lt;/span&gt;);&lt;br /&gt;                spoon.&lt;span style=&quot;color: #c77dbb;&quot;&gt;owner &lt;/span&gt;= spouse;&lt;br /&gt;            } &lt;span style=&quot;color: #cf8e6d;&quot;&gt;else &lt;/span&gt;{&lt;br /&gt;                &lt;span style=&quot;color: #7a7e85;&quot;&gt;// finally&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;                &lt;/span&gt;spoon.use();&lt;br /&gt;                &lt;span style=&quot;color: #c77dbb;&quot;&gt;isHungry &lt;/span&gt;= &lt;span style=&quot;color: #cf8e6d;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;                System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;[&quot; &lt;/span&gt;+ &lt;span style=&quot;color: #c77dbb;&quot;&gt;name &lt;/span&gt;+ &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;] Finally ate!!!&quot;&lt;/span&gt;); &lt;span style=&quot;color: #7a7e85;&quot;&gt;// never&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;                &lt;/span&gt;spoon.&lt;span style=&quot;color: #c77dbb;&quot;&gt;owner &lt;/span&gt;= spouse;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;private static void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;livelock&lt;/span&gt;() {&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;final &lt;/span&gt;Diner husband = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Diner(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Adnan&quot;&lt;/span&gt;);&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;final &lt;/span&gt;Diner wife = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Diner(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Hannan&quot;&lt;/span&gt;);&lt;br /&gt;    Spoon spoon = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Spoon(wife);&lt;br /&gt;    &lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;try &lt;/span&gt;{&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Thread(() -&amp;gt; &lt;span style=&quot;color: #c77dbb;&quot;&gt;husband&lt;/span&gt;.eatWith(&lt;span style=&quot;color: #c77dbb;&quot;&gt;spoon&lt;/span&gt;, &lt;span style=&quot;color: #c77dbb;&quot;&gt;wife&lt;/span&gt;)).start();&lt;br /&gt;        Thread.&lt;span style=&quot;font-style: italic;&quot;&gt;sleep&lt;/span&gt;(&lt;span style=&quot;color: #2aacb8;&quot;&gt;1500&lt;/span&gt;);&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Thread(() -&amp;gt; &lt;span style=&quot;color: #c77dbb;&quot;&gt;wife&lt;/span&gt;.eatWith(&lt;span style=&quot;color: #c77dbb;&quot;&gt;spoon&lt;/span&gt;, &lt;span style=&quot;color: #c77dbb;&quot;&gt;husband&lt;/span&gt;)).start();&lt;br /&gt;    } &lt;span style=&quot;color: #cf8e6d;&quot;&gt;catch &lt;/span&gt;(InterruptedException e) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throw new &lt;/span&gt;RuntimeException(e);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/1144889625519324277/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/1144889625519324277?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/1144889625519324277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/1144889625519324277'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/08/exemple-deadlock-livelock.html' title='Exemple Deadlock &amp; Livelock'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-4724574274073371695</id><published>2024-08-07T23:16:00.001+03:00</published><updated>2024-08-07T23:26:05.123+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="utile"/><title type='text'>Script bash pt build proiecte</title><content type='html'>&lt;p&gt;&amp;nbsp;./script.sh &amp;lt;nume branch&amp;gt;&lt;/p&gt;&lt;div style=&quot;background-color: #1f1f1f; color: #cccccc; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;branch&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;master&quot;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; [ &lt;span style=&quot;color: #d4d4d4;&quot;&gt;-n&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$1&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&lt;/span&gt; ]; &lt;span style=&quot;color: #c586c0;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #9cdcfe;&quot;&gt;branch&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;\ngit pull from &quot;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$branch&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;\n\n&quot;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;currentDate&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt; +&quot;%Y-%m-%d-%H%M&quot;`&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;filename&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$currentDate&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;.log&quot;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;touch&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$filename&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;dir&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;ls&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt; .`&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;do&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; [[ &lt;span style=&quot;color: #d4d4d4;&quot;&gt;-d&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt; ]]; &lt;span style=&quot;color: #c586c0;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;$&#39;&lt;/span&gt;&lt;span style=&quot;color: #d7ba7d;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;cd&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;mvn&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;clean&lt;/span&gt; &amp;amp;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; ../&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$filename&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;git&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;checkout&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;master&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;git&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;pull&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;cd&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;..&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;$&#39;&lt;/span&gt;&lt;span style=&quot;color: #d7ba7d;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;&lt;/span&gt; &amp;amp;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$filename&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #c586c0;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;done&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #6a9955;&quot;&gt;# legacy first&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;$&#39;&lt;/span&gt;&lt;span style=&quot;color: #d7ba7d;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;&lt;/span&gt; &lt;span style=&quot;color: #d4d4d4;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$filename&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;dir&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;ls&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt; .`&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;do&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; [[ &lt;span style=&quot;color: #d4d4d4;&quot;&gt;-d&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt; &lt;span style=&quot;color: #d4d4d4;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&lt;/span&gt; &lt;span style=&quot;color: #d4d4d4;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #d4d4d4;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;legacy&quot;&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;*&lt;/span&gt; ]]; &lt;span style=&quot;color: #c586c0;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;$&#39;&lt;/span&gt;&lt;span style=&quot;color: #d7ba7d;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;cd&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;mvn&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;install&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;-DskipTests&lt;/span&gt; &amp;amp;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; ../&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$filename&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;cd&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;..&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;$&#39;&lt;/span&gt;&lt;span style=&quot;color: #d7ba7d;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;&lt;/span&gt; &amp;amp;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$filename&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #c586c0;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;done&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;\n&quot;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;dir&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;ls&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt; .`&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;do&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; [[ &lt;span style=&quot;color: #d4d4d4;&quot;&gt;-d&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt; &lt;span style=&quot;color: #d4d4d4;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&lt;/span&gt; &lt;span style=&quot;color: #d4d4d4;&quot;&gt;!=&lt;/span&gt; &lt;span style=&quot;color: #d4d4d4;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;legacy&quot;&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;*&lt;/span&gt; ]]; &lt;span style=&quot;color: #c586c0;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;$&#39;&lt;/span&gt;&lt;span style=&quot;color: #d7ba7d;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;cd&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$dir&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;mvn&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;install&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;-DskipTests&lt;/span&gt; &amp;amp;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; ../&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$filename&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;cd&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;..&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;$&#39;&lt;/span&gt;&lt;span style=&quot;color: #d7ba7d;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;&lt;/span&gt; &amp;amp;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;$filename&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #c586c0;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;done&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/4724574274073371695/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/4724574274073371695?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/4724574274073371695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/4724574274073371695'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/08/script-bash-pt-build-proiecte.html' title='Script bash pt build proiecte'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-8610700604857608258</id><published>2024-07-21T21:06:00.018+03:00</published><updated>2024-07-24T18:03:12.990+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cracking the code interview"/><category scheme="http://www.blogger.com/atom/ns#" term="grafuri"/><title type='text'>Probleme grafuri &amp; arbori (2)</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#5. Aranjarea unor cursuri cu relatie de dependenta intre ele&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Se da un numCourses si o lista de dependinte prereq[i] = [a, b], cu semnificatia: pentru a putea participa la cursul a, un student trebuie sa participe intai la cursul b. Sa se gaseasca o aranjare posibila a cursurilor, cu satisfacerea tuturor relatiilor de dependenta.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Nota&lt;/b&gt;: sortare topologica intr-un graf orientat. Se pun intr-o stiva si se elimina succesiv nodurile care nu au arce de iesire, impreuna cu arcele lor de intrare. Se repeta pana cand nu mai ramane niciun nod, apoi se scot nodurile din stiva; ele vor fi sortate topologic. Daca exista un ciclu in graf, nu exista sortare topologica - se va observa ca de la o iteratie la alta nu se mai sterg noduri.&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #dcdcaa;&quot;&gt;findOrder&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;numCourses&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;prereq&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Set&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;HashMap&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;numCourses; i++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;put&lt;/span&gt;(i, &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;HashSet&lt;/span&gt;&amp;lt;&amp;gt;());&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;edges&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; prereq) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;to&lt;/span&gt; = edges[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;], from = edges[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(from).&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(to);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;[] = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[numCourses];&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;try&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Stack&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;stack&lt;/span&gt; = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;topologicalSort&lt;/span&gt;(numCourses, outgoingEdges);&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (!&lt;span style=&quot;color: #9cdcfe;&quot;&gt;stack&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isEmpty&lt;/span&gt;()) {&lt;/div&gt;&lt;div&gt;                result[i++] = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;stack&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;pop&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        } &lt;span style=&quot;color: #c586c0;&quot;&gt;catch&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;CircularException&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;e&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; result;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Stack&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;topologicalSort&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;numCourses&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Set&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Stack&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodeStack&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Stack&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;remainingNodes&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;size&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (!&lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isEmpty&lt;/span&gt;()) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;connectionsToDelete&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;LinkedList&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;numCourses; i++) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;containsKey&lt;/span&gt;(i) &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(i).&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isEmpty&lt;/span&gt;()) {&lt;/div&gt;&lt;div&gt;                    &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodeStack&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;push&lt;/span&gt;(i);&lt;/div&gt;&lt;div&gt;                    &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;remove&lt;/span&gt;(i);&lt;/div&gt;&lt;div&gt;                    &lt;span style=&quot;color: #9cdcfe;&quot;&gt;connectionsToDelete&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(i);&lt;/div&gt;&lt;div&gt;                }&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;forEach&lt;/span&gt;((k,v) &lt;span style=&quot;color: #569cd6;&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;v&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;removeAll&lt;/span&gt;(connectionsToDelete));&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;connectionsToDelete&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;clear&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;            &lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #6a9955;&quot;&gt;// este un ciclu atunci cand dupa o parcurgere completa nu se mai scot noduri&lt;/span&gt;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (remainingNodes == &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;size&lt;/span&gt;()) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;CircularException&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;            remainingNodes = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;outgoingEdges&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;size&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; nodeStack;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;CircularException&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;extends&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;RuntimeException&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;CircularException&lt;/span&gt;() {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #569cd6;&quot;&gt;super&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Varianta mai eficienta&lt;/b&gt;: sortare topologica folosind DSF. Dupa obtinerea unei ordini topologice, trebuie sa se verifice ca graful nu contine cicluri.&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #dcdcaa;&quot;&gt;findOrder&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;numCourses&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;prereq&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;adjList&lt;/span&gt; = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;getAdjList&lt;/span&gt;(numCourses, prereq);&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;visited&lt;/span&gt;[] = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt;[numCourses]; &lt;span style=&quot;color: #6a9955;&quot;&gt;// all false&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Stack&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;stack&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Stack&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;[] = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[numCourses];&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;numCourses; i++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (!visited[i]) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #dcdcaa;&quot;&gt;dfs&lt;/span&gt;(i, adjList, stack, visited);&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (!&lt;span style=&quot;color: #9cdcfe;&quot;&gt;stack&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isEmpty&lt;/span&gt;()) {&lt;/div&gt;&lt;div&gt;            result[i++] = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;stack&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;pop&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// check for any cycle&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; node &amp;lt; numCourses; node++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;conn&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;adjList&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(node)) { &lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #6a9955;&quot;&gt;// we have a vertex from node -&amp;gt; conn&lt;/span&gt;&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #6a9955;&quot;&gt;// if conn appears before node in the ordering =&amp;gt; cycle&lt;/span&gt;&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;indexOf&lt;/span&gt;(conn, result) &amp;lt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;indexOf&lt;/span&gt;(node, result)) {&lt;/div&gt;&lt;div&gt;                    &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;]; &lt;span style=&quot;color: #6a9955;&quot;&gt;// cycle&lt;/span&gt;&lt;/div&gt;&lt;div&gt;                }&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; result;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;dfs&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;adjList&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Stack&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;stack&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;visited&lt;/span&gt;[]) {&lt;/div&gt;&lt;div&gt;        visited[node] = &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;neighbor&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;adjList&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(node)) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (!visited[neighbor]) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #dcdcaa;&quot;&gt;dfs&lt;/span&gt;(neighbor, adjList, stack, visited);&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;stack&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;push&lt;/span&gt;(node);&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;getAdjList&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;numCourses&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;prereq&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;adjList&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;ArrayList&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;numCourses; i++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;adjList&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(&lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;ArrayList&lt;/span&gt;&amp;lt;&amp;gt;());&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;edges&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; prereq) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;to&lt;/span&gt; = edges[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;], from = edges[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;adjList&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(from).&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(to);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; adjList;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;indexOf&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;order&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;order&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (order[i] == node) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; i;&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; -&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;    }    &lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#6. Primul stramos comun a doua noduri dintr-un arbore binar&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Cand avem acces la parintii unui nod:&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;lowestCommonAncestor&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;p&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;q&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (p == root || q == root) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; root;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;diffDepth&lt;/span&gt; = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;depth&lt;/span&gt;(root, p) - &lt;span style=&quot;color: #dcdcaa;&quot;&gt;depth&lt;/span&gt;(root, q);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (diffDepth &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            p = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;p&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;parent&lt;/span&gt;; &lt;span style=&quot;color: #6a9955;&quot;&gt;// bring p on the same level with q&lt;/span&gt;&lt;/div&gt;&lt;div&gt;            diffDepth--;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (diffDepth &amp;lt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            q = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;q&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;parent&lt;/span&gt;; &lt;span style=&quot;color: #6a9955;&quot;&gt;// bring q on the same level with p&lt;/span&gt;&lt;/div&gt;&lt;div&gt;            diffDepth++;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (p != q &amp;amp;&amp;amp; p != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; q != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #6a9955;&quot;&gt;// go up together&lt;/span&gt;&lt;/div&gt;&lt;div&gt;            p = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;q&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;parent&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;            p = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;q&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;parent&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; (p != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; q != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; p &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;depth&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;depth&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (node != root) {&lt;/div&gt;&lt;div&gt;            depth++;&lt;/div&gt;&lt;div&gt;            node = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;parent&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; depth;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Cand nu avem acces la parintii unui nod:&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;lowestCommonAncestor&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;p&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;q&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (p == root || q == root || root == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; root;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(root, p, q);&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;p&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;q&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (node == p || node == q) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; node;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;isPinLeft&lt;/span&gt; = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isNodeInSubtree&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt;, p);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;isQinLeft&lt;/span&gt; = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isNodeInSubtree&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt;, q);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (isPinLeft != isQinLeft) { &lt;span style=&quot;color: #6a9955;&quot;&gt;// if p and q are in different branches of node&lt;/span&gt;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; node; &lt;span style=&quot;color: #6a9955;&quot;&gt;// common ancestor&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        } &lt;span style=&quot;color: #c586c0;&quot;&gt;else&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodeNext&lt;/span&gt; = isPinLeft &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(nodeNext, p, q);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isNodeInSubtree&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;subtree&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (subtree == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;subtree&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; == &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isNodeInSubtree&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;subtree&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt;, node) || &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isNodeInSubtree&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;subtree&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt;, node);&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #6a9955;&quot;&gt;// issue: repetitive calls to isNodeInSubtree when it already found the node&lt;/span&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Alternativa - fara acces la parinti, tinem minte calea pana la nod in format L/R&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;lowestCommonAncestor&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;p&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;q&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (p == root || q == root || root == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; root;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(root, p, &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&quot;&lt;/span&gt;, q, &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;ancestor&lt;/span&gt; = root;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;finalPathP&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;length&lt;/span&gt;() &amp;gt; i &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;finalPathQ&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;length&lt;/span&gt;() &amp;gt; i &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;finalPathP&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i) == &lt;span style=&quot;color: #9cdcfe;&quot;&gt;finalPathQ&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i)) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;c&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;finalPathP&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i);&lt;/div&gt;&lt;div&gt;            ancestor = c == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;L&#39;&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;ancestor&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;ancestor&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;            i++;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; ancestor;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;finalPathP&lt;/span&gt; = &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;finalPathQ&lt;/span&gt; = &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;p&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;pathP&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;q&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;pathQ&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (node == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; == &lt;span style=&quot;color: #9cdcfe;&quot;&gt;p&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            finalPathP = pathP;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; == &lt;span style=&quot;color: #9cdcfe;&quot;&gt;q&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            finalPathQ = pathQ;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (finalPathP == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; || finalPathQ == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt;, p, pathP + &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;L&quot;&lt;/span&gt;, q, pathQ + &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;L&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt;, p, pathP + &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;R&quot;&lt;/span&gt;, q, pathQ + &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;R&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/8610700604857608258/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/8610700604857608258?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/8610700604857608258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/8610700604857608258'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/07/probleme-grafuri-arbori-2.html' title='Probleme grafuri &amp; arbori (2)'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-5238519140203791042</id><published>2024-07-19T16:23:00.008+03:00</published><updated>2024-07-24T18:02:41.016+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cracking the code interview"/><category scheme="http://www.blogger.com/atom/ns#" term="grafuri"/><title type='text'>Probleme grafuri &amp; arbori (1)</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#1. Aflare daca exista o cale intre doua noduri dintr-un graf&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Graf neorientat cu n noduri pentru care se da o lista de muchii edges[i] = [n1, n2] care inseamna ca exista o legatura directa intre n1 si n2. Sa se afle daca din n1 se poate ajunge in n2.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Nota&lt;/b&gt;: BFS. Nu este necesar sa folosim Map, un simplu ArrayList e suficient.&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;validPath&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;n&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;edges&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;source&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;destination&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (source == destination) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Node&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodes&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;HashMap&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;n; i++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodes&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;put&lt;/span&gt;(i, &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;Node&lt;/span&gt;(i));&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;edges&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;from&lt;/span&gt; = edges[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;], to = edges[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodes&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(from).&lt;span style=&quot;color: #dcdcaa;&quot;&gt;addNeighbor&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodes&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(to));&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodes&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(to).&lt;span style=&quot;color: #dcdcaa;&quot;&gt;addNeighbor&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodes&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(from));&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Node&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;startNode&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodes&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(source);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;startNode&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isLinkedTo&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodes&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(destination))) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;startNode&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;setVisited&lt;/span&gt;();&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Queue&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Node&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;queue&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;LinkedList&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;queue&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;addAll&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;startNode&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;neighbors&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt;(!&lt;span style=&quot;color: #9cdcfe;&quot;&gt;queue&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isEmpty&lt;/span&gt;()) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Node&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;next&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;queue&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;remove&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (!&lt;span style=&quot;color: #9cdcfe;&quot;&gt;next&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;visited&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #9cdcfe;&quot;&gt;next&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;setVisited&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;next&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isLinkedTo&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nodes&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(destination))) {&lt;/div&gt;&lt;div&gt;                    &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;                }&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #9cdcfe;&quot;&gt;queue&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;addAll&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;next&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;neighbors&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Node&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;value&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Node&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;neighbors&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;visited&lt;/span&gt; = &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;Node&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;value&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #569cd6;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;value&lt;/span&gt; = value;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #569cd6;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;neighbors&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;ArrayList&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;addNeighbor&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Node&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #569cd6;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;neighbors&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(node);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isLinkedTo&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Node&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;neighbors&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;contains&lt;/span&gt;(node);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;setVisited&lt;/span&gt;() {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #569cd6;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;visited&lt;/span&gt; = &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#2. Transformarea unui array sortat intr-un BST (binary search tree)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Sirul este sortat crescator. In arborele creat, toti descendentii din stanga ai unui nod &amp;lt;= valoarea nodului, iar descendentii din dreapta &amp;gt; valoarea nodului. In plus, arborele trebuie sa fie aiba inaltimea minima posibila.&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;sortedArrayToBST&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;transform&lt;/span&gt;(nums, &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; - &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;transform&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;indexFrom&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;indexTo&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (indexFrom == indexTo) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;TreeNode&lt;/span&gt;(nums[indexFrom]);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (indexFrom == indexTo - &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;TreeNode&lt;/span&gt;(nums[indexTo]);&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;TreeNode&lt;/span&gt;(nums[indexFrom]);&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; root;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;size&lt;/span&gt; = indexTo - indexFrom + &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;TreeNode&lt;/span&gt;(nums[indexFrom + size/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;]);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;transform&lt;/span&gt;(nums, indexFrom, indexFrom + size/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt; - &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt; = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;transform&lt;/span&gt;(nums, indexFrom + size/&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt; + &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;, indexTo);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; root;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#3. Arbore binar echilibrat&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Dandu-se un arbore binar, sa se afle daca este echilibrat, adica pt fiecare nod diferenta intre inaltimile in jos ale fiecarui subarbore sa nu fie mai mare decat 1.&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isBalanced&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (root == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;try&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #dcdcaa;&quot;&gt;findHeightUnderNode&lt;/span&gt;(root);&lt;/div&gt;&lt;div&gt;        } &lt;span style=&quot;color: #c586c0;&quot;&gt;catch&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;UnbalancedTreeException&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;e&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;findHeightUnderNode&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;) &lt;span style=&quot;color: #569cd6;&quot;&gt;throws&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;UnbalancedTreeException&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt; == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;heightUnderLeft&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;findHeightUnderNode&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;heightUnderRight&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt; == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;findHeightUnderNode&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;Math&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;abs&lt;/span&gt;(heightUnderLeft - heightUnderRight) &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;UnbalancedTreeException&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt; + &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Math&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;max&lt;/span&gt;(heightUnderLeft, heightUnderRight);&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;UnbalancedTreeException&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;extends&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;RuntimeException&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;UnbalancedTreeException&lt;/span&gt;() {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #569cd6;&quot;&gt;super&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#4. Validarea unui BST&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Se da un arbore binar. Sa se verifice daca este un arbore binar de cautare (BST).&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isValidBST&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;root&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;try&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #dcdcaa;&quot;&gt;checkValid&lt;/span&gt;(root, &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;, &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;        } &lt;span style=&quot;color: #c586c0;&quot;&gt;catch&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;InvalidBSTException&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;e&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;checkValid&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;TreeNode&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;lessThan&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;moreThan&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// lessThan, moreThan - constrangeri propagate de sus in jos&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (node == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; || (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt; == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;)) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; &amp;gt;= &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; || (lessThan != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; &amp;gt;= lessThan) || &lt;/div&gt;&lt;div&gt;                    (moreThan != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; &amp;lt;= moreThan)) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;InvalidBSTException&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt; != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; &amp;lt;= &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; || (lessThan != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; &amp;gt;= lessThan) || &lt;/div&gt;&lt;div&gt;                    (moreThan != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; &amp;lt;= moreThan)) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;InvalidBSTException&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;checkValid&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt;, &lt;span style=&quot;color: #dcdcaa;&quot;&gt;min&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt;, lessThan), moreThan);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;checkValid&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt;, lessThan, &lt;span style=&quot;color: #dcdcaa;&quot;&gt;max&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;node&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt;, moreThan));&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;min&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;x&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;y&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (x != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; y != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Math&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;min&lt;/span&gt;(x,y);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; x != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; x &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; y;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;max&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;x&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;y&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (x != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; y != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Math&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;max&lt;/span&gt;(x,y);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; x != &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; x &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; y;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;InvalidBSTException&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;extends&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;RuntimeException&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;InvalidBSTException&lt;/span&gt;() {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #569cd6;&quot;&gt;super&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/5238519140203791042/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/5238519140203791042?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/5238519140203791042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/5238519140203791042'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/07/probleme-grafuri.html' title='Probleme grafuri &amp; arbori (1)'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-7734373606065887334</id><published>2024-07-17T10:52:00.015+03:00</published><updated>2024-07-24T18:02:23.426+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cracking the code interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Programare dinamica"/><title type='text'>Probleme programare dinamică &amp; recursivitate (2)</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#5. Generarea tuturor parantezelor&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Dându-se un număr n, să se genereze toate combinațiile de paranteze bine-formate. Adică: fiecare paranteză deschisă formează un cuplu cu o paranteză închisă și cuplul începe întotdeauna cu paranteza deschisă.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Exemplu&lt;/b&gt;: Input: n = 3&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Output: [&quot;((()))&quot;,&quot;(()())&quot;,&quot;(())()&quot;,&quot;()(())&quot;,&quot;()()()&quot;]&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;generateParenthesis&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;n&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;ArrayList&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// all strings will have 2*n length and are built from scratch&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;generateParenthesis&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;*n, n, &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&quot;&lt;/span&gt;, result);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; result;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;generateParenthesis&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;n&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;initialN&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;generated&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (n == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #6a9955;&quot;&gt;// in the last call we can only use )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isValid&lt;/span&gt;(generated + &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;)&#39;&lt;/span&gt;, &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;, initialN)) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(generated + &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;)&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// recurse only if we are on the good path with the partial result&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isValid&lt;/span&gt;(generated + &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;(&#39;&lt;/span&gt;, &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;, initialN)) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #dcdcaa;&quot;&gt;generateParenthesis&lt;/span&gt;(n-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;, initialN, generated + &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;(&#39;&lt;/span&gt;, result);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isValid&lt;/span&gt;(generated + &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;)&#39;&lt;/span&gt;, &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;, initialN)) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #dcdcaa;&quot;&gt;generateParenthesis&lt;/span&gt;(n-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;, initialN, generated + &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;)&#39;&lt;/span&gt;, result);&lt;/div&gt;&lt;div&gt;        }        &lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isValid&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;checkFinal&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;n&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;, right = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;c&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;toCharArray&lt;/span&gt;()) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (c == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;(&#39;&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;                left++;&lt;/div&gt;&lt;div&gt;            } &lt;span style=&quot;color: #c586c0;&quot;&gt;else&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;                right++;&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (right &amp;gt; left) {&lt;/div&gt;&lt;div&gt;                    &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;                }&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; checkFinal &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; &lt;/div&gt;&lt;div&gt;            left == right &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #6a9955;&quot;&gt;// a well-formed string has the same number of ( and )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;            left &amp;lt;= n;      &lt;span style=&quot;color: #6a9955;&quot;&gt;// a partial result should not have ( count more than n&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#6. Asezarea unor cutii intr-o stiva&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Avem N cutii, fiecare cutie fiind reprezentata in 3 dimensiuni (width, length, height). Ele se pot stivui astfel incat cutia aflata deasupra altei cutii va avea w2 &amp;lt;= w1, l2 &amp;lt;= l1 si h2 &amp;lt;= h1. Nu toate cutiile se pot stivui, dar ele se pot roti astfel incat o inaltime sa devina lungime etc. Care e inaltimea celei mai inalte stive posibile?&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Nota&lt;/b&gt;: la prima vedere, problema este o variatie la problema &lt;a href=&quot;https://boomblebee.blogspot.com/2023/12/50-dsa-questions-5-6-7.html&quot;&gt;&lt;b&gt;Maximum subarray&lt;/b&gt;&lt;/a&gt;&amp;nbsp;(aflarea sumei maxime a unui subsir dintr-un sir), la care se adauga cateva constrangeri. Am implementat urmatorii pasi:&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;transformarea obiectelor-cutie prin rotire astfel incat inaltimea sa fie dimensiunea cu valoarea cea mai mare dintre cele 3D&amp;nbsp; (greedy)&lt;/li&gt;&lt;li&gt;sortarea cutiilor dupa inaltime, urmata de celelalte doua dimensiuni, descrescator (*)&lt;/li&gt;&lt;li&gt;aplicarea algoritmului pt Max subarray mentionat anterior, cu adaptarea constrangerilor pentru cutii (programare dinamica)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;(*) neasteptat de tricky este sortarea cutiilor. Nu toate cutiile sunt ordonabile, iar un algoritm eficient precum Mergesort greseste pentru anumite cazuri. Asa ca am optat pentru un Bubblesort cu numar maxim de comparatii intre elemente, pentru a forta o relatie de ordonare intre oricare 2 elemente din sirul de cutii. (S-a dovedit si ca doar Bubblesort-ul cu 2 for-uri va functiona corect pentru toate testele!)&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Nota&lt;/b&gt;: nu e extrem de eficient, dar e corect. Complexitate: timp O(N^2) determinata in principal de Bubblesort, spatiu O(N) pt un array suplimentar.&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;maxHeight&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxes&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// boxes[i] = (w, len, h)&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;rotateObjectsMaxHeight&lt;/span&gt;(boxes);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxes&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; boxes[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;sortByMaxHeightAndWLDesc&lt;/span&gt;(boxes);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;maxSumHeight&lt;/span&gt; = boxes[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;largest&lt;/span&gt;[] = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[&lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxes&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;        largest[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] = boxes[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;lastAddedIndex&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: #6a9955;&quot;&gt;// index of the last added box to obtain largest so far&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxes&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;canPlace&lt;/span&gt;(boxes[lastAddedIndex], boxes[i])) {&lt;/div&gt;&lt;div&gt;                largest[i] = largest[lastAddedIndex] + boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;            } &lt;span style=&quot;color: #c586c0;&quot;&gt;else&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;                largest[i] = boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #6a9955;&quot;&gt;// try to put current box on any previous box if it gives profit&lt;/span&gt;&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;j&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; j&amp;lt;i; j++) {&lt;/div&gt;&lt;div&gt;                    &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (j != lastAddedIndex) {&lt;/div&gt;&lt;div&gt;                        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;canPlace&lt;/span&gt;(boxes[j], boxes[i]) &amp;amp;&amp;amp; largest[i] &amp;lt; largest[j] + boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;]) {&lt;/div&gt;&lt;div&gt;                            largest[i] = largest[j] + boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;                        }&lt;/div&gt;&lt;div&gt;                    }&lt;/div&gt;&lt;div&gt;                }&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (maxSumHeight &amp;lt; largest[i]) {&lt;/div&gt;&lt;div&gt;                maxSumHeight = largest[i];&lt;/div&gt;&lt;div&gt;                lastAddedIndex = i;&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; maxSumHeight;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;rotateObjectsMaxHeight&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxes&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// h = max(w, len, h) =&amp;gt; swap h with the max&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxes&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;max&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Math&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;max&lt;/span&gt;(boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;], &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Math&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;max&lt;/span&gt;(boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;], boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;]));&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (max != boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;]) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;aux&lt;/span&gt; = boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;]; &lt;span style=&quot;color: #6a9955;&quot;&gt;// h&lt;/span&gt;&lt;/div&gt;&lt;div&gt;                boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;] = max;&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (max == boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;]) { &lt;span style=&quot;color: #6a9955;&quot;&gt;// w&lt;/span&gt;&lt;/div&gt;&lt;div&gt;                    boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] = aux;&lt;/div&gt;&lt;div&gt;                } &lt;span style=&quot;color: #c586c0;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (max == boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;]) { &lt;span style=&quot;color: #6a9955;&quot;&gt;// l&lt;/span&gt;&lt;/div&gt;&lt;div&gt;                    boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] = aux;&lt;/div&gt;&lt;div&gt;                }&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;canPlace&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxUnder&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxTop&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;firstCheck&lt;/span&gt; = boxUnder[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] &amp;gt;= boxTop[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] &amp;amp;&amp;amp; boxUnder[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] &amp;gt;= boxTop[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;rotateCheck&lt;/span&gt; = boxUnder[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] &amp;gt;= boxTop[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] &amp;amp;&amp;amp; boxUnder[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] &amp;gt;= boxTop[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; firstCheck || rotateCheck;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;equals&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxUnder&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxTop&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;firstCheck&lt;/span&gt; = boxUnder[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] == boxTop[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] &amp;amp;&amp;amp; boxUnder[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] == boxTop[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;rotateCheck&lt;/span&gt; = boxUnder[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] == boxTop[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] &amp;amp;&amp;amp; boxUnder[&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] == boxTop[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; firstCheck || rotateCheck;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;sortByMaxHeightAndWLDesc&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxes&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// max complexity bubble sort needed because we need to make as many comparisons as possible&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxes&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; - &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;j&lt;/span&gt;=i+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;; j&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;boxes&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; j++) {&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;rightHeightHigher&lt;/span&gt; = boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;] &amp;lt; boxes[j][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;equalHeightsWithRightBigger&lt;/span&gt; = boxes[i][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;] == boxes[j][&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;] &amp;amp;&amp;amp; &lt;/div&gt;&lt;div&gt;                        &lt;span style=&quot;color: #dcdcaa;&quot;&gt;canPlace&lt;/span&gt;(boxes[j], boxes[i]) &amp;amp;&amp;amp;&lt;/div&gt;&lt;div&gt;                        !&lt;span style=&quot;color: #dcdcaa;&quot;&gt;equals&lt;/span&gt;(boxes[j], boxes[i]);&lt;/div&gt;&lt;div&gt;                &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (rightHeightHigher || equalHeightsWithRightBigger) {&lt;/div&gt;&lt;div&gt;                    &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;aux&lt;/span&gt; = boxes[i];&lt;/div&gt;&lt;div&gt;                    boxes[i] = boxes[j];&lt;/div&gt;&lt;div&gt;                    boxes[j] = aux;&lt;/div&gt;&lt;div&gt;                }&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#7. In cate moduri se pot pune paranteze unei expresii booleene&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Se da o expresie formata din valorile 0, 1 (false, true) si operatorii binari &amp;amp;, | si ^. In cate moduri se pot pune paranteze astfel incat evaluarea expresiei sa fie &lt;i&gt;result&lt;/i&gt;? Parantezele de genul (( )) nu sunt valide.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Exemplu: &lt;u&gt;countEval&lt;/u&gt;(&#39;1 &amp;amp; 0 | 1&#39;, true) = 2, posibilitatile sunt&amp;nbsp;1 &amp;amp; (0 | 1) si (1 &amp;amp; 0) | 1.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Rezolvare&lt;/b&gt;: cateva observatii:&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;cazuri de baza: countEval(Strings.EMPTY, result) = 0 si countEval(str, result) ~ str.equals(result) adica 0 sau 1, cand str are un singur caracter.&lt;/li&gt;&lt;li&gt;valorile 0 si 1 vor sta intotdeauna pe pozitiile 0, 2, 4, ... n , pe cand operatorii binari vor sta intotdeauna pe pozitiile 1, 3, 5, ... n-1&lt;/li&gt;&lt;ul&gt;&lt;li&gt;asta duce la un for (int i=1; i&amp;lt;str.length(); i+=2) in care sa calculam subproblemele&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;daca ne situam pe pozitia unui operator (i), putem calcula recursiv leftCountTrue = countEval(str.substring(0, i), true) si rightCountTrue = countEval(str.substring(i+1), true). Similar si leftCountFalse, rightCountFalse. Toate variabilele ne trebuie pentru ca la un &#39;|&#39;, de exemplu, evaluarea uneia din parti poate fi si false, iar rezultatul final sa fie true.&lt;/li&gt;&lt;li&gt;se calculeaza totalCount = toate modurile posibile de a obtine orice rezultat al evaluarii, care consta din toate modurile de a aranja parantezele in partea stanga * toate modurile de a aranja parantezele in partea dreapta&lt;/li&gt;&lt;ul&gt;&lt;li&gt;totalCount = (leftTrue + leftFalse) * (rightTrue + rightFalse);&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;calculam totalCountTrue in functie de operatorul de pe pozitia i:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&#39;&amp;amp;&#39; --&amp;gt; totalCountTrue = leftCountTrue * rightCountTrue&lt;/li&gt;&lt;li&gt;&#39;|&#39;&amp;nbsp; --&amp;gt; totalCountTrue = leftCountTrue * rightCountTrue + leftCountTrue * rightCountFalse + leftCountFalse * rightCountTrue;&lt;/li&gt;&lt;li&gt;&#39;^&#39; --&amp;gt; totalCountTrue = leftCountTrue * rightCountFalse + leftCountFalse * rightCountTrue;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;in functie de rezultatul dorit, solutia subproblemei curente este totalCountTrue sau totalCount - totalCountTrue. Ea se adauga la variabila pentru pastrarea tuturor modurilor.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;b&gt;Optimizare&lt;/b&gt;: unele apeluri ale metodei countEval se repeta. Putem pastra un tabel unde stocam rezultatul apelului curent pe care sa-l obtinem rapid, daca exista, inainte de intrarea in for.&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;if (memo.containsKey(result + str)) return memo.get(result+str);&lt;/li&gt;&lt;li&gt;memo.put(result+str, countWays);&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/7734373606065887334/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/7734373606065887334?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/7734373606065887334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/7734373606065887334'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/07/probleme-programare-dinamica_17.html' title='Probleme programare dinamică &amp; recursivitate (2)'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-2249474909864719331</id><published>2024-07-16T18:31:00.003+03:00</published><updated>2024-07-24T18:01:42.000+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cracking the code interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Programare dinamica"/><title type='text'>Probleme programare dinamică &amp; recursivitate (1)</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#1. Robot in a Grid (p.d.)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Un robot se află într-o matrice, in coltul din stanga sus. El se poate deplasa doar la dreapta sau in jos, daca celula vizata nu contine un obstacol. Tinta lui este sa ajunga in coltul din dreapta jos al matricii. Sa se afle in cate moduri poate ajunge robotul la destinatie.&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;uniquePathsWithObstacles&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;grid&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// go from destination to origin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;,&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;cache&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;HashMap&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(grid, &lt;span style=&quot;color: #9cdcfe;&quot;&gt;grid&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;, grid[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;].&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;, cache);&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;grid&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;j&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;,&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;cache&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;reachedBack&lt;/span&gt;(grid, i, j)) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;; &lt;span style=&quot;color: #6a9955;&quot;&gt;// found one way!&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;// Number of ways to reach grid[i][j] = ways to reach grid[i-1][j] (go up) +&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #6a9955;&quot;&gt;//                                      ways to reach grid[i][j-1] (left)&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isCellFit&lt;/span&gt;(grid, i, j)) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;indexUp&lt;/span&gt; = (i-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) * grid[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;].&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; + j;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;pathUp&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #6a9955;&quot;&gt;// element indexUp could be already visited but not necessarily attainable from grid[i][j]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isCellFit&lt;/span&gt;(grid, i-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;, j)) {&lt;/div&gt;&lt;div&gt;                pathUp = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;cache&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;containsKey&lt;/span&gt;(indexUp) &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;cache&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(indexUp) &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(grid, i-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;, j, cache);&lt;/div&gt;&lt;div&gt;            }             &lt;/div&gt;&lt;br /&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;indexLeft&lt;/span&gt; = i * grid[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;].&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; + j-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;pathLeft&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isCellFit&lt;/span&gt;(grid, i, j-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)) {&lt;/div&gt;&lt;div&gt;                pathLeft = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;cache&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;containsKey&lt;/span&gt;(indexLeft) &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;cache&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(indexLeft) &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;search&lt;/span&gt;(grid, i, j-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;, cache);&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;            &lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;index&lt;/span&gt; = i * grid[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;].&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; + j;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;cache&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;put&lt;/span&gt;(index, pathUp + pathLeft); &lt;span style=&quot;color: #6a9955;&quot;&gt;// grid[i][j] is visited and its result established&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; pathUp + pathLeft;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isCellFit&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;grid&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;j&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (i &amp;lt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; || i &amp;gt;= &lt;span style=&quot;color: #9cdcfe;&quot;&gt;grid&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; || j &amp;lt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; || j &amp;gt;= grid[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;].&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;; &lt;span style=&quot;color: #6a9955;&quot;&gt;// out of grid&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        }        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; grid[i][j] == &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: #6a9955;&quot;&gt;// should be obstacle free&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;reachedBack&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[][] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;grid&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;j&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; i==&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; j==&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; grid[i][j] == &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#2. Toate submultimile unei multimi (recursivitate)&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: &amp;quot;Droid Sans Mono&amp;quot;, &amp;quot;monospace&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;subsets&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;ArrayList&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(&lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;ArrayList&lt;/span&gt;&amp;lt;&amp;gt;());&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;addAll&lt;/span&gt;(&lt;span style=&quot;color: #dcdcaa;&quot;&gt;find&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;stream&lt;/span&gt;(nums).&lt;span style=&quot;color: #dcdcaa;&quot;&gt;boxed&lt;/span&gt;().&lt;span style=&quot;color: #dcdcaa;&quot;&gt;collect&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;Collectors&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;toList&lt;/span&gt;())));&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; result;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;find&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;set&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;set&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;size&lt;/span&gt;() == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;set&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;)));&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;ArrayList&lt;/span&gt;&amp;lt;&amp;gt;(); &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;set&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;))); &lt;span style=&quot;color: #6a9955;&quot;&gt;// primul element&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;subsets&lt;/span&gt; = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;find&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;set&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;subList&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #9cdcfe;&quot;&gt;set&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;size&lt;/span&gt;()));&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;addAll&lt;/span&gt;(subsets); &lt;span style=&quot;color: #6a9955;&quot;&gt;// submultimile din (A - primul elem)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;subset&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; subsets) {&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;subsetCopy&lt;/span&gt; = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;clone&lt;/span&gt;(subset);&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #6a9955;&quot;&gt;// adaug primul element la toate submultimile din (A - primul elem)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;subsetCopy&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;set&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;));&lt;/div&gt;&lt;div&gt;            &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(subsetCopy);&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; result;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;    &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;clone&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;set&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;clonedSet&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;ArrayList&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #9cdcfe;&quot;&gt;clonedSet&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;addAll&lt;/span&gt;(set);&lt;/div&gt;&lt;div&gt;        &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; clonedSet;&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#3. Inmultirea a doua numere fara a folosi * , doar prin adunari, scaderi sau deplasari de biti, in numar minim de operatii. (recursivitate)&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #1e1f22; color: #bcbec4;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 10,5pt;&quot;&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;MultiplyIntegers {&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public static int &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;solve&lt;/span&gt;(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;a, &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;b) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;minAb = Math.&lt;span style=&quot;font-style: italic;&quot;&gt;min&lt;/span&gt;(a, b);&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;maxAb = Math.&lt;span style=&quot;font-style: italic;&quot;&gt;max&lt;/span&gt;(a, b);&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;multiply&lt;/span&gt;(minAb, maxAb); &lt;span style=&quot;color: #7a7e85;&quot;&gt;// to optimize the number of recursions&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private static int &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;multiply&lt;/span&gt;(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;a, &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;b) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(a == &lt;span style=&quot;color: #2aacb8;&quot;&gt;0 &lt;/span&gt;|| b == &lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(a == &lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;b;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// a is even =&amp;gt; multiply(a,b) = 2 * multiply(a/2, b)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        // a is odd =&amp;gt; multiply(a,b) = 2 * multiply(a/2, b) + b&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;partialRes = &lt;span style=&quot;font-style: italic;&quot;&gt;multiply&lt;/span&gt;(a &amp;gt;&amp;gt; &lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;, b); &lt;span style=&quot;color: #7a7e85;&quot;&gt;// multiply (a/2, b)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;partialRes &amp;lt;&amp;lt;= &lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;; &lt;span style=&quot;color: #7a7e85;&quot;&gt;// partialRes *= 2&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(a % &lt;span style=&quot;color: #2aacb8;&quot;&gt;2 &lt;/span&gt;== &lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;) {&lt;br /&gt;            partialRes += b;&lt;br /&gt;        }&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;partialRes;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;test&lt;/span&gt;() {&lt;br /&gt;        List&amp;lt;TestCase&amp;gt; testCases = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #2aacb8;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;15&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #2aacb8;&quot;&gt;10&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;7&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;70&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #2aacb8;&quot;&gt;31&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;35&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;1085&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #2aacb8;&quot;&gt;16&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;96&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #2aacb8;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #2aacb8;&quot;&gt;27&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;108&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #2aacb8;&quot;&gt;36475&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;4249&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;154982275&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #2aacb8;&quot;&gt;4585&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;42339&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;194124315&lt;/span&gt;));&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;long &lt;/span&gt;startTime = System.&lt;span style=&quot;font-style: italic;&quot;&gt;nanoTime&lt;/span&gt;();&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;for &lt;/span&gt;(TestCase testCase : testCases) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;result = MultiplyIntegers.&lt;span style=&quot;font-style: italic;&quot;&gt;solve&lt;/span&gt;(testCase.&lt;span style=&quot;color: #c77dbb;&quot;&gt;a&lt;/span&gt;, testCase.&lt;span style=&quot;color: #c77dbb;&quot;&gt;b&lt;/span&gt;);&lt;br /&gt;            System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Test case #&quot; &lt;/span&gt;+ testCases.indexOf(testCase) + &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; &quot; &lt;/span&gt;+&lt;br /&gt;                    (result == testCase.&lt;span style=&quot;color: #c77dbb;&quot;&gt;result &lt;/span&gt;?&lt;br /&gt;                            &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;PASSED&quot; &lt;/span&gt;:&lt;br /&gt;                            &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;FAILED with output=&quot; &lt;/span&gt;+ result + &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; &quot; &lt;/span&gt;+&lt;br /&gt;                                    &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;[expected=&quot; &lt;/span&gt;+ testCase.&lt;span style=&quot;color: #c77dbb;&quot;&gt;result &lt;/span&gt;+ &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;] &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;\t\t&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&amp;lt;------&quot;&lt;/span&gt;));&lt;br /&gt;        }&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;long &lt;/span&gt;endTime = System.&lt;span style=&quot;font-style: italic;&quot;&gt;nanoTime&lt;/span&gt;();&lt;br /&gt;        System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Executed in &quot; &lt;/span&gt;+ (endTime - startTime)/&lt;span style=&quot;color: #2aacb8;&quot;&gt;1000000 &lt;/span&gt;+ &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; ms.&quot;&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public static void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;main&lt;/span&gt;(String args[]) {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;MultiplyIntegers().test();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;TestCase {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public final int &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;a&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public final int &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;b&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public final int &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;result&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;TestCase&lt;/span&gt;(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;a, &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;b, &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;result) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;a &lt;/span&gt;= a;&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;b &lt;/span&gt;= b;&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;result &lt;/span&gt;= result;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#4. Turnurile din Hanoi&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Se dau 3 turnuri: A, B, C. Pe fiecare turn se pot aseza discuri aranjate descrescator, cele mai mari stand la baza si cele mai mici deasupra. Sa se mute toate discurile din A in C, folosind B ca intermediar, respectand conditia. Care e numarul minim de miscari pentru a realiza acest transfer?&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Nota&lt;/b&gt;: se porneste de la cazul de baza - 1 disc, care are nevoie de o singura miscare pt a ajunge in C. Apoi simulam pe hartie ce se intampla cand avem 2 discuri. Apoi 3. De fiecare data se poate observa (de la n &amp;gt;= 2) ca turnul B se comporta ca un buffer. De asemenea, pentru a rezolva cazuri superioare, ne putem folosi de rezultatul anterior deja calculat, la care mai avem de mutat un singur disc (ultimul). Astfel: pentru a muta n discuri, trebuie sa mutam n-1 discuri din A in B (folosind C ca intermediar) pentru a lasa liber ultimul disc din A, apoi mutat direct discul din A in C, apoi mutate cele n-1 discuri din B in C (folosind A ca intermediar). Se observa ca numarul de mutari este 2^n - 1.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Nota&lt;/b&gt;: design-ul solutiei. Obiectele Disk si Tower sunt &quot;personalizate&quot;. Am facut cateva validari. Tower detine o stiva de obiecte Disk. Adaugarea se face intr-o metoda din Tower afectand un alt obiect Tower din care se scoate un disc.&lt;/p&gt;&lt;div style=&quot;background-color: #1e1f22; color: #bcbec4;&quot;&gt;&lt;pre style=&quot;font-family: &#39;JetBrains Mono&#39;,monospace; font-size: 10,5pt;&quot;&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;import &lt;/span&gt;java.util.*;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;Hanoi {&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;private int &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;moveDisks &lt;/span&gt;(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;n, Tower origin, Tower destination, Tower buffer) &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throws &lt;/span&gt;Exception {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(n == &lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;) {&lt;br /&gt;            destination.takeFrom(origin);&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;; &lt;span style=&quot;color: #7a7e85;&quot;&gt;// one move&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;steps = &lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        steps += moveDisks(n-&lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;, origin, buffer, destination); &lt;span style=&quot;color: #7a7e85;&quot;&gt;// move first n-1 from origin to buffer&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;destination.takeFrom(origin);                            &lt;span style=&quot;color: #7a7e85;&quot;&gt;// move last element from origin to dest&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;steps++;&lt;br /&gt;        steps += moveDisks(n-&lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;, buffer, destination, origin); &lt;span style=&quot;color: #7a7e85;&quot;&gt;// move back n-1 elements from buffer to dest&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;steps;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public static void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;main&lt;/span&gt;(String args[]) {&lt;br /&gt;        Hanoi hanoi = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Hanoi();&lt;br /&gt;        hanoi.test();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;test&lt;/span&gt;() {&lt;br /&gt;        Hanoi hanoi = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Hanoi();&lt;br /&gt;&lt;br /&gt;        List&amp;lt;Disk&amp;gt; disks = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;        disks.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Disk(&lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;5&lt;/span&gt;));&lt;br /&gt;        disks.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Disk(&lt;span style=&quot;color: #2aacb8;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;2&lt;/span&gt;));&lt;br /&gt;        disks.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Disk(&lt;span style=&quot;color: #2aacb8;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;8&lt;/span&gt;));&lt;br /&gt;        disks.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Disk(&lt;span style=&quot;color: #2aacb8;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;));&lt;br /&gt;        disks.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Disk(&lt;span style=&quot;color: #2aacb8;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;3&lt;/span&gt;));&lt;br /&gt;        disks.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Disk(&lt;span style=&quot;color: #2aacb8;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;4&lt;/span&gt;));&lt;br /&gt;        disks.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Disk(&lt;span style=&quot;color: #2aacb8;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;7&lt;/span&gt;));&lt;br /&gt;        disks.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Disk(&lt;span style=&quot;color: #2aacb8;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;6&lt;/span&gt;));&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #7a7e85;&quot;&gt;// hanoi(n) = 2^n - 1&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #7a7e85;&quot;&gt;        &lt;/span&gt;List&amp;lt;TestCase&amp;gt; testCases = &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;A&quot;&lt;/span&gt;, disks.subList(&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;)), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;B&quot;&lt;/span&gt;), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;C&quot;&lt;/span&gt;), &lt;span style=&quot;color: #2aacb8;&quot;&gt;1&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;A&quot;&lt;/span&gt;, disks.subList(&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;2&lt;/span&gt;)), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;B&quot;&lt;/span&gt;), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;C&quot;&lt;/span&gt;), &lt;span style=&quot;color: #2aacb8;&quot;&gt;3&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;A&quot;&lt;/span&gt;, disks.subList(&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;3&lt;/span&gt;)), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;B&quot;&lt;/span&gt;), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;C&quot;&lt;/span&gt;), &lt;span style=&quot;color: #2aacb8;&quot;&gt;7&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;A&quot;&lt;/span&gt;, disks.subList(&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;4&lt;/span&gt;)), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;B&quot;&lt;/span&gt;), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;C&quot;&lt;/span&gt;), &lt;span style=&quot;color: #2aacb8;&quot;&gt;15&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;A&quot;&lt;/span&gt;, disks.subList(&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;5&lt;/span&gt;)), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;B&quot;&lt;/span&gt;), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;C&quot;&lt;/span&gt;), &lt;span style=&quot;color: #2aacb8;&quot;&gt;31&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;A&quot;&lt;/span&gt;, disks.subList(&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;6&lt;/span&gt;)), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;B&quot;&lt;/span&gt;), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;C&quot;&lt;/span&gt;), &lt;span style=&quot;color: #2aacb8;&quot;&gt;63&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;A&quot;&lt;/span&gt;, disks.subList(&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #2aacb8;&quot;&gt;7&lt;/span&gt;)), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;B&quot;&lt;/span&gt;), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;C&quot;&lt;/span&gt;), &lt;span style=&quot;color: #2aacb8;&quot;&gt;127&lt;/span&gt;));&lt;br /&gt;        testCases.add(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;A&quot;&lt;/span&gt;, disks), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;B&quot;&lt;/span&gt;), &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Tower(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;C&quot;&lt;/span&gt;), &lt;span style=&quot;color: #2aacb8;&quot;&gt;255&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;for &lt;/span&gt;(TestCase tc : testCases) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;try &lt;/span&gt;{&lt;br /&gt;                &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;numberOfDisks = tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;origin&lt;/span&gt;.getNumberOfDisks();&lt;br /&gt;                &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;res = hanoi.moveDisks(numberOfDisks, tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;origin&lt;/span&gt;, tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;destination&lt;/span&gt;, tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;buffer&lt;/span&gt;);&lt;br /&gt;                &lt;span style=&quot;color: #cf8e6d;&quot;&gt;boolean &lt;/span&gt;testResult = res == tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;expectedMoves &lt;/span&gt;&amp;amp;&amp;amp; tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;origin&lt;/span&gt;.getNumberOfDisks() == &lt;span style=&quot;color: #2aacb8;&quot;&gt;0 &lt;/span&gt;&amp;amp;&amp;amp;&lt;br /&gt;                        tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;buffer&lt;/span&gt;.getNumberOfDisks() == &lt;span style=&quot;color: #2aacb8;&quot;&gt;0 &lt;/span&gt;&amp;amp;&amp;amp;&lt;br /&gt;                        tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;destination&lt;/span&gt;.getNumberOfDisks() == numberOfDisks;&lt;br /&gt;                System.&lt;span style=&quot;color: #c77dbb; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Test case #&quot; &lt;/span&gt;+ testCases.indexOf(tc) + &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; &quot; &lt;/span&gt;+&lt;br /&gt;                        (testResult ?&lt;br /&gt;                                &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;PASSED&quot; &lt;/span&gt;:&lt;br /&gt;                                &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;FAILED with moves=&quot; &lt;/span&gt;+ res + &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; &quot; &lt;/span&gt;+&lt;br /&gt;                                        &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;[expected.moves=&quot; &lt;/span&gt;+ tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;expectedMoves &lt;/span&gt;+ &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;] AND &quot; &lt;/span&gt;+&lt;br /&gt;                                        &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;with origin.size=&quot; &lt;/span&gt;+ tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;origin&lt;/span&gt;.getNumberOfDisks() + &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; AND &quot; &lt;/span&gt;+&lt;br /&gt;                                        &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;with buffer.size=&quot; &lt;/span&gt;+ tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;buffer&lt;/span&gt;.getNumberOfDisks() + &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; AND &quot; &lt;/span&gt;+&lt;br /&gt;                                        &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;with destination.size=&quot; &lt;/span&gt;+ tc.&lt;span style=&quot;color: #c77dbb;&quot;&gt;destination&lt;/span&gt;.getNumberOfDisks() +&lt;br /&gt;                                        &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; [expected.dest.size=&quot; &lt;/span&gt;+ numberOfDisks + &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;] &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;\t\t&lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&amp;lt;------&quot;&lt;/span&gt;));&lt;br /&gt;            } &lt;span style=&quot;color: #cf8e6d;&quot;&gt;catch &lt;/span&gt;(Exception e) {&lt;br /&gt;                e.printStackTrace();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;class &lt;/span&gt;Tower {&lt;br /&gt;        String &lt;span style=&quot;color: #c77dbb;&quot;&gt;label&lt;/span&gt;;&lt;br /&gt;        Stack&amp;lt;Disk&amp;gt; &lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;Tower&lt;/span&gt;(String label) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;label &lt;/span&gt;= label;&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;disks &lt;/span&gt;= &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Stack&amp;lt;&amp;gt;();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;Tower&lt;/span&gt;(String label, List&amp;lt;Disk&amp;gt; initDisks) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;label &lt;/span&gt;= label;&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;disks &lt;/span&gt;= &lt;span style=&quot;color: #cf8e6d;&quot;&gt;new &lt;/span&gt;Stack&amp;lt;&amp;gt;();&lt;br /&gt;            Collections.&lt;span style=&quot;font-style: italic;&quot;&gt;sort&lt;/span&gt;(initDisks);&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;for &lt;/span&gt;(Disk disk : initDisks) {&lt;br /&gt;                &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;.push(disk);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;takeFrom&lt;/span&gt;(Tower from) &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throws &lt;/span&gt;Exception {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(from.&lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;.isEmpty()) {&lt;br /&gt;                &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throw new &lt;/span&gt;Exception(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Nothing to add from!&quot;&lt;/span&gt;);&lt;br /&gt;            }&lt;br /&gt;            Disk diskToAdd = from.&lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;.peek();&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(!&lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;.isEmpty() &amp;amp;&amp;amp; diskToAdd.&lt;span style=&quot;color: #c77dbb;&quot;&gt;value &lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;.peek().&lt;span style=&quot;color: #c77dbb;&quot;&gt;value&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: #cf8e6d;&quot;&gt;throw new &lt;/span&gt;Exception(&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Cannot add disk with value &quot; &lt;/span&gt;+ diskToAdd.&lt;span style=&quot;color: #c77dbb;&quot;&gt;value &lt;/span&gt;+ &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; to tower &quot; &lt;/span&gt;+ &lt;span style=&quot;color: #c77dbb;&quot;&gt;label&lt;/span&gt;);&lt;br /&gt;            }&lt;br /&gt;            &lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;.push(from.&lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;.pop());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public int &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;getNumberOfDisks&lt;/span&gt;() {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;.size();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #b3ae60;&quot;&gt;@Override&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public &lt;/span&gt;String &lt;span style=&quot;color: #56a8f5;&quot;&gt;toString&lt;/span&gt;() {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #6aab73;&quot;&gt;&quot;Tower &quot; &lt;/span&gt;+ &lt;span style=&quot;color: #c77dbb;&quot;&gt;label &lt;/span&gt;+ &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; has &quot; &lt;/span&gt;+ &lt;span style=&quot;color: #c77dbb;&quot;&gt;disks&lt;/span&gt;.size() + &lt;span style=&quot;color: #6aab73;&quot;&gt;&quot; disks.&quot;&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;class &lt;/span&gt;Disk &lt;span style=&quot;color: #cf8e6d;&quot;&gt;implements &lt;/span&gt;Comparable&amp;lt;Disk&amp;gt; {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;label&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;value&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;Disk&lt;/span&gt;(&lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;label, &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;value) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;label &lt;/span&gt;= label;&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;value &lt;/span&gt;= value;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #b3ae60;&quot;&gt;@Override&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #b3ae60;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cf8e6d;&quot;&gt;public int &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;compareTo&lt;/span&gt;(Disk disk) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;if &lt;/span&gt;(disk.&lt;span style=&quot;color: #c77dbb;&quot;&gt;value &lt;/span&gt;== &lt;span style=&quot;color: #c77dbb;&quot;&gt;value&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #2aacb8;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;return &lt;/span&gt;disk.&lt;span style=&quot;color: #c77dbb;&quot;&gt;value &lt;/span&gt;- &lt;span style=&quot;color: #c77dbb;&quot;&gt;value&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public class &lt;/span&gt;TestCase {&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public final &lt;/span&gt;Tower &lt;span style=&quot;color: #c77dbb;&quot;&gt;origin&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public final &lt;/span&gt;Tower &lt;span style=&quot;color: #c77dbb;&quot;&gt;buffer&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public final &lt;/span&gt;Tower &lt;span style=&quot;color: #c77dbb;&quot;&gt;destination&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public final int &lt;/span&gt;&lt;span style=&quot;color: #c77dbb;&quot;&gt;expectedMoves&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #cf8e6d;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #56a8f5;&quot;&gt;TestCase&lt;/span&gt;(Tower tower, Tower buffer, Tower destination, &lt;span style=&quot;color: #cf8e6d;&quot;&gt;int &lt;/span&gt;expectedMoves) {&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;origin &lt;/span&gt;= tower;&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;buffer &lt;/span&gt;= buffer;&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;destination &lt;/span&gt;= destination;&lt;br /&gt;            &lt;span style=&quot;color: #cf8e6d;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #c77dbb;&quot;&gt;expectedMoves &lt;/span&gt;= expectedMoves;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/2249474909864719331/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/2249474909864719331?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/2249474909864719331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/2249474909864719331'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/07/probleme-programare-dinamica.html' title='Probleme programare dinamică &amp; recursivitate (1)'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-9138588729585106883</id><published>2024-07-09T18:31:00.006+03:00</published><updated>2024-07-10T12:42:57.151+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interviu"/><category scheme="http://www.blogger.com/atom/ns#" term="technical task"/><title type='text'>Amazon &quot;code assessment&quot;</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;1. Student prep for test&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Un student se pregateste de un examen, are de studiat o carte impartita in capitole: pages[i] reprezinta nr. de pagini per capitole. El are la dispozitie un numar maxim de zile de pregatire pana la examen si ar vrea sa citeasca cat mai putin pe zi, daca se poate. De fiecare data cand se termina capitolul, studentul incheie ziua si incepe cu urmatorul capitol in urmatoarea zi. Sa se afle numarul minim de pagini/zi pe care trebuie sa le citeasca pentru a fi gata la timp.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Ex.: pages = [2,3,4,5] si days=5 . Daca citeste 4 pagini/zi, in primele 3 zile citeste 3 capitole, iar al patrulea il face in 2 zile (4+1 pagini). Daca ar citi mai putin, nu s-ar incadra in timp.&lt;/p&gt;&lt;div style=&quot;background-color: white; color: #080808;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9,8pt;&quot;&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;package &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;amazon&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.&lt;/span&gt;*;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;StudentExam &lt;/span&gt;{&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public static int &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;minimumNumberOfPages&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;days&lt;/span&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;.isEmpty()) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;.size() &amp;gt; &lt;span style=&quot;color: black;&quot;&gt;days&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;-&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;max &lt;/span&gt;= &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;page &lt;/span&gt;: &lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;page &lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;max&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;max &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;page&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;.size() == &lt;span style=&quot;color: black;&quot;&gt;days&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;max&lt;/span&gt;;&lt;br /&gt;        }&lt;span style=&quot;color: #8c8c8c; font-style: italic;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #8c8c8c; font-style: italic;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #8c8c8c; font-style: italic;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;solve_kiss_approach&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;days&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public static int &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;solve_kiss_approach&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;days&lt;/span&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;totalPages &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;.stream().reduce((&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;,&lt;span style=&quot;color: black;&quot;&gt;b&lt;/span&gt;) -&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;+&lt;span style=&quot;color: black;&quot;&gt;b&lt;/span&gt;).get();&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;pagesPerDay &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;totalPages &lt;/span&gt;% &lt;span style=&quot;color: black;&quot;&gt;days &lt;/span&gt;== &lt;span style=&quot;color: #1750eb;&quot;&gt;0 &lt;/span&gt;? &lt;span style=&quot;color: black;&quot;&gt;totalPages&lt;/span&gt;/&lt;span style=&quot;color: black;&quot;&gt;days &lt;/span&gt;: &lt;span style=&quot;color: black;&quot;&gt;totalPages&lt;/span&gt;/&lt;span style=&quot;color: black;&quot;&gt;days&lt;/span&gt;+&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;while &lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;true&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;neededDays &lt;/span&gt;= &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;.size(); &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;++) {&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;neededDays &lt;/span&gt;+= &lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;) % &lt;span style=&quot;color: black;&quot;&gt;pagesPerDay &lt;/span&gt;== &lt;span style=&quot;color: #1750eb;&quot;&gt;0 &lt;/span&gt;? &lt;br /&gt;                        &lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;) / &lt;span style=&quot;color: black;&quot;&gt;pagesPerDay &lt;/span&gt;: &lt;br /&gt;                        &lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;)/&lt;span style=&quot;color: black;&quot;&gt;pagesPerDay&lt;/span&gt;+&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;neededDays &lt;/span&gt;&amp;lt;= &lt;span style=&quot;color: black;&quot;&gt;days&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;pagesPerDay&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;            &lt;span style=&quot;color: black;&quot;&gt;pagesPerDay&lt;/span&gt;++;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public static void &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;main&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;String args&lt;/span&gt;[]) {&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;StudentExam().test();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;test&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;TestCase&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;testCases &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;, -&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;8&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;9&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;7&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;20&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;30&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;25&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;9&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;13&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;30&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;25&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;20&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;12&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;9&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;70&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;12&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;9&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;15&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;15&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;16&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;20&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;11&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;12&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;8&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase (&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;100&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;TestCase testCase &lt;/span&gt;: &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;result &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;StudentExam&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;minimumNumberOfPages&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;pages&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;days&lt;/span&gt;);&lt;br /&gt;            &lt;span style=&quot;color: black;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #871094; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;Test case #&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.indexOf(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;) + &lt;span style=&quot;color: #067d17;&quot;&gt;&quot; &quot; &lt;/span&gt;+&lt;br /&gt;                    (&lt;span style=&quot;color: black;&quot;&gt;result &lt;/span&gt;== &lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;expectedResult &lt;/span&gt;?&lt;br /&gt;                            &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;PASSED&quot; &lt;/span&gt;:&lt;br /&gt;                            &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;FAILED with output=&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;result &lt;/span&gt;+ &lt;span style=&quot;color: #067d17;&quot;&gt;&quot; &quot; &lt;/span&gt;+&lt;br /&gt;                                    &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;[expected=&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;expectedResult &lt;/span&gt;+ &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;] &lt;/span&gt;&lt;span style=&quot;color: #0037a6;&quot;&gt;\t\t&lt;/span&gt;&lt;span style=&quot;color: #067d17;&quot;&gt;&amp;lt;------&quot;&lt;/span&gt;));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;TestCase &lt;/span&gt;{&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #871094;&quot;&gt;pages&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final int &lt;/span&gt;&lt;span style=&quot;color: #871094;&quot;&gt;days&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final int &lt;/span&gt;&lt;span style=&quot;color: #871094;&quot;&gt;expectedResult&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;TestCase&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;days&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;pagesPerDay&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;pages &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;pages&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;days &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;days&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;expectedResult &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;pagesPerDay&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;2. Market trends of Amazon stocks&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Se da un array reprezentand profiturile pe un numar de luni consecutive, initial toate valorile sunt pozitive (castig). Sa se afle numarul maxim de luni ale caror valori pot fi transformate in pierdere (inmultindu-le cu -1), astfel incat profitul cumulat de la luna la luna sa reprezinte totusi castig.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Ex.: PnL = [5,3,1,2], daca il transformam in [5,-3,-1,2] =&amp;gt; profitul cumulat este [5, 2, 1, 3] cu toate valorile pozitive =&amp;gt; 2 elemente s-au putut negativiza si nu exista o solutie cu 3 elemente negativizate.&lt;/p&gt;&lt;div style=&quot;background-color: white; color: #080808;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9,8pt;&quot;&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;package &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;amazon&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.ArrayList&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.Arrays&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.List&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;AmazonStocks &lt;/span&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public static int &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;getMaxNegativePnL&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;PnL&lt;/span&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;maxCumul &lt;/span&gt;= &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;PnL&lt;/span&gt;.size(); &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;++) {&lt;br /&gt;            &lt;span style=&quot;color: black;&quot;&gt;maxCumul &lt;/span&gt;+= &lt;span style=&quot;color: black;&quot;&gt;PnL&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;num &lt;/span&gt;= &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: black;&quot;&gt;PnL&lt;/span&gt;.size()-&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;; &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;&amp;gt;=&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;; &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;--) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;maxCumul &lt;/span&gt;- &lt;span style=&quot;color: black;&quot;&gt;PnL&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;)*&lt;span style=&quot;color: #1750eb;&quot;&gt;2 &lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;maxCumul &lt;/span&gt;-= &lt;span style=&quot;color: black;&quot;&gt;PnL&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;)*&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;;&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;num&lt;/span&gt;++;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;num&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public static void &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;main&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;String args&lt;/span&gt;[]) {&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;AmazonStocks().test();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;test&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;TestCase&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;testCases &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;10&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;9&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;), &lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;TestCase testCase &lt;/span&gt;: &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;res &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;AmazonStocks&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;getMaxNegativePnL&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;pnl&lt;/span&gt;);&lt;br /&gt;            &lt;span style=&quot;color: black;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #871094; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;Test case #&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.indexOf(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;) + &lt;span style=&quot;color: #067d17;&quot;&gt;&quot; &quot; &lt;/span&gt;+&lt;br /&gt;                    (&lt;span style=&quot;color: black;&quot;&gt;res &lt;/span&gt;== &lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;result &lt;/span&gt;? &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;PASSED&quot; &lt;/span&gt;: &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;FAILED with output=&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;res &lt;/span&gt;+&lt;br /&gt;                            &lt;span style=&quot;color: #067d17;&quot;&gt;&quot; [expected=&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;result &lt;/span&gt;+ &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;] &amp;lt;------&quot;&lt;/span&gt;));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;TestCase &lt;/span&gt;{&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #871094;&quot;&gt;pnl&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final int &lt;/span&gt;&lt;span style=&quot;color: #871094;&quot;&gt;result&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;TestCase&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;pnl&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;result&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;pnl &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;pnl&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;result &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;result&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Bonus Demo #1: Optimizing Box Weights&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Se da un array de greutati ale unor cutii, se cere impartirea acestor valori in 2 multimi A si B cu urmatoarele conditii:&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;A intersectat cu B = vid&lt;/li&gt;&lt;li&gt;A reunit cu B = arr&lt;/li&gt;&lt;li&gt;A are numar minim de elemente&lt;/li&gt;&lt;li&gt;sum(A) &amp;gt; sum(B)&lt;/li&gt;&lt;li&gt;A trebuie returnat in ordine crescatoare&lt;/li&gt;&lt;li&gt;daca exista mai multe multimi A, se returneaza cea cu greutate totala maxima&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Ex.: arr = [1, 12, 5, 5, 7] =&amp;gt; A = [7, 12]&lt;/p&gt;&lt;div style=&quot;background-color: white; color: #080808;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9,8pt;&quot;&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;package &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;amazon.demo&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.ArrayList&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.Arrays&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.Comparator&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.List&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.concurrent.atomic.AtomicInteger&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;SetProblem &lt;/span&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public static &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #00627a;&quot;&gt;minimalHeaviestSetA&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;arr&lt;/span&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;arr&lt;/span&gt;.sort(&lt;span style=&quot;color: black;&quot;&gt;Comparator&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;reverseOrder&lt;/span&gt;());&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;AtomicInteger totalSum &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;AtomicInteger(&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;);&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;arr&lt;/span&gt;.forEach(&lt;span style=&quot;color: black;&quot;&gt;elem &lt;/span&gt;-&amp;gt; &lt;span style=&quot;color: #851691;&quot;&gt;totalSum&lt;/span&gt;.set(&lt;span style=&quot;color: #851691;&quot;&gt;totalSum&lt;/span&gt;.get() + &lt;span style=&quot;color: black;&quot;&gt;elem&lt;/span&gt;));&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;A &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;aSum &lt;/span&gt;= &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;elem &lt;/span&gt;: &lt;span style=&quot;color: black;&quot;&gt;arr&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: black;&quot;&gt;A&lt;/span&gt;.add(&lt;span style=&quot;color: black;&quot;&gt;elem&lt;/span&gt;);&lt;br /&gt;            &lt;span style=&quot;color: black;&quot;&gt;aSum &lt;/span&gt;+= &lt;span style=&quot;color: black;&quot;&gt;elem&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;aSum &lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;totalSum&lt;/span&gt;.get() - &lt;span style=&quot;color: black;&quot;&gt;aSum&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;A&lt;/span&gt;.sort(&lt;span style=&quot;color: black;&quot;&gt;Comparator&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;naturalOrder&lt;/span&gt;());&lt;br /&gt;                &lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;A&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;return new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public static void &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;main&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;String&lt;/span&gt;[] &lt;span style=&quot;color: black;&quot;&gt;args&lt;/span&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;SetProblem().test();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;test&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;TestCase&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;testCases &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;12&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;7&lt;/span&gt;), &lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;7&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;12&lt;/span&gt;)));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;70&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;), &lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;70&lt;/span&gt;)));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;15&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;15&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;16&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;20&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;11&lt;/span&gt;), &lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;15&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;16&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;20&lt;/span&gt;)));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;), &lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;)));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;10&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;9&lt;/span&gt;), &lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;9&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;10&lt;/span&gt;)));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;10&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;12&lt;/span&gt;), &lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;12&lt;/span&gt;)));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(), &lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;()));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;6&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;7&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;10&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;), &lt;span style=&quot;color: black;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;asList&lt;/span&gt;(&lt;span style=&quot;color: #1750eb;&quot;&gt;7&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;10&lt;/span&gt;)));&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;TestCase testCase &lt;/span&gt;: &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;result &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;SetProblem&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;minimalHeaviestSetA&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;arr&lt;/span&gt;);&lt;br /&gt;            &lt;span style=&quot;color: black;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #871094; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;Test case #&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.indexOf(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;) + &lt;span style=&quot;color: #067d17;&quot;&gt;&quot; &quot; &lt;/span&gt;+&lt;br /&gt;                    (&lt;span style=&quot;color: black;&quot;&gt;result&lt;/span&gt;.equals(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;result&lt;/span&gt;) ? &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;PASSED&quot; &lt;/span&gt;: &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;FAILED with output=&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;result &lt;/span&gt;+&lt;br /&gt;                            &lt;span style=&quot;color: #067d17;&quot;&gt;&quot; [expected=&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;result &lt;/span&gt;+ &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;] &amp;lt;------&quot;&lt;/span&gt;));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;TestCase &lt;/span&gt;{&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #871094;&quot;&gt;arr&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #871094;&quot;&gt;result&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;TestCase&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;arr&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;result&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;arr &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;arr&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;result &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;result&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Bonus Demo #2: Items in containers&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Se da un string compus din caracterele &#39;*&#39; pentru un obiect si &#39;|&#39; pentru delimitarea unui compartiment. Se cere sa se afle toate obiectele aflate intre pozitiile &lt;i&gt;start&lt;/i&gt; si &lt;i&gt;stop&lt;/i&gt; din acel string, cu conditia ca obiectul sa apartina unui compartiment inchis (intre doua caractere &#39;|&#39;).&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Ex.:&amp;nbsp;&quot;|*|**|*|&quot; , start = 1, stop = 5 =&amp;gt; se afla 2 obiecte (numerotarea incepe de la 0, start/stop sunt inclusive)&lt;/p&gt;&lt;div style=&quot;background-color: white; color: #080808;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9,8pt;&quot;&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;package &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;amazon.demo&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.&lt;/span&gt;*;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Containers &lt;/span&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;private &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #00627a;&quot;&gt;buildMap&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;String input&lt;/span&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;countMap &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TreeMap&amp;lt;&amp;gt;(); &lt;span style=&quot;color: #8c8c8c; font-style: italic;&quot;&gt;// the keys are sorted asc&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #8c8c8c; font-style: italic;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;count &lt;/span&gt;= &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;indexStart &lt;/span&gt;= -&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;input&lt;/span&gt;.length(); &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;++) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;input&lt;/span&gt;.charAt(&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;) == &lt;span style=&quot;color: #067d17;&quot;&gt;&#39;|&#39;&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;indexStart &lt;/span&gt;&amp;gt;= &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;) {&lt;br /&gt;                    &lt;span style=&quot;color: black;&quot;&gt;countMap&lt;/span&gt;.put(&lt;span style=&quot;color: black;&quot;&gt;indexStart&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;count&lt;/span&gt;);&lt;br /&gt;                }&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;indexStart &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;;&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;count &lt;/span&gt;= &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;            } &lt;span style=&quot;color: #0033b3;&quot;&gt;else if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;input&lt;/span&gt;.charAt(&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;) == &lt;span style=&quot;color: #067d17;&quot;&gt;&#39;*&#39;&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;count&lt;/span&gt;++;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;countMap&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #8c8c8c; font-style: italic;&quot;&gt;// key: indexFrom, value: number of items&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #8c8c8c; font-style: italic;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;private int &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;find&lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;from&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;to&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;map&lt;/span&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;to &lt;/span&gt;- &lt;span style=&quot;color: black;&quot;&gt;from &lt;/span&gt;&amp;lt; &lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;count &lt;/span&gt;= &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;boolean &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;started &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;key &lt;/span&gt;: &lt;span style=&quot;color: black;&quot;&gt;map&lt;/span&gt;.keySet()) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;if &lt;/span&gt;(!&lt;span style=&quot;color: black;&quot;&gt;started &lt;/span&gt;&amp;amp;&amp;amp; &lt;span style=&quot;color: black;&quot;&gt;key &lt;/span&gt;&amp;gt;= &lt;span style=&quot;color: black;&quot;&gt;from &lt;/span&gt;&amp;amp;&amp;amp; &lt;span style=&quot;color: black;&quot;&gt;to &lt;/span&gt;&amp;gt;= &lt;span style=&quot;color: black;&quot;&gt;key &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;map&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;key&lt;/span&gt;) + &lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;count &lt;/span&gt;+= &lt;span style=&quot;color: black;&quot;&gt;map&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;key&lt;/span&gt;);&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;started &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;true&lt;/span&gt;;&lt;br /&gt;            } &lt;span style=&quot;color: #0033b3;&quot;&gt;else if &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;started &lt;/span&gt;&amp;amp;&amp;amp; &lt;span style=&quot;color: black;&quot;&gt;to &lt;/span&gt;&amp;gt;= &lt;span style=&quot;color: black;&quot;&gt;key &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;map&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;key&lt;/span&gt;) + &lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;) {&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;count &lt;/span&gt;+= &lt;span style=&quot;color: black;&quot;&gt;map&lt;/span&gt;.get(&lt;span style=&quot;color: black;&quot;&gt;key&lt;/span&gt;);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;count&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public static void &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;main&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;String&lt;/span&gt;[] &lt;span style=&quot;color: black;&quot;&gt;args&lt;/span&gt;) {&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;Containers().test();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;test&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;TestCase&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;testCases &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;ArrayList&amp;lt;&amp;gt;();&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;|*|**|*|&quot;&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;new int&lt;/span&gt;[]{&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;7&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;15&lt;/span&gt;},&lt;br /&gt;                &lt;span style=&quot;color: #0033b3;&quot;&gt;new int&lt;/span&gt;[]{&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;7&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;7&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;7&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;17&lt;/span&gt;}, &lt;span style=&quot;color: #0033b3;&quot;&gt;new int&lt;/span&gt;[]{&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;}));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;|**|*|*&quot;&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;new int&lt;/span&gt;[]{&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;},&lt;br /&gt;                &lt;span style=&quot;color: #0033b3;&quot;&gt;new int&lt;/span&gt;[]{&lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;6&lt;/span&gt;}, &lt;span style=&quot;color: #0033b3;&quot;&gt;new int&lt;/span&gt;[]{&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;}));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.add(&lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;TestCase(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;*|*|*|||**|&quot;&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;new int&lt;/span&gt;[]{&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;},&lt;br /&gt;                &lt;span style=&quot;color: #0033b3;&quot;&gt;new int&lt;/span&gt;[]{&lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;9&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;10&lt;/span&gt;,&lt;span style=&quot;color: #1750eb;&quot;&gt;10&lt;/span&gt;}, &lt;span style=&quot;color: #0033b3;&quot;&gt;new int&lt;/span&gt;[]{&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #1750eb;&quot;&gt;4&lt;/span&gt;}));&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;Containers containers &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;new &lt;/span&gt;Containers();&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;TestCase testCase &lt;/span&gt;: &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: black;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;occurrenceMap &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;containers&lt;/span&gt;.buildMap(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;input&lt;/span&gt;);&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;for &lt;/span&gt;(&lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #1750eb;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;start&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;length&lt;/span&gt;; &lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;++) {&lt;br /&gt;                &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;res &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;containers&lt;/span&gt;.find(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;start&lt;/span&gt;[&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;], &lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;stop&lt;/span&gt;[&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;], &lt;span style=&quot;color: black;&quot;&gt;occurrenceMap&lt;/span&gt;);&lt;br /&gt;                &lt;span style=&quot;color: black;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #871094; font-style: italic;&quot;&gt;out&lt;/span&gt;.println(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;Test case #&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;testCases&lt;/span&gt;.indexOf(&lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;) + &lt;span style=&quot;color: #067d17;&quot;&gt;&quot; &quot; &lt;/span&gt;+&lt;br /&gt;                        (&lt;span style=&quot;color: black;&quot;&gt;res &lt;/span&gt;== &lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;result&lt;/span&gt;[&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;] ? &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;PASSED&quot; &lt;/span&gt;: &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;FAILED with output=&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;res &lt;/span&gt;+&lt;br /&gt;                                &lt;span style=&quot;color: #067d17;&quot;&gt;&quot; [expected=&quot; &lt;/span&gt;+ &lt;span style=&quot;color: black;&quot;&gt;testCase&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;result&lt;/span&gt;[&lt;span style=&quot;color: black;&quot;&gt;i&lt;/span&gt;] + &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;] &amp;lt;------&quot;&lt;/span&gt;));&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;TestCase &lt;/span&gt;{&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;String &lt;/span&gt;&lt;span style=&quot;color: #871094;&quot;&gt;input&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final int&lt;/span&gt;[] &lt;span style=&quot;color: #871094;&quot;&gt;start&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final int&lt;/span&gt;[] &lt;span style=&quot;color: #871094;&quot;&gt;stop&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public final int&lt;/span&gt;[] &lt;span style=&quot;color: #871094;&quot;&gt;result&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;TestCase&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;String input&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: black;&quot;&gt;start&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: black;&quot;&gt;stop&lt;/span&gt;, &lt;span style=&quot;color: #0033b3;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: black;&quot;&gt;expectedResult&lt;/span&gt;) {&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;input &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;input&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;start &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;start&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;stop &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;stop&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;result &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;expectedResult&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/9138588729585106883/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/9138588729585106883?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/9138588729585106883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/9138588729585106883'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/07/amazon-code-assessment.html' title='Amazon &quot;code assessment&quot;'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-1642245969937605257</id><published>2024-06-27T19:31:00.002+03:00</published><updated>2024-06-28T10:40:05.533+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="catalog"/><category scheme="http://www.blogger.com/atom/ns#" term="Cracking the code interview"/><title type='text'>CATALOG Cracking the code interview </title><content type='html'>&lt;p&gt;&lt;b&gt;&lt;a href=&quot;https://boomblebee.blogspot.com/2015/03/probleme-pentru-interviu-structuri-de.html&quot;&gt;POST #1&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Șiruri de caractere&lt;/li&gt;&lt;li&gt;impl. Java pt. cap.1 Arrays &amp;amp; Strings&lt;b&gt;&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/06/cracking-coding-interview-revisited-6th.html&quot;&gt;aici&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Liste înlănțuite&lt;/li&gt;&lt;li&gt;Stive &amp;amp; cozi&lt;/li&gt;&lt;li&gt;Arbori binari și grafuri&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;https://boomblebee.blogspot.com/2015/03/probleme-pentru-interviu-operatii-pe.html&quot;&gt;POST #2&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Operații pe biți&lt;/li&gt;&lt;li&gt;Întrebări de sucit mințile&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;https://boomblebee.blogspot.com/2015/04/probleme-pentru-interviu-probabilitati.html&quot;&gt;POST #3&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Matematică, probabilități&lt;/li&gt;&lt;li&gt;OOP&lt;/li&gt;&lt;li&gt;Recursivitate și programare dinamică&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;https://boomblebee.blogspot.com/2015/05/probleme-pentru-interviu-scalabilitate.html&quot;&gt;POST #4&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Memorie și scalabilitate&lt;/li&gt;&lt;li&gt;Sortări și căutări&lt;/li&gt;&lt;li&gt;Testări&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;https://boomblebee.blogspot.com/2015/06/probleme-pt-interviu-c-java-database.html&quot;&gt;POST #5&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;C/C++&lt;/li&gt;&lt;li&gt;Java&lt;/li&gt;&lt;li&gt;Baze de date&lt;/li&gt;&lt;li&gt;Thread-uri, lock-uri&lt;/li&gt;&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/1642245969937605257/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/1642245969937605257?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/1642245969937605257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/1642245969937605257'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/06/catalog-cracking-code-interview.html' title='CATALOG Cracking the code interview '/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-1738329227215036493</id><published>2024-06-22T16:38:00.022+03:00</published><updated>2024-08-16T14:51:34.913+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="50dsa"/><category scheme="http://www.blogger.com/atom/ns#" term="catalog"/><category scheme="http://www.blogger.com/atom/ns#" term="interviu"/><title type='text'>CATALOG 50DSA </title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;span style=&quot;font-size: large;&quot;&gt;Array&lt;/span&gt;&lt;/p&gt;&lt;p&gt;1. &lt;a href=&quot;https://boomblebee.blogspot.com/2023/12/50-dsa-questions-1-2.html&quot;&gt;Two Sum&lt;/a&gt;&amp;nbsp;&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;2. &lt;a href=&quot;https://boomblebee.blogspot.com/2023/12/50-dsa-questions-1-2.html&quot;&gt;Best time to buy and sell stock&lt;/a&gt;&amp;nbsp;&lt;b style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://boomblebee.blogspot.com/2023/12/50-dsa-questions-3-4.html&quot;&gt;3. Contains duplicate&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://boomblebee.blogspot.com/2023/12/50-dsa-questions-3-4.html&quot;&gt;4. Product of array except self&lt;/a&gt;&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;5. &lt;a href=&quot;https://boomblebee.blogspot.com/2023/12/50-dsa-questions-5-6-7.html&quot;&gt;Maximum subarray&lt;/a&gt; &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;6. &lt;a href=&quot;https://boomblebee.blogspot.com/2023/12/50-dsa-questions-5-6-7.html&quot;&gt;Maximum product subarray&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;7. Find the minimum in rotated sorted array&lt;/p&gt;&lt;p&gt;8. Search in rotated sorted array&lt;/p&gt;&lt;p&gt;9. 3Sum&lt;/p&gt;&lt;p&gt;10. Container with most water&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Matrix&lt;/span&gt;&lt;/p&gt;&lt;p&gt;11. &lt;a href=&quot;https://boomblebee.blogspot.com/2023/12/50-dsa-questions-10-11.html&quot;&gt;Set matrix zeroes&lt;/a&gt; &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;12.&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/01/50-dsa-questions-12-13.html&quot;&gt;Spiral matrix&lt;/a&gt;&amp;nbsp;&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;13. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/01/50-dsa-questions-12-13.html?zx=b93af6dc7e23ec74&quot;&gt;Rotate image&lt;/a&gt;&amp;nbsp;&lt;b style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/b&gt;&lt;/p&gt;&lt;p&gt;14. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/01/50-dsa-questions-14.html&quot;&gt;Word Search&lt;/a&gt; &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;String&lt;/span&gt;&lt;/p&gt;&lt;p&gt;15.&amp;nbsp;Longest Substring Without Repeating Character&lt;/p&gt;&lt;p&gt;16.&amp;nbsp;Longest Repeating Character Replacement&lt;/p&gt;&lt;p&gt;17.&amp;nbsp;Minimum Window Substring&lt;/p&gt;&lt;p&gt;18.&amp;nbsp;Valid Anagram&lt;/p&gt;&lt;p&gt;19. Group Anagrams&lt;/p&gt;&lt;p&gt;20.&amp;nbsp;Valid Parentheses&lt;/p&gt;&lt;p&gt;21.&amp;nbsp;Longest Palindromic Substring&amp;nbsp;&lt;/p&gt;&lt;p&gt;22. Palindromic Substrings&lt;/p&gt;&lt;div&gt;23.&amp;nbsp;Encode and Decode Strings&amp;nbsp;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Linked List&lt;/span&gt;&lt;/p&gt;&lt;p&gt;24.&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/02/50-dsa-questions-23-24-25.html&quot;&gt;Reverse Linked Lists&lt;/a&gt;&amp;nbsp;&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;25. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/02/50-dsa-questions-23-24-25.html&quot;&gt;Linked List Cycle&lt;/a&gt;&amp;nbsp;&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;26. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/02/50-dsa-questions-26-27-28-29.html&quot;&gt;Merge two sorted lists&lt;/a&gt;&amp;nbsp;&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;27. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/02/50-dsa-questions-26-27-28-29.html&quot;&gt;Merge k Sorted Lists&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK &lt;/span&gt;&lt;/b&gt;- vezi si #38&lt;/p&gt;&lt;p&gt;28. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/02/50-dsa-questions-26-27-28-29.html&quot;&gt;Remove Nth Node From End of List&lt;/a&gt;&amp;nbsp;&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;29. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/02/50-dsa-questions-26-27-28-29.html&quot;&gt;Reorder List&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Tree&lt;/span&gt;&lt;/p&gt;&lt;p&gt;30.&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/03/50-dsa-questions-30-31-32.html&quot;&gt;Maximum Depth of Binary Tree&lt;/a&gt; &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;31. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/03/50-dsa-questions-30-31-32.html&quot;&gt;Same Tree&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;32.&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/03/50-dsa-questions-30-31-32.html&quot;&gt;Invert Binary Tree&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;33. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/04/50-dsa-questions-33.html&quot;&gt;Binary Tree Maximum Path Sum&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;34.&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/04/50-dsa-questions-34-35.html&quot;&gt;Binary Tree Level Order Traversal&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;35. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/04/50-dsa-questions-34-35.html&quot;&gt;Serialize &amp;amp; Deserialize Binary Tree&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;36. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-36.html&quot;&gt;Design Add and Search Words Data Structure&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;37.&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-36.html&quot;&gt;Word Search II&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Heap&lt;/span&gt;&lt;/p&gt;&lt;p&gt;38.&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-38-39.html&quot;&gt;Merge k Sorted Lists&lt;/a&gt;&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;39. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-38-39.html&quot;&gt;Top K Frequent Elements&lt;/a&gt;&amp;nbsp;&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;40. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-median-from-data.html&quot;&gt;Find Median from Data Stream&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Graph&lt;/span&gt;&lt;/p&gt;&lt;p&gt;41. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-graph.html&quot;&gt;Clone graph&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;42. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-graph.html&quot;&gt;Course Schedule&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;43. &lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-graph-43-44.html&quot;&gt;Number of Islands&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;44.&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-graph-43-44.html&quot;&gt;Pacific Atlantic Water Flow&lt;/a&gt; &lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;OK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Dynamic Programming -&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/05/50-dsa-questions-graph-45-46.html&quot;&gt;link&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;45.&amp;nbsp;Climbing Stairs &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;46.&amp;nbsp;Coin Change &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Bitwise Operations -&amp;nbsp;&lt;a href=&quot;https://boomblebee.blogspot.com/2024/06/50-dsa-questions-biti-47-48-49.html&quot;&gt;link&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;47. Sum of Two Integers &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;48. Number of 1 Bit &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;49.&amp;nbsp;Counting Bits &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;50. Missing Number &lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;OK&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/1738329227215036493/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/1738329227215036493?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/1738329227215036493'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/1738329227215036493'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/06/50dsa.html' title='CATALOG 50DSA '/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-5647087641211773447</id><published>2024-06-21T12:18:00.001+03:00</published><updated>2024-06-21T12:18:11.884+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="docker"/><title type='text'>Dockerfile</title><content type='html'>&lt;div&gt;&lt;span style=&quot;background-color: white; color: green; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;# specify base image to start from&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;background-color: white; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; node:9.4.0-alpine&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# copy files&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: blue;&quot;&gt;COPY&lt;/span&gt; app.js .&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: blue;&quot;&gt;COPY&lt;/span&gt; package.json .&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# execute commands&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: blue;&quot;&gt;RUN&lt;/span&gt; npm install &amp;amp;&amp;amp;\&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; apk update &amp;amp;&amp;amp;\&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; apk upgrade&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# exposes port 8080 with a specified protocol inside a Docker Container&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: blue;&quot;&gt;EXPOSE&lt;/span&gt; &amp;nbsp;8080&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# run app.js with executable &quot;node&quot;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: blue;&quot;&gt;CMD&lt;/span&gt; node app.js&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# Build in the current dir with tag myimage version v1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# &amp;gt; docker build . -t myimage:v1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# &amp;gt; docker images&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# Run the image as a container &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# -d=detach, run in background&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# -p=publish a container&#39;s port to the host&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# &amp;gt; docker run -dp 8080:8080 myimage:v1&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# Ping the application&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: green;&quot;&gt;# &amp;gt; curl localhost:8080&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/5647087641211773447/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/5647087641211773447?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/5647087641211773447'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/5647087641211773447'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/06/dockerfile.html' title='Dockerfile'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-4524224552827776743</id><published>2024-06-13T17:07:00.008+03:00</published><updated>2024-07-24T18:25:07.748+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cracking the code interview"/><category scheme="http://www.blogger.com/atom/ns#" term="lucru pe biti"/><category scheme="http://www.blogger.com/atom/ns#" term="strings"/><title type='text'>Probleme Strings</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#1. First non-repeating character&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;firstUniqChar&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Character&lt;/span&gt;,&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;map&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;HashMap&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;length&lt;/span&gt;(); i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;count&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;map&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i));&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;map&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;put&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i), count == &lt;span style=&quot;color: #569cd6;&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; count + &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;length&lt;/span&gt;(); i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;map&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i)) == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; i;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; -&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;firstUniqChar_2&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;) { &lt;span style=&quot;color: #6a9955;&quot;&gt;// str contains only lowercase letters &#39;a&#39; t o &#39;z&#39;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;bitVector&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;unique&lt;/span&gt; = (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;) &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Math&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;pow&lt;/span&gt;(&lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #b5cea8;&quot;&gt;27&lt;/span&gt;) - &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;; &lt;span style=&quot;color: #6a9955;&quot;&gt;// 1....1 for 26 bits corresponding to &#39;a&#39; to &#39;z&#39;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;length&lt;/span&gt;(); i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;index&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i) - &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;a&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; ((bitVector &amp;amp; (&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt; &amp;lt;&amp;lt; index)) &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) { &lt;span style=&quot;color: #6a9955;&quot;&gt;// if bit index already set&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unique = unique &amp;amp; ~(&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt; &amp;lt;&amp;lt; index); &lt;span style=&quot;color: #6a9955;&quot;&gt;// clear bit at index&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bitVector = bitVector | (&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt; &amp;lt;&amp;lt; index); &lt;span style=&quot;color: #6a9955;&quot;&gt;// set bit at index&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;length&lt;/span&gt;(); i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;index&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;str&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i) - &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;a&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;isBitSet&lt;/span&gt; = (unique &amp;amp; (&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt; &amp;lt;&amp;lt; index)) &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (isBitSet) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; i;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; -&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#2. Permutation of a palindrome&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Given a string, return if it is a permutation of a palindrome.&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #569cd6; font-family: Consolas; font-size: 10pt;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #4ec9b0; font-family: Consolas; font-size: 10pt;&quot;&gt;Solution&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #569cd6; font-family: Consolas; font-size: 10pt;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #4ec9b0; font-family: Consolas; font-size: 10pt;&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #dcdcaa; font-family: Consolas; font-size: 10pt;&quot;&gt;canBecomePalindrome&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #4ec9b0; font-family: Consolas; font-size: 10pt;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;) {&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #dcdcaa; font-family: Consolas; font-size: 10pt;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;() ==&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;) {&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #569cd6; font-family: Consolas; font-size: 10pt;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #4ec9b0; font-family: Consolas; font-size: 10pt;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;bitVector&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: #4ec9b0; font-family: Consolas; font-size: 10pt;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;; i&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #dcdcaa; font-family: Consolas; font-size: 10pt;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;(); i++) {&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #4ec9b0; font-family: Consolas; font-size: 10pt;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;index&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #dcdcaa; font-family: Consolas; font-size: 10pt;&quot;&gt;charAt&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;(i) -&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #ce9178; font-family: Consolas; font-size: 10pt;&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;((bitVector &amp;amp; (&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;lt;&amp;lt; index)) &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;) {&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #6a9955; font-family: Consolas; font-size: 10pt;&quot;&gt;// if bit set&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bitVector = bitVector &amp;amp; ~(&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;lt;&amp;lt; index);&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #6a9955; font-family: Consolas; font-size: 10pt;&quot;&gt;// clear&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bitVector = bitVector | (&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;lt;&amp;lt; index);&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #6a9955; font-family: Consolas; font-size: 10pt;&quot;&gt;// set&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #6a9955; font-family: Consolas; font-size: 10pt;&quot;&gt;// se poate transforma in palindrom daca:&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #6a9955; font-family: Consolas; font-size: 10pt;&quot;&gt;// Are nr par de caractere si toti bitii 0, SAU&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #6a9955; font-family: Consolas; font-size: 10pt;&quot;&gt;// nr impar de caractere si un singur bit 1&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #4ec9b0; font-family: Consolas; font-size: 10pt;&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;evenAmountOfChar&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #dcdcaa; font-family: Consolas; font-size: 10pt;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;() %&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;==&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #4ec9b0; font-family: Consolas; font-size: 10pt;&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;hasBit1&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #569cd6; font-family: Consolas; font-size: 10pt;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: #4ec9b0; font-family: Consolas; font-size: 10pt;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe; font-family: Consolas; font-size: 10pt;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;; i&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;; i++) {&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #6a9955; font-family: Consolas; font-size: 10pt;&quot;&gt;// 26 letters in alphabet&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;((bitVector &amp;amp; (&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&amp;lt;&amp;lt; i)) &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #b5cea8; font-family: Consolas; font-size: 10pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;) {&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #6a9955; font-family: Consolas; font-size: 10pt;&quot;&gt;// if bit set&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;(hasBit1) {&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #569cd6; font-family: Consolas; font-size: 10pt;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #6a9955; font-family: Consolas; font-size: 10pt;&quot;&gt;// a second bit is set&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hasBit1 =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #569cd6; font-family: Consolas; font-size: 10pt;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #c586c0; font-family: Consolas; font-size: 10pt;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp;evenAmountOfChar ^ hasBit1;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); color: #1d2228; font-family: Aptos, sans-serif; font-size: 11pt; line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas; font-size: 10pt;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;yiv4513681056MsoNormal&quot; style=&quot;background: rgb(40, 40, 40); line-height: 13.5pt; margin: 0in;&quot;&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-size: 13.3333px;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/4524224552827776743/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/4524224552827776743?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/4524224552827776743'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/4524224552827776743'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/06/cracking-coding-interview-revisited-6th.html' title='Probleme Strings'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-9084184214634015737</id><published>2024-06-06T19:06:00.005+03:00</published><updated>2024-06-08T22:27:49.512+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interviu"/><category scheme="http://www.blogger.com/atom/ns#" term="technical task"/><title type='text'>Microsoft &quot;technical task&quot;</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;1. De corectat un program&amp;nbsp;✖️&lt;/span&gt;&lt;/p&gt;&lt;p&gt;A este un array de cifre 0 sau 1 (reprezentarea binară a unui număr, cu A[0] = LSB). Se cere să se afle prima poziție (de la LSB la MSB) de pe care apare cel mai lung șir de biți/cifre 1. De corectat maxim 2 linii (eu am corectat una).&lt;/p&gt;&lt;div style=&quot;line-height: 19px;&quot;&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;solution&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;A&lt;/span&gt;) {&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;n&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;A&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt; = n - &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt; = -&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;k&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;, maximal = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (i &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;A&lt;/span&gt;[i] == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; k = k + &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (k &amp;gt;= maximal) {&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; maximal = k;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result = i;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; k = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i = i - &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #d4d4d4; font-family: Consolas, Courier New, monospace;&quot;&gt;&lt;span style=&quot;background-color: #1e1e1e; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;A&lt;/span&gt;[&lt;/b&gt;&lt;b style=&quot;background-color: #1e1e1e; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #b5cea8;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;] == &lt;/span&gt;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt; &amp;amp;&amp;amp; k + &lt;/span&gt;&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt; &amp;gt;= maximal) &lt;/span&gt;&lt;/b&gt;// correction &amp;gt;= instead of &amp;gt;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; result;&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; white-space: pre;&quot;&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;2. Repartizare pacienți într-un sanatoriu&amp;nbsp;✔️&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Se dau N oaspeți (0... N-1) care așteaptă să fie repartizați pe camere, într-un sanatoriu. Într-o cameră se pot caza oricâți, dar nu toți pacienții vor să aibă mulți colegi de cameră.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Input: un array A cu N elemente, A[K] = numărul maxim de persoane într-o cameră, permis de pacientul K, inclusiv el însuși&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Să se afle numărul minim de camere necesare pentru a caza toți pacienții.&lt;/p&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;import&lt;/span&gt; java.util.*;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;import&lt;/span&gt; java.util.stream.Collectors;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;solution&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;A&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;rooms&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;patients&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Arrays&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;stream&lt;/span&gt;(A).&lt;span style=&quot;color: #dcdcaa;&quot;&gt;boxed&lt;/span&gt;().&lt;span style=&quot;color: #dcdcaa;&quot;&gt;collect&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;Collectors&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;toList&lt;/span&gt;());&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Collections&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;sort&lt;/span&gt;(patients);&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;patients&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;size&lt;/span&gt;(); i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rooms++;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;patients&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(i) == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;continue&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i += &lt;span style=&quot;color: #9cdcfe;&quot;&gt;patients&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;get&lt;/span&gt;(i);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; rooms;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;3. Reducerea unui șir de caractere&amp;nbsp;✔️&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Un șir S conține doar literele A, B, C, D. El se poate transforma eliminând un grup de litere adiacente „AB” sau „CD” (în orice ordine). Să se afle șirul final, după aplicarea tuturor reducerilor posibile. Algoritmul trebuie să fie eficient pt seturi mari de date (un șir de maxim 250.000 caractere).&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div style=&quot;line-height: 19px;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;solution2&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;copy&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;do&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; copy = word;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; word = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;replaceAll&lt;/span&gt;(&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;AB&quot;&lt;/span&gt;, &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; word = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;replaceAll&lt;/span&gt;(&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;BA&quot;&lt;/span&gt;, &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; word = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;replaceAll&lt;/span&gt;(&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;CD&quot;&lt;/span&gt;, &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; word = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;replaceAll&lt;/span&gt;(&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;DC&quot;&lt;/span&gt;, &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (!&lt;span style=&quot;color: #9cdcfe;&quot;&gt;copy&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;equals&lt;/span&gt;(word));&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; word;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;solution&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;isEmpty&lt;/span&gt;()) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; word;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;marked&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[&lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;length&lt;/span&gt;()];&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; marked[&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;] = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;length&lt;/span&gt;(); i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; marked[i] = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;condition&lt;/span&gt;(word, i, i-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;)) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; marked[i] = &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; marked[i-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] = &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i++;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;length&lt;/span&gt;(); i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (marked[i] == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; marked = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;circle&lt;/span&gt;(word, i, marked);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i++;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;StringBuilder&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;StringBuilder&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;marked&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (marked[i] == &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;append&lt;/span&gt;(&lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i));&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;toString&lt;/span&gt;();&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #dcdcaa;&quot;&gt;circle&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;pos&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;marked&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;left&lt;/span&gt; = pos - &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;right&lt;/span&gt; = pos + &lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (left &amp;gt;= &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; right &amp;lt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;marked&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length &lt;/span&gt;&amp;amp;&amp;amp; marked[left] == 0) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (marked[left] == &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; marked[right] == &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;condition&lt;/span&gt;(word, left, right)) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; marked[left] = &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; marked[right] = &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left--;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; right--;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;continue&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;r2&lt;/span&gt; = right;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (r2 &amp;lt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;marked&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; &amp;amp;&amp;amp; marked[r2] == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; r2++;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (r2 != right) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; right = r2;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &lt;span style=&quot;color: #c586c0;&quot;&gt;else&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;break&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; marked;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;condition&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;String&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;j&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i) == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;A&#39;&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(j) == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;B&#39;&lt;/span&gt; || &lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i) == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;B&#39;&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(j) == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;A&#39;&lt;/span&gt; ||&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i) == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;C&#39;&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(j) == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;D&#39;&lt;/span&gt; ||&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(i) == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;D&#39;&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;word&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;charAt&lt;/span&gt;(j) == &lt;span style=&quot;color: #ce9178;&quot;&gt;&#39;C&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;4. Bonus (demo):&amp;nbsp;First Missing Positive&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;✖️&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Given an unsorted integer array nums, return the smallest positive integer that is not present in nums. You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Prima implementare (&lt;span style=&quot;background-color: #282828; color: #dcdcaa; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; text-align: left; white-space: pre;&quot;&gt;firstMissingPositive2&lt;/span&gt;): O(n^2) timp și O(n) spațiu&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;A doua implementare (&lt;span style=&quot;background-color: #282828; color: #dcdcaa; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; text-align: left; white-space: pre;&quot;&gt;firstMissingPositive)&lt;/span&gt;: O(n) timp și O(1) spațiu&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;firstMissingPositive2&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;initialCheck&lt;/span&gt;(nums) == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Set&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;Integer&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;elems&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;HashSet&lt;/span&gt;&amp;lt;&amp;gt;();&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;num&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; nums) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;elems&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;add&lt;/span&gt;(num);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;; ; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (!&lt;span style=&quot;color: #9cdcfe;&quot;&gt;elems&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;contains&lt;/span&gt;(i)) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; i;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;initialCheck&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;allNegative&lt;/span&gt; = &lt;span style=&quot;color: #569cd6;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;min&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Integer&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;MAX_VALUE&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (nums[i] &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; allNegative = &lt;span style=&quot;color: #569cd6;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (min &amp;gt; nums[i]) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; min = nums[i];&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (allNegative || min &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isArrayComplete&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;max&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;xor&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;times&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (nums[i] &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xor = xor ^ nums[i];&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; times++;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;; i&amp;lt;=times; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xor = xor ^ i;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; xor == &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; times == max;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;firstMissingPositive&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;initialCheck&lt;/span&gt;(nums) == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #6a9955;&quot;&gt;// find min, max&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;max&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Integer&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;MIN_VALUE&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;min&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Integer&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;MAX_VALUE&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (nums[i] &amp;lt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nums[i] = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (max &amp;lt; nums[i]) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; max = nums[i];&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (min &amp;gt; nums[i] &amp;amp;&amp;amp; min &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; min = nums[i];&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (min == &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;isArrayComplete&lt;/span&gt;(nums, max)) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; max + &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #6a9955;&quot;&gt;// tag in place&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;tag&lt;/span&gt; = max != &lt;span style=&quot;color: #9cdcfe;&quot;&gt;Integer&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;MAX_VALUE&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; max + &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; max;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;val&lt;/span&gt; = nums[i] &amp;gt;= tag &lt;span style=&quot;color: #c586c0;&quot;&gt;?&lt;/span&gt; nums[i]-tag &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; nums[i]; &lt;span style=&quot;color: #6a9955;&quot;&gt;// untag/extract if already tagged&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (val &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; val &amp;lt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt; &amp;amp;&amp;amp; nums[val-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] &amp;lt; tag) { &lt;span style=&quot;color: #6a9955;&quot;&gt;// avoid duplicates&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nums[val-&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;] += tag;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #6a9955;&quot;&gt;// find first untagged&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (nums[i] &amp;lt; tag &amp;amp;&amp;amp; nums[i] &amp;gt;= &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; i+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; max + &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;; &lt;span style=&quot;color: #6a9955;&quot;&gt;// should not arrive here&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/9084184214634015737/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/9084184214634015737?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/9084184214634015737'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/9084184214634015737'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/06/microsoft-technical-task.html' title='Microsoft &quot;technical task&quot;'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1570382885092564234.post-8371564742497732687</id><published>2024-06-01T23:49:00.005+03:00</published><updated>2024-07-19T17:17:48.926+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="50dsa"/><category scheme="http://www.blogger.com/atom/ns#" term="lucru pe biti"/><title type='text'>50 DSA-Questions: Biti #47, #48, #49, #50</title><content type='html'>&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#47.&amp;nbsp;Sum of Two Integers&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Given two integers a and b, return the sum of the two integers
without using the operators + and -.&amp;nbsp;&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #6a9955;&quot;&gt;// addition a, b =&amp;gt; sum = a ^ b; carry = a &amp;amp; b&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;getSum1&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;a&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;b&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;carry&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (b != &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; carry = a &amp;amp; b;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a = a ^ b;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b = carry &amp;lt;&amp;lt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; a;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;getSum2&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;a&lt;/span&gt;, &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;b&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;carry&lt;/span&gt; = (a &amp;amp; b) &amp;lt;&amp;lt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;result&lt;/span&gt; = a ^ b;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (carry == &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; result;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;getSum2&lt;/span&gt;(carry, result);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#48.&amp;nbsp;Number of 1 Bit&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Write a function that takes the binary representation of an unsigned integer and returns the number of &#39;1&#39; bits it has (also known as the Hamming weight).&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;hammingWeight&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;num&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;bits&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (num != &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;boolean&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;is1&lt;/span&gt; = (num &amp;amp; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) != &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (is1) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bits++;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num = num &amp;gt;&amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; bits;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#49.&amp;nbsp;Counting Bits&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Given an integer n, return an array of length n + 1 such that for each i (0 &amp;lt;= i &amp;lt;= n), ans[i] is the number of 1&#39;s in the binary representation of i.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #dcdcaa;&quot;&gt;countBits&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;n&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;array&lt;/span&gt; = &lt;span style=&quot;color: #c586c0;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[n+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;];&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;=n; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; array[i] = &lt;span style=&quot;color: #dcdcaa;&quot;&gt;hammingWeight&lt;/span&gt;(i);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; array;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;#50.&amp;nbsp;Missing Number&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span&gt;Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;missingNumber2&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;max&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;sum&lt;/span&gt; = (max+&lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;) * max / &lt;span style=&quot;color: #b5cea8;&quot;&gt;2&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;num&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;:&lt;/span&gt; nums) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum -= num;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; sum;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;missingNumber&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt;[] &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;xor&lt;/span&gt; = &lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #6a9955;&quot;&gt;// XOR properties:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #6a9955;&quot;&gt;// a ^ b = b ^ a =&amp;gt; we can xor the elements in any order&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #6a9955;&quot;&gt;// x ^ x = 0 =&amp;gt; nums[k] ^ i = 0 if nums[k] == i =&amp;gt; will eliminate matching elements&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #6a9955;&quot;&gt;// x ^ 0 = x&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #6a9955;&quot;&gt;// the unmatched i will stand out&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt;=&lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nums&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;length&lt;/span&gt;; i++) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xor = xor ^ nums[i] ^ i;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; xor;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Bonus: Reverse bits&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Reverse bits of a given 32 bits &lt;u&gt;unsigned&lt;/u&gt; integer.&lt;/p&gt;&lt;div style=&quot;background-color: #282828; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Solution&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #569cd6;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;reverseBits&lt;/span&gt;(&lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;n&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;res&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;i&lt;/span&gt; = &lt;span style=&quot;color: #b5cea8;&quot;&gt;32&lt;/span&gt;; &amp;nbsp;&lt;span style=&quot;color: #6a9955;&quot;&gt;// need to fill all 32 bits&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;while&lt;/span&gt; (i &amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;0&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #9cdcfe;&quot;&gt;currentBit&lt;/span&gt; = n &amp;amp; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; res = res &amp;lt;&amp;lt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt; | currentBit; &lt;span style=&quot;color: #6a9955;&quot;&gt;// res = res * 2 + currentBit;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; n = n &amp;gt;&amp;gt; &lt;span style=&quot;color: #b5cea8;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i--;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #c586c0;&quot;&gt;return&lt;/span&gt; res;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boomblebee.blogspot.com/feeds/8371564742497732687/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1570382885092564234/8371564742497732687?isPopup=true' title='0 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/8371564742497732687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1570382885092564234/posts/default/8371564742497732687'/><link rel='alternate' type='text/html' href='http://boomblebee.blogspot.com/2024/06/50-dsa-questions-biti-47-48-49.html' title='50 DSA-Questions: Biti #47, #48, #49, #50'/><author><name>shakuka</name><uri>http://www.blogger.com/profile/03494386541140595972</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibSj1HrK2npFJox9HCGcFKN0-bUdE3wgOtg3NKm2N174_k2k_qNSSkHr9fRZYO1mP8mB8NoH7J_m44x1pr_yfOp5IknkGOyTtxlAKQpQm4Yx0qF7fDnG7auJ9ufNFFnw/s113/*'/></author><thr:total>0</thr:total></entry></feed>