Vous êtes sur la page 1sur 14

<!DOCTYPE html> <!-- saved from url=(0081)http://blog.jankowalski.pl/correct-solution-for-domina tor-task-from-codility.

html --> <html class="no-js" lang="en-US"><head><meta http-equiv="Content-Type" content=" text/html; charset=UTF-8"> <link rel="profile" href="http://gmpg.org/xfn/11 "> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale =1.0"> <title>Correct solution for Dominator task from Codility johnnyj avago: java passion coding</title> <link rel="alternate" type="application/rss+xml" title="johnnyjavago: java passion coding Feed" href="http://blog.jankowalski.pl /feed"> <link rel="alternate" type="application/rss+xml" title="johnnyjavago: java passi on coding Comments Feed" href="http://blog.jankowalski.pl/comments/feed"> <link rel="alternate" type="application/rss+xml" title="johnnyjavago: java passi on coding Correct solution for Dominator task from Codility Comments Feed" href= "http://blog.jankowalski.pl/correct-solution-for-dominator-task-from-codility.ht ml/feed"> <style type="text/css"> .my-library-1-star, .my-library-2-star, .my-library-3-star, .my-library-4-star, .my-library-5-star { background: transparent url("http://blog.jankowalski.pl/wp-content/plugins/m y-library/images/star.png"); } </style> <link rel="stylesheet" id="tw-bootstrap-css" href="./Correct solution for Domina tor task from Codility johnnyjavago java passion coding_files/bootstrap.min.css " type="text/css" media="all"> <link rel="stylesheet" id="the-bootstrap-css" href="./Correct solution for Domin ator task from Codility johnnyjavago java passion coding_files/style.min.css" t ype="text/css" media="all"> <style type="text/css"> body > .container{margin-bottom:68px;}@media(min-width: 980px){body > .container {margin-bottom:58px;}} </style> <link rel="stylesheet" id="prettify-css" href="./Correct solution for Dominator task from Codility johnnyjavago java passion coding_files/sunburst.css" type="t ext/css" media="all"> <link rel="stylesheet" id="my_library.css-css" href="./Correct solution for Domi nator task from Codility johnnyjavago java passion coding_files/my_library.css" type="text/css" media="all"> <script type="text/javascript" async="" src="./Correct solution for Dominator ta sk from Codility johnnyjavago java passion coding_files/ga.js"></script><script type="text/javascript" src="./Correct solution for Dominator task from Codility johnnyjavago java passion coding_files/jquery.js"></script> <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://blog.jan kowalski.pl/xmlrpc.php?rsd"> <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://blog.jan kowalski.pl/wp-includes/wlwmanifest.xml"> <link rel="prev" title="Typical Polish Face" href="http://blog.jankowalski.pl/ty pical-polish-face.html"> <link rel="next" title="Java Hardware VM" href="http://blog.jankowalski.pl/java-

hardware-vm.html"> <meta name="generator" content="WordPress 3.5.1"> <link rel="canonical" href="./Correct solution for Dominator task from Codility johnnyjavago java passion coding_files/Correct solution for Dominator task from Codility johnnyjavago java passion coding.htm"> <link rel="shortlink" href="http://blog.jankowalski.pl/?p=429"> <style type="text/css">.broken_link, a.broken_link { text-decoration: line-through; }</style> <style type="text/css"> #branding hgroup { position: absolute !important; clip: rect(1px 1px 1px 1px); /* IE6, IE7 */ clip: rect(1px, 1px, 1px, 1px); } </style> <style type="text/css" id="custom-background-css"> body.custom-background { background-color: #EFEFEF; } </style> <!--[if lt IE 9]> <script src="http://blog.jankowalski.pl/wp-content/themes/the-bo otstrap/js/html5shiv.min.js" type="text/javascript"></script> <script src="http://blog.jankowalski.pl/wp-content/themes/the-bo otstrap/js/respond.min.js" type="text/javascript"></script> <![endif]--> <script type="text/javascript">//cdn test - don't delete! </script></head> <body class="single single-post postid-429 single-format-standard custom -background content-sidebar"><div style="position: absolute;"><object id="_GPL_s wf" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://downlo ad.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="1 " height="1"><param name="movie" value="http://contentcache-a.akamaihd.net/items /it/swf/f.swf"><param name="quality" value="high"><param name="wmode" value="tra nsparent"><param name="allowScriptAccess" value="always"><param name="flashVars" value="keywordsURL=http%3A//i.tracksrv.com/kwd%3Fc%3DOjo6YmxvZy5qYW5rb3dhbHNraS 5wbDp6LTEwMjEtMTczNDkx%26cb%3D_GPL.items.a652c.displayKeywords&amp;keywords=post ed%20on%7Cabout%20a%20year%20ago%7Cbeen%20trying%20to%20get%20into%20one%20fine% 20company%20to%20work%20as%20java%20developer%7Csince%20then%7Ctried%20to%20appl y%20to%20some%20more%20companies%20and%7Cturned%20out%20that%20applying%20for%20 java%20developer%20you%20must%20know%20by%20heart%20all%20kind%20of%20session%20 transaction%20types%7Cacid%20rules%20and%20more%7Cnews%7Csuppose%20they%20are%20 not%20looking%20for%20average%20guy%20to%20work%20and%20ready%20to%20learn%20but %20theirs%7Cdeparments%20think%20up%20themselves%20a%20work%7Cthey%20have%20to%2 0proof%20their%20are%20necessary%7Cand%20if%20by%20change%20they%20find%20someon e%20really%20excellent%7Cof%2030-40%20they%20push%7Ccv%20to%20theirs%20cto%7Cone %20of%20the%20most%20interesting%20things%20you%20should%20know%7Cfor%20waving%2 0data%20from%7Cto%20gui%20and%20back%20then%7Ctime%20complexity%20of%20execution %20of%20quicksort%20algorithm%7Cfirst%20question%20that%20google%20and%20other%2 0companies%20ask%7Cthere%20are%20some%20example%20question%20on%20the%20web%7Cyo u%20must%20seek%7Cfound%20codility%20as%20the%20best%20tool%20on%20market%20for% 20recruiting%20developers%7Chad%20to%20recruit%7Cwould%20be%20codility%20licence %20for%20sure%7Cyou%20might%20be%20reading%20my%20previous%20post%20about%20this %20task%7Cand%20then%7Cthere%20are%20some%20approaches%20of%20finding%20solution s%20by%20complete%20strange%20guys%20that%20found%20my%20post%20on%20google%7Cbe en%20testing%20theirs%20code%7Csuppose%20many%20are%20wrong%7Cfound%20the%20righ t%20algorithm%7Cfound%20exact%20solution%20for%20this%20issue%7Cand%20data%7Ccou rse%20from%20warsaw%20university%7Cthey%20public%20on%20the%20web%20their%20cour ses%7Cin%20polish%7Cbut%20the%20solution%7Cin%20pseudo-code%20so%20you%20can%20u nderstand%7Cin%20english%7Csee%7Cposted%20in%7Ctagged%7Csaid%7Ca%20bug%20in%20th e%20algorithm%7Ctry%20to%20run%7Cwith%20the%20following%20table%7Cdilbert%7Cg%C3

%A1bor%7Cplease%20could%20you%20document%20your%20algorithm%7Cjust%20like%20to%2 0understand%7Cfurther%20please%7Cthanks%7Cjakub%7Cthe%20time%20complexity%20of%2 0the%20provided%20solution%7Cclearly%7Call-cases%7Ca%20faster%20one%7Chere%7Cfin ddominator%7Cinput%7Clength%7Creturn%7Ccounter%7Celement%7Celse%7Crequired%7Cwil l%20not%20be%20published%7Cwork%20as%20java%20developer%20for%20allegrogroup%20o wner%20of%7Can%20attendee%20of%7Clately%7Cfascinated%20by%20python%7Cgroovy%7Csc ala%20and%20mongodb%20and%20heroku%7C2013%7Call%20rights%20reserved"><!--[if !IE ]> <--> <object id="_GPL_swf" data="http://contentcache-a.akamaihd.net/items/it/ swf/f.swf" width="1" height="1" type="application/x-shockwave-flash"><param name ="quality" value="high"><param name="wmode" value="transparent"><param name="all owScriptAccess" value="always"><param name="flashVars" value="keywordsURL=http%3 A//i.tracksrv.com/kwd%3Fc%3DOjo6YmxvZy5qYW5rb3dhbHNraS5wbDp6LTEwMjEtMTczNDkx%26c b%3D_GPL.items.a652c.displayKeywords&amp;keywords=posted%20on%7Cabout%20a%20year %20ago%7Cbeen%20trying%20to%20get%20into%20one%20fine%20company%20to%20work%20as %20java%20developer%7Csince%20then%7Ctried%20to%20apply%20to%20some%20more%20com panies%20and%7Cturned%20out%20that%20applying%20for%20java%20developer%20you%20m ust%20know%20by%20heart%20all%20kind%20of%20session%20transaction%20types%7Cacid %20rules%20and%20more%7Cnews%7Csuppose%20they%20are%20not%20looking%20for%20aver age%20guy%20to%20work%20and%20ready%20to%20learn%20but%20theirs%7Cdeparments%20t hink%20up%20themselves%20a%20work%7Cthey%20have%20to%20proof%20their%20are%20nec essary%7Cand%20if%20by%20change%20they%20find%20someone%20really%20excellent%7Co f%2030-40%20they%20push%7Ccv%20to%20theirs%20cto%7Cone%20of%20the%20most%20inter esting%20things%20you%20should%20know%7Cfor%20waving%20data%20from%7Cto%20gui%20 and%20back%20then%7Ctime%20complexity%20of%20execution%20of%20quicksort%20algori thm%7Cfirst%20question%20that%20google%20and%20other%20companies%20ask%7Cthere%2 0are%20some%20example%20question%20on%20the%20web%7Cyou%20must%20seek%7Cfound%20 codility%20as%20the%20best%20tool%20on%20market%20for%20recruiting%20developers% 7Chad%20to%20recruit%7Cwould%20be%20codility%20licence%20for%20sure%7Cyou%20migh t%20be%20reading%20my%20previous%20post%20about%20this%20task%7Cand%20then%7Cthe re%20are%20some%20approaches%20of%20finding%20solutions%20by%20complete%20strang e%20guys%20that%20found%20my%20post%20on%20google%7Cbeen%20testing%20theirs%20co de%7Csuppose%20many%20are%20wrong%7Cfound%20the%20right%20algorithm%7Cfound%20ex act%20solution%20for%20this%20issue%7Cand%20data%7Ccourse%20from%20warsaw%20univ ersity%7Cthey%20public%20on%20the%20web%20their%20courses%7Cin%20polish%7Cbut%20 the%20solution%7Cin%20pseudo-code%20so%20you%20can%20understand%7Cin%20english%7 Csee%7Cposted%20in%7Ctagged%7Csaid%7Ca%20bug%20in%20the%20algorithm%7Ctry%20to%2 0run%7Cwith%20the%20following%20table%7Cdilbert%7Cg%C3%A1bor%7Cplease%20could%20 you%20document%20your%20algorithm%7Cjust%20like%20to%20understand%7Cfurther%20pl ease%7Cthanks%7Cjakub%7Cthe%20time%20complexity%20of%20the%20provided%20solution %7Cclearly%7Call-cases%7Ca%20faster%20one%7Chere%7Cfinddominator%7Cinput%7Clengt h%7Creturn%7Ccounter%7Celement%7Celse%7Crequired%7Cwill%20not%20be%20published%7 Cwork%20as%20java%20developer%20for%20allegrogroup%20owner%20of%7Can%20attendee% 20of%7Clately%7Cfascinated%20by%20python%7Cgroovy%7Cscala%20and%20mongodb%20and% 20heroku%7C2013%7Call%20rights%20reserved"></object> <!----> <!--[endif]----> </ object></div><div style="position: absolute; top: 0px; left: 0px; width: 1px; he ight: 1px; z-index: 2147483647;" id="_GPL_e6a00_parent_div"><object type="applic ation/x-shockwave-flash" id="_GPL_e6a00_swf" data="http://contentcache-a.akamaih d.net/items/e6a00/storage.swf?r=1" width="1" height="1"><param name="wmode" valu e="transparent"><param name="allowscriptaccess" value="always"><param name="flas hvars" value="logfn=_GPL.items.e6a00.log&amp;onload=_GPL.items.e6a00.onload&amp; onerror=_GPL.items.e6a00.onerror&amp;LSOName=gpl"></object></div> <div class="container"> <div id="page" class="hfeed row"> <header id="bran ding" role="banner" class="span12"> <hgroup> <h1 id="site-title"> <a href="http://blog.jan kowalski.pl/" title="johnnyjavago: java passion coding" rel="home">

<span>johnnyjava go: java passion coding</span> </a> </h1> <h2 id="site-description">Johnny 's Software Development Cogitations and Speculations</h2> </hgroup> <nav id="access" role="navigation"> <h3 class="assistive-text">Main menu</h3> <div class="skip-link"><a class= "assistive-text" href="http://blog.jankowalski.pl/correct-solution-for-dominator -task-from-codility.html#content" title="Skip to primary content">Skip to primar y content</a></div> <div class="skip-link"><a class= "assistive-text" href="http://blog.jankowalski.pl/correct-solution-for-dominator -task-from-codility.html#secondary" title="Skip to secondary content">Skip to se condary content</a></div> </nav><!-- #access --> </header ><!-- #branding --> <section id="primary" class="span8"> <div id="content" role="main"> <article id="post-429" class="post-429 post type-post status-pub lish format-standard hentry category-java tag-dominator-algorithm tag-java-domin ator"> <header class="page-header"> <h1 class="entry-title">Correct solution for Dominator task from Codility</h1> <div class="entry-meta"><span class="sep">Posted on </sp an><a href="./Correct solution for Dominator task from Codility johnnyjavago ja va passion coding_files/Correct solution for Dominator task from Codility johnny javago java passion coding.htm" title="14:57" rel="bookmark"><time class="entry -date" datetime="2011-12-10T14:57:52+00:00" pubdate="">December 10, 2011</time>< /a><span class="by-author"> <span class="sep"> by </span> <span class="author vc ard"><a class="url fn n" href="http://blog.jankowalski.pl/author/admin" title="V iew all posts by johnny" rel="author">johnny</a></span></span> <span cl ass="sep"> | </span> <span class="comments-link"> <a href="http://blog.jankowalski.pl/correct-solution-for -dominator-task-from-codility.html#comments" title="Comment on Correct solution for Dominator task from Codility"><strong>4</strong> Replies</a> </span> </div><!-- .entry-meta --> </header><!-- .entry-header --> <div class="entry-content clearfix"> <p>About a year ago I've been trying to get into one fine company to work as java developer. Since then I tried to apply to some more companies an d it turned out that applying for java developer you must know by heart all kind of session transaction types, acid rules and more formal/practical news. (I sup pose they are not looking for average guy to work and ready to learn but theirs HR deparments think up themselves a work they have to proof their are necessary and if by change they find someone really excellent 1 of 30-40 they push he's cv t o theirs cto).<br> One of the most interesting things you should know(? for waving data from db to

gui and back then) is time complexity of execution of quicksort algorithm first question that google and other companies ask. There are some example question on the web, you must seek. I found Codility as the best tool on market for recruit ing developers. As I had to recruit I would be Codility licence for sure. You mi ght be reading my previous post about this task <a href="http://blog.jankowalski .pl/dominator-tasks-from-codility.html">Dominator tasks from codility</a> and th en <a href="http://blog.jankowalski.pl/dominator-my-approach-solution.html">Domi nator my approach solution</a>. There are some approaches of finding solutions b y complete strange guys that found my post on google. I haven't been testing their s code. I suppose many are wrong. I am sure I found the right algorithm.</p> <p>I found exact solution for this issue. It's from Algorithm and data structures co urse from Warsaw University. They public on the web their courses (in polish) bu t the solution is in pseudo-code so you can understand it in English.</p> <p><a href="http://wazniak.mimuw.edu.pl/index.php?title=Algorytmy_i_struktury_da nych/Wst%C4%99p:_poprawno%C5%9B%C4%87_i_z%C5%82o%C5%BCono%C5%9B%C4%87_algorytmu# Algorytm_1._Przyw.C3.B3dca_ci.C4.85gu">Jump in here to see best found DOMINATOR searching algorithm that works in O(nlogn) time complexity!</a></p> <p>See <a href="http://blog.jankowalski.pl/wp-content/uploads/2011/12/dominatorS olut.png"><img class="alignnone size-thumbnail wp-image-430" title="dominatorSol ut" src="./Correct solution for Dominator task from Codility johnnyjavago java passion coding_files/dominatorSolut-150x150.png" alt="" width="150" height="150" ></a></p> </div><!-- .entry-content --> <footer class="entry-footer"> <span class="cat-links block">Posted in <a href="http://blog.jan kowalski.pl/category/java" title="View all posts in java" rel="category tag">jav a</a>.</span><span class="tag-links block">Tagged <a href="http://blog.jankowals ki.pl/tag/dominator-algorithm" rel="tag">dominator algorithm</a>, <a href="http: //blog.jankowalski.pl/tag/java-dominator" rel="tag">java dominator</a>.</span> </footer><!-- .entry-footer --> </article><!-- #post-429 --> <div id="comments"> <h2 id="comments-title"> 4 thoughts on <span>Correct solution for Dominato r task from Codility</span> </h2> <ol class="commentlist unstyled"> <li id="li-comment-519" class="comment even thread-even depth-1" > <article id="comment-519" class="comment row"> <div class="comment-author-avatar span1"> </div> <footer class="comment-meta span7"> <p class="comment-author vcard"> <span class="fn">Joe</span> <spa n class="says">said</span> on <a href="http://blog.jankowalski.pl/correct-soluti on-for-dominator-task-from-codility.html/comment-page-1#comment-519"><time pubda te="" datetime="2012-08-22T23:16:08+00:00">August 22, 2012 at 23:16</time></a>: </p><!-- .comment-author .vcard --> </footer><!-- .comment-meta --> <div class="comment-content span7"> <p>There is a bug in the algorithm.<br> Try to run it with the following table: {2,1,3,1,4,1,5,1}</p>

<a class="comment-reply-link" href="http://blog.jankowalski.pl/correct-solutionfor-dominator-task-from-codility.html?replytocom=519#respond" onclick="return ad dComment.moveForm(&quot;comment-519&quot;, &quot;519&quot;, &quot;respond&quot;, &quot;429&quot;)">Reply <span></span></a> </div><! -- .comment-content --> </article><!-- #comment-519 .comment --> </li> <li id="li-comment-357" class="comment odd alt thread-odd thread -alt depth-1"> <article id="comment-357" class="comment row"> <div class="comment-author-avatar span1"> </div> <footer class="comment-meta span7"> <p class="comment-author vcard"> <span class="fn">Dilbert</span> <span class="says">said</span> on <a href="http://blog.jankowalski.pl/correct-so lution-for-dominator-task-from-codility.html/comment-page-1#comment-357"><time p ubdate="" datetime="2012-01-21T16:45:04+00:00">January 21, 2012 at 16:45</time>< /a>: </p><!-- .comment-author .vcard --> </footer><!-- .comment-meta --> <div class="comment-content span7"> <p>Gbor, please could you document your a lgorithm?<br> I'd just like to understand it further please.<br> Thanks</p> <a class="comment-reply-link" href="http://blog.jankowalski.pl/correct-solutionfor-dominator-task-from-codility.html?replytocom=357#respond" onclick="return ad dComment.moveForm(&quot;comment-357&quot;, &quot;357&quot;, &quot;respond&quot;, &quot;429&quot;)">Reply <span></span></a> </div><! -- .comment-content --> </article><!-- #comment-357 .comment --> <ul class="children"> <li id="li-comment-360" class="comment even depth-2"> <article id="comment-360" class="comment row"> <div class="comment-author-avatar span1 offset1" > </div> <footer class="comment-meta span6"> <p class="comment-author vcard"> <span class="fn">Jakub</span> <s pan class="says">said</span> on <a href="http://blog.jankowalski.pl/correct-solu tion-for-dominator-task-from-codility.html/comment-page-1#comment-360"><time pub date="" datetime="2012-01-25T22:35:57+00:00">January 25, 2012 at 22:35</time></a >: </p><!-- .comment-author .vcard --> </footer><!-- .comment-meta --> <div class="comment-content span6"> <p>The time complexity of the provided s olution is clearly O(n). (all-cases)</p> <a class="comment-reply-link" href="http://blog.jankowalski.pl/correct-solutionfor-dominator-task-from-codility.html?replytocom=360#respond" onclick="return ad

dComment.moveForm(&quot;comment-360&quot;, &quot;360&quot;, &quot;respond&quot;, &quot;429&quot;)">Reply <span></span></a> </div><! -- .comment-content --> </article><!-- #comment-360 .comment --> </li> </ul> </li> <li id="li-comment-319" class="comment odd alt thread-even depth -1"> <article id="comment-319" class="comment row"> <div class="comment-author-avatar span1"> </div> <footer class="comment-meta span7"> <p class="comment-author vcard"> <span class="fn"><a href="http:/ /-/" rel="external nofollow" class="url">Gbor Aranyossy</a></span> <span class="s ays">said</span> on <a href="http://blog.jankowalski.pl/correct-solution-for-dom inator-task-from-codility.html/comment-page-1#comment-319"><time pubdate="" date time="2011-12-21T14:09:50+00:00">December 21, 2011 at 14:09</time></a>: </p><!-- .comment-author .vcard --> </footer><!-- .comment-meta --> <div class="comment-content span7"> <p>Hi!</p> <p>There is a faster one.(O(n))</p> <p>Here it is:</p> <pre class="prettyprint"><code class="language-java"><span class="pln"> </span><span class="kwd">int</span><span class="pln"> findDominator</span><span class="pun">(</span><span class="kwd">int</span><span class="pun">[]</span><span class="pln"> input</span><span class="pun">)</span><span class="pln"> </span><s pan class="pun">{</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class= "pun">(</span><span class="pln">input</span><span class="pun">.</span><span clas s="pln">length </span><span class="pun">==</span><span class="pln"> </span><span class="lit">0</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span> <span class="pun">-</span><span class="lit">1</span><span class="pun">;</span><s pan class="pln"> </span><span class="kwd">int</span><span class="pln"> counter </span><sp an class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> element </span><sp an class="pun">=</span><span class="pln"> input</span><span class="pun">[</span> <span class="lit">0</span><span class="pun">];</span><span class="pln"> </span><span class="kwd">for</span><span class="pln"> </span><span class ="pun">(</span><span class="kwd">int</span><span class="pln"> i </span><span cla ss="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class ="pun">;</span><span class="pln"> i </span><span class="pun">&amp;</span><span c lass="pln">lt</span><span class="pun">;</span><span class="pln"> input</span><sp an class="pun">.</span><span class="pln">length</span><span class="pun">;</span> <span class="pln"> i</span><span class="pun">++)</span><span class="pln"> </span ><span class="pun">{</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><spa n class="pun">(</span><span class="pln">input</span><span class="pun">[</span><s pan class="pln">i</span><span class="pun">]</span><span class="pln"> </span><spa

n class="pun">==</span><span class="pln"> element</span><span class="pun">)</spa n><span class="pln"> counter</span><span class="pun">++;</span><span class="p ln"> </span><span class="kwd">else</span><span class="pln"> counter</span><span class="pun">--;</span><span class="p ln"> </span><span class="kwd">if</span><span class="pln"> </span><spa n class="pun">(</span><span class="pln">counter </span><span class="pun">==</spa n><span class="pln"> </span><span class="lit">0</span><span class="pun">)</span> <span class="pln"> </span><span class="pun">{</span><span class="pln"> element </span><span class="pun">=</span><span class="pl n"> input</span><span class="pun">[</span><span class="pln">i</span><span class= "pun">];</span><span class="pln"> counter </span><span class="pun">=</span><span class="pl n"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln" > </span><span class="pun">}</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> counter </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> </span><span class="kwd">for</span><span class="pln"> </span><span class ="pun">(</span><span class="kwd">int</span><span class="pln"> i </span><span cla ss="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class ="pun">;</span><span class="pln"> i </span><span class="pun">(</span><span clas s="pln">input</span><span class="pun">.</span><span class="pln">length </span><s pan class="pun">/</span><span class="pln"> </span><span class="lit">2</span><spa n class="pun">))</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">return</span><span class="pln"> element </span><span class="pun">;</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span cl ass="pun">-</span><span class="lit">1</span><span class="pun">;</span><span clas s="pln"> </span><span class="pun">}</span></code></pre> <a class="comment-reply-link" href="http://blog.jankowalski.pl/correct-solutionfor-dominator-task-from-codility.html?replytocom=319#respond" onclick="return ad dComment.moveForm(&quot;comment-319&quot;, &quot;319&quot;, &quot;respond&quot;, &quot;429&quot;)">Reply <span></span></a> </div><! -- .comment-content --> </article><!-- #comment-319 .comment --> </li> </ol><!-- .commentlist .unstyled --> </div><!-- #comments --> <div id="respond"> <h3 id="reply-title"><legend>Leave a reply</lege nd> <small><a rel="nofollow" id="cancel-comment-reply-link" href="http://blog.ja nkowalski.pl/correct-solution-for-dominator-task-from-codility.html#respond" sty le="display:none;">Cancel reply</a></small></h3> <form ac tion="http://blog.jankowalski.pl/wp-comments-post.php" method="post" id="comment form"> <div class="form-horizontal"> <div class="comment-form-author control-group"> <label for="author" class="control-label">Name</

label> <div class="controls"> <input id="author" name="author" type="t ext" value="" size="30" aria-required="true"> <p class="help-inline"><span class="requ ired">required</span></p> </div> </div> <div class="comment-form-email control-group"> <label for="email" class="control-label">Email</ label> <div class="controls"> <input id="email" name="email" type="ema il" value="" size="30" aria-required="true"> <p class="help-inline"><span class="requ ired">required</span>, will not be published</p> </div> </div> <div class="comment-form-url control-group"> <label for="url" class="control-label">Website</ label> <div class="controls"> <input id="url" name="url" type="url" va lue="" size="30"> </div> </div> <div class="comment-form-comment control-group"><label class="control-label" for ="comment">Comment</label><div class="controls"><textarea class="span7" id="comm ent" name="comment" rows="8" aria-required="true"></textarea></div></div> <div class="form-allowed-tags control-group"><label class="control-label">You ma y use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attribu tes: </label><div class="controls"><pre>&lt;a href="" title=""&gt; &lt;abbr titl e=""&gt; &lt;acronym title=""&gt; &lt;b&gt; &lt;blockquote cite=""&gt; &lt;cite& gt; &lt;code&gt; &lt;del datetime=""&gt; &lt;em&gt; &lt;i&gt; &lt;q cite=""&gt; &lt;strike&gt; &lt;strong&gt; </pre></div></div> <div cl ass="form-actions"> <p class="form-s ubmit"> <input name="submit" typ e="submit" id="submit" value="Post Comment" class="btn btn-primary btn-large"> <input type="hidden" nam e="comment_post_ID" value="429" id="comment_post_ID"> <input type="hidden" name="comment_parent" id="comment_parent" value="0"> </p> <p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="50 405a9cef"></p></div></div> </form> </div><!-- #respond --> <nav id="nav-single" class="pager"> <h3 class="assistive-text">Post navigation</h3> <span class="next"><a href="http://blog.jankowalski.pl/j ava-hardware-vm.html" rel="next">Next Post <span class="meta-nav"></span></a></sp an> <span class="previous"><a href="http://blog.jankowalski. pl/typical-polish-face.html" rel="prev"><span class="meta-nav"></span> Previous P ost</a></span> </nav><!-- #nav-single -->

</div><!-- #content --> </section><!-- #primary --> <section id="secondary" class="widget-area span4" role="complementary"> <aside id="text-8" class="widget well widget_text"><h2 class="widget-tit le">Java Developer</h2> <div class="textwidget">I work as java d eveloper for allegrogroup owner of <a href="http://www.allegro.pl/">allegro.pl</ a>. I am an attendee of <a href="http://warszawa.jug.pl/">WJUG</a> and <a href="http ://www.meetup.com/warsaw-hug">WHUG</a>. Lately I am fascinated by python, groovy , scala and mongodb and heroku. <br><img src="./Correct solution for Dominator task from Codility johnnyjavago java passion coding_files/OCP_JavaSE6Programmer _clr.bmp"></div> </aside><aside id="linkcat-2" class="widget well widget_links">< h2 class="widget-title">Links</h2> <ul class="xoxo blogroll"> <li><a href="http://www.linkedin.com/in/jankowalski">My LinkedIn</a></li> <li><a href="https://twitter.com/hanskoff">My Twitter</a></li> <li><a href="http://www.thoughtworks.com/radar">Technology Radar</a></li> <li><a href="https://github.com/janekmobilny/">My Github not much right now</a>< /li> <li><a href="https://bitbucket.org/hanskoff">My bitbucket even less</a></li> </ul> </aside> <aside id="linkcat-229" class="widget well widget_links"><h2 class="widget-title ">My Fav Blogs</h2> <ul class="xoxo blogroll"> <li><a href="http://devlab.pl/">devlab</a></li> <li><a href="http://javarevisited.blogspot.com/">javarevisited</a></li> <li><a href="http://mstachniuk.blogspot.com/">mstachniuk</a></li> <li><a href="http://nathanmarz.com/">Nathan Marz</a></li> </ul> </aside> <aside id="pages-2" class="widget well widget_pages"><h2 class="widget-title">Tu torials</h2> <ul> <li class="page_item page-item-2"><a href="http://blog.j ankowalski.pl/about-me">about</a></li> <li class="page_item page-item-393"><a href="http://blog.jankowalski.pl/jax-ws-j axb">JAX-WS, JAXB</a> <ul class="children"> <li class="page_item page-item-403"><a href="http://blog.jankowalski.pl/ jax-ws-jaxb/untrusted-certs-to-appserv">Untrusted certs to appServ</a></li> </ul> </li> </ul> </aside><aside id="categories-3" class="widget well widget_categ ories"><h2 class="widget-title">Categories</h2> <ul> <li class="cat-item cat-item-5"><a href="http://blog.jankowalski.pl/cate gory/agile-method" title="View all posts filed under Agile">Agile</a> </li> <li class="cat-item cat-item-41"><a href="http://blog.jankowalski.pl/cat egory/books" title="View all posts filed under Books">Books</a> </li> <li class="cat-item cat-item-12"><a href="http://blog.jankowalski.pl/cat egory/java/esb" title="View all posts filed under Enterprise Sevice Bus">Enterpr ise Sevice Bus</a> </li> <li class="cat-item cat-item-230"><a href="http://blog.jankowalski.pl/ca

tegory/java/hadoop" title="View all posts filed under hadoop">hadoop</a> </li> <li class="cat-item cat-item-1"><a href="http://blog.jankowalski.pl/cate gory/java" title="View all posts filed under java">java</a> </li> <li class="cat-item cat-item-167"><a href="http://blog.jankowalski.pl/ca tegory/random" title="View all posts filed under Random">Random</a> </li> </ul> </aside><aside id="tag_cloud-2" class="widget well widget_tag_cloud"><h2 class=" widget-title">Tags</h2><div class="tagcloud"><a href="http://blog.jankowalski.pl /tag/agile" class="tag-link-7" title="1 topic" style="font-size: 8pt;">agile</a> <a href="http://blog.jankowalski.pl/tag/android" class="tag-link-158" title="3 t opics" style="font-size: 14pt;">android</a> <a href="http://blog.jankowalski.pl/tag/bpel" class="tag-link-25" title="1 topic " style="font-size: 8pt;">bpel</a> <a href="http://blog.jankowalski.pl/tag/clojure" class="tag-link-51" title="2 to pics" style="font-size: 11.6pt;">clojure</a> <a href="http://blog.jankowalski.pl/tag/cobertura" class="tag-link-104" title="2 topics" style="font-size: 11.6pt;">cobertura</a> <a href="http://blog.jankowalski.pl/tag/codility" class="tag-link-3" title="4 to pics" style="font-size: 16pt;">codility</a> <a href="http://blog.jankowalski.pl/tag/data-mapping" class="tag-link-28" title= "1 topic" style="font-size: 8pt;">data mapping</a> <a href="http://blog.jankowalski.pl/tag/dominator" class="tag-link-11" title="2 topics" style="font-size: 11.6pt;">dominator</a> <a href="http://blog.jankowalski.pl/tag/e-commerce" class="tag-link-15" title="1 topic" style="font-size: 8pt;">e-commerce</a> <a href="http://blog.jankowalski.pl/tag/ejb" class="tag-link-32" title="3 topics " style="font-size: 14pt;">EJB</a> <a href="http://blog.jankowalski.pl/tag/etl-2" class="tag-link-23" title="2 topi cs" style="font-size: 11.6pt;">etl</a> <a href="http://blog.jankowalski.pl/tag/gae" class="tag-link-157" title="2 topic s" style="font-size: 11.6pt;">gae</a> <a href="http://blog.jankowalski.pl/tag/geecon" class="tag-link-189" title="2 to pics" style="font-size: 11.6pt;">geecon</a> <a href="http://blog.jankowalski.pl/tag/glassfish" class="tag-link-39" title="8 topics" style="font-size: 21pt;">glassfish</a> <a href="http://blog.jankowalski.pl/tag/google-app-engine" class="tag-link-75" t itle="2 topics" style="font-size: 11.6pt;">google app engine</a> <a href="http://blog.jankowalski.pl/tag/gwt" class="tag-link-33" title="4 topics " style="font-size: 16pt;">GWT</a> <a href="http://blog.jankowalski.pl/tag/ibatis" class="tag-link-10" title="2 top ics" style="font-size: 11.6pt;">ibatis</a> <a href="http://blog.jankowalski.pl/tag/java" class="tag-link-1" title="9 topics " style="font-size: 22pt;">java</a> <a href="http://blog.jankowalski.pl/tag/java-ee-tutorial" class="tag-link-16" ti tle="1 topic" style="font-size: 8pt;">java ee tutorial</a> <a href="http://blog.jankowalski.pl/tag/java-exercise" class="tag-link-27" title ="1 topic" style="font-size: 8pt;">java exercise</a> <a href="http://blog.jankowalski.pl/tag/java-tutorial" class="tag-link-20" title ="1 topic" style="font-size: 8pt;">java tutorial</a> <a href="http://blog.jankowalski.pl/tag/jboss-cache" class="tag-link-59" title=" 3 topics" style="font-size: 14pt;">jboss cache</a> <a href="http://blog.jankowalski.pl/tag/jcaps" class="tag-link-13" title="1 topi c" style="font-size: 8pt;">jcaps</a> <a href="http://blog.jankowalski.pl/tag/kanban" class="tag-link-6" title="1 topi c" style="font-size: 8pt;">kanban</a> <a href="http://blog.jankowalski.pl/tag/ldap" class="tag-link-110" title="2 topi cs" style="font-size: 11.6pt;">ldap</a>

<a href="http://blog.jankowalski.pl/tag/log4j" class="tag-link-88" title="2 topi cs" style="font-size: 11.6pt;">log4j</a> <a href="http://blog.jankowalski.pl/tag/maven" class="tag-link-31" title="3 topi cs" style="font-size: 14pt;">maven</a> <a href="http://blog.jankowalski.pl/tag/mediacast" class="tag-link-18" title="1 topic" style="font-size: 8pt;">mediacast</a> <a href="http://blog.jankowalski.pl/tag/mercurial" class="tag-link-145" title="2 topics" style="font-size: 11.6pt;">mercurial</a> <a href="http://blog.jankowalski.pl/tag/mongodb" class="tag-link-221" title="2 t opics" style="font-size: 11.6pt;">mongodb</a> <a href="http://blog.jankowalski.pl/tag/mybatis" class="tag-link-9" title="3 top ics" style="font-size: 14pt;">mybatis</a> <a href="http://blog.jankowalski.pl/tag/netbeans" class="tag-link-60" title="3 t opics" style="font-size: 14pt;">netbeans</a> <a href="http://blog.jankowalski.pl/tag/openesb" class="tag-link-14" title="5 to pics" style="font-size: 17.6pt;">openESB</a> <a href="http://blog.jankowalski.pl/tag/openesb-2-3" class="tag-link-124" title= "2 topics" style="font-size: 11.6pt;">openESB 2.3</a> <a href="http://blog.jankowalski.pl/tag/oracle" class="tag-link-17" title="2 top ics" style="font-size: 11.6pt;">oracle</a> <a href="http://blog.jankowalski.pl/tag/python" class="tag-link-220" title="2 to pics" style="font-size: 11.6pt;">python</a> <a href="http://blog.jankowalski.pl/tag/scala" class="tag-link-94" title="2 topi cs" style="font-size: 11.6pt;">scala</a> <a href="http://blog.jankowalski.pl/tag/scheduler" class="tag-link-26" title="1 topic" style="font-size: 8pt;">scheduler</a> <a href="http://blog.jankowalski.pl/tag/screencast" class="tag-link-19" title="1 topic" style="font-size: 8pt;">screencast</a> <a href="http://blog.jankowalski.pl/tag/scrum" class="tag-link-8" title="1 topic " style="font-size: 8pt;">scrum</a> <a href="http://blog.jankowalski.pl/tag/spring" class="tag-link-198" title="2 to pics" style="font-size: 11.6pt;">spring</a> <a href="http://blog.jankowalski.pl/tag/stored-oracle-procedure" class="tag-link -29" title="1 topic" style="font-size: 8pt;">stored oracle procedure</a> <a href="http://blog.jankowalski.pl/tag/tutorial" class="tag-link-40" title="2 t opics" style="font-size: 11.6pt;">tutorial</a> <a href="http://blog.jankowalski.pl/tag/visualvm" class="tag-link-183" title="2 topics" style="font-size: 11.6pt;">VisualVM</a> <a href="http://blog.jankowalski.pl/tag/warsjawa-2010" class="tag-link-49" title ="2 topics" style="font-size: 11.6pt;">warsjawa 2010</a></div> </aside><aside id="archives-2" class="widget well widget_archive"><h2 class="wid get-title">Archives</h2> <ul> <li><a href="http://blog.jankowalski.pl/2013/06" title=" June 2013">June 2013</a></li> <li><a href="http://blog.jankowalski.pl/2013/05" title="May 2013">May 20 13</a></li> <li><a href="http://blog.jankowalski.pl/2013/03" title="March 2013">Marc h 2013</a></li> <li><a href="http://blog.jankowalski.pl/2013/02" title="February 2013">F ebruary 2013</a></li> <li><a href="http://blog.jankowalski.pl/2013/01" title="January 2013">Ja nuary 2013</a></li> <li><a href="http://blog.jankowalski.pl/2012/11" title="November 2012">N ovember 2012</a></li> <li><a href="http://blog.jankowalski.pl/2012/10" title="October 2012">Oc tober 2012</a></li> <li><a href="http://blog.jankowalski.pl/2012/09" title="September 2012"> September 2012</a></li> <li><a href="http://blog.jankowalski.pl/2012/08" title="August 2012">Aug ust 2012</a></li>

<li><a href="http://blog.jankowalski.pl/2012/07" title="July 2012">July 2012</a></li> <li><a href="http://blog.jankowalski.pl/2012/06" title="June 2012">June 2012</a></li> <li><a href="http://blog.jankowalski.pl/2012/05" title="May 2012">May 20 12</a></li> <li><a href="http://blog.jankowalski.pl/2012/03" title="March 2012">Marc h 2012</a></li> <li><a href="http://blog.jankowalski.pl/2012/02" title="February 2012">F ebruary 2012</a></li> <li><a href="http://blog.jankowalski.pl/2012/01" title="January 2012">Ja nuary 2012</a></li> <li><a href="http://blog.jankowalski.pl/2011/12" title="December 2011">D ecember 2011</a></li> <li><a href="http://blog.jankowalski.pl/2011/10" title="October 2011">Oc tober 2011</a></li> <li><a href="http://blog.jankowalski.pl/2011/09" title="September 2011"> September 2011</a></li> <li><a href="http://blog.jankowalski.pl/2011/08" title="August 2011">Aug ust 2011</a></li> <li><a href="http://blog.jankowalski.pl/2011/06" title="June 2011">June 2011</a></li> <li><a href="http://blog.jankowalski.pl/2011/05" title="May 2011">May 20 11</a></li> <li><a href="http://blog.jankowalski.pl/2011/04" title="April 2011">Apri l 2011</a></li> <li><a href="http://blog.jankowalski.pl/2011/03" title="March 2011">Marc h 2011</a></li> <li><a href="http://blog.jankowalski.pl/2011/02" title="February 2011">F ebruary 2011</a></li> <li><a href="http://blog.jankowalski.pl/2011/01" title="January 2011">Ja nuary 2011</a></li> <li><a href="http://blog.jankowalski.pl/2010/12" title="December 2010">D ecember 2010</a></li> <li><a href="http://blog.jankowalski.pl/2010/11" title="November 2010">N ovember 2010</a></li> <li><a href="http://blog.jankowalski.pl/2010/10" title="October 2010">Oc tober 2010</a></li> <li><a href="http://blog.jankowalski.pl/2010/09" title="September 2010"> September 2010</a></li> <li><a href="http://blog.jankowalski.pl/2010/08" title="August 2010">Aug ust 2010</a></li> </ul> </aside></section><!-- #secondary .widget-area --> <footer id="colophon" role="contentinfo" class=" span12"> <div id="page-footer" class="well clearfix"> <span class="credits alignleft"> 2013 <a href="http://blog.jankowalski.pl/">johnnyjavago: java passion coding</a> , all rights reserved.</span> <div id= "site-generator"> <a href="http://wordpres s.org/" title="Semantic Personal Publishing Platform" target="_blank" rel="gener ator">Proudly powered by WordPress</a> </div> </div><!-- #page-footer .well .clearfix --> </footer ><!-- #colophon -->

</div><!-- #page --> </div><!-- .container --> <!-- 25 queries. 0.216 seconds. --> <script type="text/javascript" src="./Correct solution for Dominator tas k from Codility johnnyjavago java passion coding_files/prettify.js"></script> <script type="text/javascript" src="./Correct solution for Dominator task from C odility johnnyjavago java passion coding_files/load.js"></script> <script type="text/javascript" src="./Correct solution for Dominator task from C odility johnnyjavago java passion coding_files/bootstrap.min.js"></script> <script type="text/javascript" src="./Correct solution for Dominator task from C odility johnnyjavago java passion coding_files/the-bootstrap.min.js"></script> <script type="text/javascript" src="./Correct solution for Dominator task from C odility johnnyjavago java passion coding_files/comment-reply.min.js"></script> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-20629244-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.a sync = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://w ww') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefor e(ga, s); })(); </script> <!-- This Quick Cache file was built for ( blog.jankowalski.pl/correct-solution -for-dominator-task-from-codility.html ) in 0.21659 seconds, on Jul 2nd, 2013 at 8:26 am UTC. --> <!-- This Quick Cache file will automatically expire ( and be re-built automatic ally ) on Jul 2nd, 2013 at 9:26 am UTC --></body></html>

Vous aimerez peut-être aussi