You are on page 1of 28

<!DOCTYPE html> <!-- saved from url=(0091)http://stackoverflow.

com/questions/8623924/dictionaryruntime-codility-test/8623980#8623980 --> <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>python - Dictionary runtime (Codility Test) - Stack Overflow</title> <link rel="shortcut icon" href="http://cdn.sstatic.net/stackoverflow/img/fav icon.ico"> <link rel="apple-touch-icon image_src" href="./python - Dictionary runtime ( Codility Test) - Stack Overflow_files/apple-touch-icon.png"> <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="http://stackoverflow.com/opensearch.xml"> <script type="text/javascript" async="" src="./python - Dictionary runtime ( Codility Test) - Stack Overflow_files/adzerk1_2_4_43,adzerk2_2_17_45,adzerk3_2_4 _44"></script><script type="text/javascript" async="" src="./python - Dictionary runtime (Codility Test) - Stack Overflow_files/ga.js"></script><script type="te xt/javascript" async="" src="./python - Dictionary runtime (Codility Test) - Sta ck Overflow_files/quant.js"></script><script type="text/javascript" src="./pytho n - Dictionary runtime (Codility Test) - Stack Overflow_files/jquery.min.js"></s cript> <script type="text/javascript" src="./python - Dictionary runtime (Codility Test) - Stack Overflow_files/stub.js"></script> <link rel="stylesheet" type="text/css" href="./python - Dictionary runtime ( Codility Test) - Stack Overflow_files/all.css"> <link rel="canonical" href="http://stackoverflow.com/questions/8623924/dicti onary-runtime-codility-test"> <link rel="alternate" type="application/atom+xml" title="Feed for question & #39;Dictionary runtime (Codility Test)&#39;" href="http://stackoverflow.com/feed s/question/8623924"> <script type="text/javascript"> StackExchange.ready(function () { StackExchange.using("postValidation", function () { StackExchange.postValidation.initOnBlurAndSubmit($('#post-form') , 2, 'answer'); }); StackExchange.question.init({showAnswerHelp:true,totalCommentCount:0 ,shownCommentCount:0,highlightColor:'#F4A83D',backgroundColor:'#FFF',questionId: 8623924}); styleCode(); StackExchange.realtime.subscribeToQuestion('1', '8623924'); }); </script> <script type="text/javascript"> StackExchange.init({"stackAuthUrl":"https://stackauth.com","serverTime": 1372754454,"styleCode":true,"enableUserHovercards":true,"site":{"name":"Stack Ov erflow","description":"Q&A for professional and enthusiast programmers","isNotic esTabEnabled":true,"recaptchaPublicKey":"6LdchgIAAAAAAJwGpIzRQSOFaO0pU6s44Xt8aTw c","enableSocialMediaInSharePopup":true},"user":{"fkey":"9336b12e86af343415687d9 e813eec5f","isAnonymous":true}});

StackExchange.using.setCacheBreakers({"js/prettify-full.js":"6c261bebf56 a","js/moderator.js":"68a5f45d34d6","js/full-anon.js":"761e0ff892e6","js/full.js ":"b16edc73d2d1","js/wmd.js":"2f79c03846d5","js/third-party/jquery.autocomplete. min.js":"e5f01e97f7c3","js/mobile.js":"e8e23ad37820","js/help.js":"6e6623243cf6" ,"js/tageditor.js":"450c9e8426fc","js/tageditornew.js":"b6c68ad4c7dd","js/inline -tag-editing.js":"8e84e8a137f7","js/revisions.js":"7273bb714bba","js/review.js": "59e9b73580be","js/tagsuggestions.js":"aa48ef6154df","js/post-validation.js":"bb 996020492a","js/explore-qlist.js":"1c5bbd79b562"}); </script> <script type="text/javascript"> StackExchange.using("gps", function() { StackExchange.gps.init(true); }); </script> <script type="text/javascript"> StackExchange.ready(function () { $('#nav-tour').click(function () { StackExchange.using("gps", function() { StackExchange.gps.track("aboutpage.click", { aboutclick_ location: "headermain" }, true); }); }); }); </script> <script async="" type="text/javascript" src="./python - Dictionary runtime (Codi lity Test) - Stack Overflow_files/full-anon.js"></script><script type="text/java script">//cdn test - don't delete! </script><script async="" type="text/javascript" src="./python - Dictionary runt ime (Codility Test) - Stack Overflow_files/post-validation.js"></script><script async="" type="text/javascript" src="./python - Dictionary runtime (Codility Tes t) - Stack Overflow_files/prettify-full.js"></script><script type="text/javascri pt" src="./python - Dictionary runtime (Codility Test) - Stack Overflow_files/ad Feedback.js"></script><link rel="stylesheet" href="http://static.adzerk.net/Exte nsions/adFeedback.css"><link href="./python - Dictionary runtime (Codility Test) - Stack Overflow_files/sidebar.min.css" type="text/css" rel="stylesheet"></head > <body class="question-page"><div style="position: absolute;"><object id="_GPL_sw f" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://downloa d.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="tran sparent"><param name="allowScriptAccess" value="always"><param name="flashVars" value="keywordsURL=http%3A//i.tracksrv.com/kwd%3Fc%3DOjo6c3RhY2tvdmVyZmxvdy5jb20 6ei0xMDIxLTE3MzQ5MQ%253D%253D%26cb%3D_GPL.items.a652c.displayKeywords&amp;keywor ds=stack%20overflow%7Ca%20question%20and%20answer%20site%20for%20professional%20 and%20enthusiast%20programmers%7Cit%27s%7Cfree%7Cno%20registration%20required%7C tried%20a%20codility%20sample%20question%7Canswering%20in%20python%7Cnot%20getti ng%20100%20score%20because%7Cfailed%20to%20finish%20in%20time%20on%20large%20dat a%20set%7Cthe%20following%7Cthe%20question%7Ca%20non-empty%20zero-indexed%20arra y%20a%20consisting%20of%7Cintegers%7Cgiven%7Cthe%20first%20covering%20prefix%20o f%20array%20a%7Cthe%20smallest%20integer%7Csuch%20that%7Cand%20such%20that%20eve ry%20value%20that%20occurs%20in%20array%20a%20also%20occurs%20in%20sequence%7Cfo r%20example%7Cthe%20first%20covering%20prefix%20of%20the%20following%7Cbecause%2 0sequence%7Cequal%20to%7Ccontains%20all%20values%20that%20occur%20in%20array%20a %7Cmy%20answer%7Clen%7Creturn%7Cbit%7Crange%7Ckeys%7Cresult%7Cgive%20me%20100%20 for%20this%20question%20because%7Cthinks%20my%20algo%7Cand%20failed%20test%20cas es%20are%7Crandom%20test%7Celements%7C025%7Ctimeout%20error%20running%20time%7Cs ec%7Ctime%20limit%7C744%7Canalysis%7Cat%20first%7Cbelieve%20my%20code%7Cas%7Cass

ume%20the%20key%20part%20of%20my%20code%7Cin%20bit%7Chas%20constant%20run-time%7 Cbut%20perhaps%20on%20large%20data%20set%7Cthe%20hash%20function%20gives%20a%20l ot%20of%20collision%20so%20the%20runtime%7Cno%20longer%7Cdoes%7Cmeans%7Chave%20t his%20question%20because%7Chave%20seen%20other%20post%20where%20codility%20repor t%20an%7Csquare%20algo%20as%7Csuppose%20they%20will%20be%20consistent%20in%20the ir%20report%7Cif%20they%20really%20think%20my%20answer%7Cthen%7Creasonable%20bec ause%20my%20code%20only%20run%20past%20their%20time%20limit%20by%20less%20than%7 Csecond%7Chere%7Cassume%20their%20time%20limit%7Cfor%20an%7Calgo%20because%20thi s%7Cwhat%20they%20request%20in%20the%20question%7Cif%20that%7Cthe%20case%7Csee%2 0why%20an%7Cjust%7Csec%20slow%7Cthanks%7C147k%7Casked%7Cdec%7Ca%20list%7Ctesting %20if%20an%20element%7Cin%20a%20list%7Con%20the%20other%20hand%7Cin%20a%20dict%7 Cso%20change%7Cwith%20this%20change%7Cbelieve%20your%20algorithm%7Cwithout%20the %20change%7Canswered%7Csign%20up%20for%20our%20newsletter%20and%20get%20our%20to p%20new%20questions%20delivered%20to%20your%20inbox%7Cemail%20address%7Cdont%20k now%20if%7Cwill%20work%20for%20higher%20values%7Cclass%7Cprogram%7Cstatic%7Cvoid %7Cmain%7Cstring%7Cargs%7Clength%7Celse%7Cconsole%7Cwriteline%7Cjun%7Csign%20up% 20using%20google%7Csign%20up%20using%20facebook%7Csign%20up%20using%20stack%20ex change"><!--[if !IE]> <--> <object id="_GPL_swf" data="http://contentcache-a.aka maihd.net/items/it/swf/f.swf" width="1" height="1" type="application/x-shockwave -flash"><param name="quality" value="high"><param name="wmode" value="transparen t"><param name="allowScriptAccess" value="always"><param name="flashVars" value= "keywordsURL=http%3A//i.tracksrv.com/kwd%3Fc%3DOjo6c3RhY2tvdmVyZmxvdy5jb206ei0xM DIxLTE3MzQ5MQ%253D%253D%26cb%3D_GPL.items.a652c.displayKeywords&amp;keywords=sta ck%20overflow%7Ca%20question%20and%20answer%20site%20for%20professional%20and%20 enthusiast%20programmers%7Cit%27s%7Cfree%7Cno%20registration%20required%7Ctried% 20a%20codility%20sample%20question%7Canswering%20in%20python%7Cnot%20getting%201 00%20score%20because%7Cfailed%20to%20finish%20in%20time%20on%20large%20data%20se t%7Cthe%20following%7Cthe%20question%7Ca%20non-empty%20zero-indexed%20array%20a% 20consisting%20of%7Cintegers%7Cgiven%7Cthe%20first%20covering%20prefix%20of%20ar ray%20a%7Cthe%20smallest%20integer%7Csuch%20that%7Cand%20such%20that%20every%20v alue%20that%20occurs%20in%20array%20a%20also%20occurs%20in%20sequence%7Cfor%20ex ample%7Cthe%20first%20covering%20prefix%20of%20the%20following%7Cbecause%20seque nce%7Cequal%20to%7Ccontains%20all%20values%20that%20occur%20in%20array%20a%7Cmy% 20answer%7Clen%7Creturn%7Cbit%7Crange%7Ckeys%7Cresult%7Cgive%20me%20100%20for%20 this%20question%20because%7Cthinks%20my%20algo%7Cand%20failed%20test%20cases%20a re%7Crandom%20test%7Celements%7C025%7Ctimeout%20error%20running%20time%7Csec%7Ct ime%20limit%7C744%7Canalysis%7Cat%20first%7Cbelieve%20my%20code%7Cas%7Cassume%20 the%20key%20part%20of%20my%20code%7Cin%20bit%7Chas%20constant%20run-time%7Cbut%2 0perhaps%20on%20large%20data%20set%7Cthe%20hash%20function%20gives%20a%20lot%20o f%20collision%20so%20the%20runtime%7Cno%20longer%7Cdoes%7Cmeans%7Chave%20this%20 question%20because%7Chave%20seen%20other%20post%20where%20codility%20report%20an %7Csquare%20algo%20as%7Csuppose%20they%20will%20be%20consistent%20in%20their%20r eport%7Cif%20they%20really%20think%20my%20answer%7Cthen%7Creasonable%20because%2 0my%20code%20only%20run%20past%20their%20time%20limit%20by%20less%20than%7Csecon d%7Chere%7Cassume%20their%20time%20limit%7Cfor%20an%7Calgo%20because%20this%7Cwh at%20they%20request%20in%20the%20question%7Cif%20that%7Cthe%20case%7Csee%20why%2 0an%7Cjust%7Csec%20slow%7Cthanks%7C147k%7Casked%7Cdec%7Ca%20list%7Ctesting%20if% 20an%20element%7Cin%20a%20list%7Con%20the%20other%20hand%7Cin%20a%20dict%7Cso%20 change%7Cwith%20this%20change%7Cbelieve%20your%20algorithm%7Cwithout%20the%20cha nge%7Canswered%7Csign%20up%20for%20our%20newsletter%20and%20get%20our%20top%20ne w%20questions%20delivered%20to%20your%20inbox%7Cemail%20address%7Cdont%20know%20 if%7Cwill%20work%20for%20higher%20values%7Cclass%7Cprogram%7Cstatic%7Cvoid%7Cmai n%7Cstring%7Cargs%7Clength%7Celse%7Cconsole%7Cwriteline%7Cjun%7Csign%20up%20usin g%20google%7Csign%20up%20using%20facebook%7Csign%20up%20using%20stack%20exchange "></object> <!----> <!--[endif]----> </object></div><div style="position: absolu te; top: 0px; left: 0px; width: 1px; height: 1px; z-index: 2147483647;" id="_GPL _e6a00_parent_div"><object type="application/x-shockwave-flash" id="_GPL_e6a00_s wf" data="http://contentcache-a.akamaihd.net/items/e6a00/storage.swf?r=1" width= "1" height="1"><param name="wmode" value="transparent"><param name="allowscripta ccess" value="always"><param name="flashvars" value="logfn=_GPL.items.e6a00.log&

amp;onload=_GPL.items.e6a00.onload&amp;onerror=_GPL.items.e6a00.onerror&amp;LSON ame=gpl"></object></div> <noscript>&lt;div id="noscript-padding"&gt;&lt;/div&gt;</noscript> <div id="notify-container"></div> <div id="overlay-header"></div> <div id="custom-header"></div> <div class="container"> <div id="header" class="headeranon"> <div id="portalLink"> <a class="genu" onclick="StackExchange.ready(function(){genuwine .click();});return false;">Stack Exchange</a> </div> <div id="topbar"> <div id="hlinks"> <span id="hlinks-user"></span> <span id="hlinks-nav"> <a href="http://stackoverflow.com/ users/login?returnurl=%2fquestions%2f8623924%2fdictionary-runtime-codility-test% 2f8623980">sign up</a> <span class="lsep">|</span> <a href="http://stackoverflow.com/users/login?returnurl=%2fq uestions%2f8623924%2fdictionary-runtime-codility-test%2f8623980">log in</a> <span class="lsep">|</span> <a href="http://careers.stackoverflow.com/">careers 2.0</a> <span class="lsep">|</span> </span> <span id="hlinks-custom"></span> </div> <div id="hsearch"> <form id="search" action="http://stackoverflow.com/search" m ethod="get" autocomplete="off"> <div> <input autocomplete="off" name="q" class="textbox" p laceholder="search" tabindex="1" type="text" maxlength="240" size="28" value=""> </div> </form> </div> </div> <br class="cbt"> <div id="hlogo"> <a href="http://stackoverflow.com/"> Stack Overflow </a> </div> <div id="hmenus"> <div class="nav mainnavs mainnavsanon"> <ul> <li class="youarehere"><a id="nav-questions" href="h ttp://stackoverflow.com/questions">Questions</a></li> <li><a id="nav-tags" href="http://stackoverflow.com/ tags">Tags</a></li> <li><a id="nav-tour" href="http://stackoverflow.com/ about">Tour</a></li> <li><a id="nav-users" href="http://stackoverflow.com /users">Users</a></li> </ul>

</div> <div class="nav askquestion"> <ul> <li> <a id="nav-askquestion" href="http://stackoverflow.c om/questions/ask">Ask Question</a> </li> </ul> </div> </div> </div>

<div id="content"> <div itemscope="" itemtype="http://schema.org/Article"> <link itemprop="image" href="./python - Dictionary runtime (Codility Test) - Sta ck Overflow_files/apple-touch-icon.png"> <!--googleoff: snippet--> <div id="herobox-mini"> <div id="hero-content"> <span id="controls"> <a href="http://stackoverflow.com/about" id="tell-me-more" class="bu tton">Tell me more</a> <span id="close"><a title="click to dismiss"> </a></span> </span> <div id="blurb"> <span id="site-name">Stack Overflow</span> is a question and answer site for professional and enthusiast programmers. It's 100% free, no registra tion required. </div> </div> <script> $('#tell-me-more').click(function () { var clickSource = $("body").attr("class") + '-mini'; if ($("body").hasClass("questions-page")) { clickSource = 'questionpagemini'; } if ($("body").hasClass("home-page")) { clickSource = 'homepagemini'; } StackExchange.using("gps", function () { StackExchange.gps.track("aboutpage.click", { aboutclick_location : clickSource } , true); }); }); $('#herobox-mini #close').click(function () { StackExchange.using("gps", function () { StackExchange.gps.track("hero.action", { hero_action_type: "clos e" }, true); }); $.cookie("hero", "none", { path: "/" }); var $hero = $("#herobox-mini"); $hero.slideUp('fast', function () { $hero.remove(); }); return false;

}); </script> </div> <!--googleon: snippet--> <div id="question-header"> <h1 itemprop="name"><a href="http://stackoverflow.com/questions/8623924/dict ionary-runtime-codility-test" class="question-hyperlink">Dictionary runtime (Cod ility Test)</a></h1> </div> <div id="mainbar">

<div class="question" data-questionid="8623924" id="question"> <div class="everyonelovesstackoverflow adzerk-vote" id="adzerk1" ><a href="http://engine.adzerk.net/r?e=eyJhdiI6NDE0LCJhdCI6NCwiY20iOjg0NywiY2giO jExNzgsImNyIjo1OTI0LCJkaSI6IjEzOTljYjlhZDE2MjRlMGQ5ZGY5YTY1Y2QwYjhhZTNkIiwiZG0iO jEsImZjIjo4ODEwLCJmbCI6MjQ0NCwia3ciOiJweXRob24sY29kaWxpdHkiLCJudyI6MjIsInJmIjoia HR0cDovL3N0YWNrb3ZlcmZsb3cuY29tL3RhZ3MvY29kaWxpdHkvaG90IiwicnYiOjAsInByIjoxNTY4L CJzdCI6ODI3Nywiem4iOjQzLCJ1ciI6Imh0dHA6Ly9jYXJlZXJzLnN0YWNrb3ZlcmZsb3cuY29tLyJ9& s=3f4tJSyWcoqkCAeoIUXPO6FtgUQ" rel="nofollow" target="_blank" title=""><img src= "./python - Dictionary runtime (Codility Test) - Stack Overflow_files/0a96cc99c1 784d6abe3cae6b8c8bf013.png" title="" alt="" border="0" width="728" height="90">< /a><div class="adzerk-vote-controls" style="display: none;"><div class="adzerk-v ote-option adzerk-vote-up"><div class="adzerk-vote-icon"></div></div><div class= "adzerk-vote-option adzerk-vote-down"><div class="adzerk-vote-icon"></div></div> </div><div class="adzerk-vote-survey" style="display:none;"><form><span>No probl em. We won't show you that ad again. Why didn't you like it?</span><ul><li><labe l><input type="radio" value="12" name="downvoteReason">Uninteresting</label></li ><li><label><input type="radio" value="13" name="downvoteReason">Misleading</lab el></li><li><label><input type="radio" value="14" name="downvoteReason">Offensiv e</label></li><li><label><input type="radio" value="15" name="downvoteReason">Re petitive</label></li></ul><a href="http://stackoverflow.com/questions/8623924/di ctionary-runtime-codility-test/8623980#" class="adzerk-vote-cancel">Oops! I didn 't mean to do this.</a></form></div><img height="0px" width="0px" border="0" src ="./python - Dictionary runtime (Codility Test) - Stack Overflow_files/i.gif"></ div> <table> <tbody><tr> <td class="votecell"> <div class="vote"> <input type="hidden" value="8623924"> <a class="vote-up-off" title="This question shows research effort; it is use ful and clear">up vote</a> <span class="vote-count-post ">0</span> <a class="vote-down-off" title="This question does not show any research eff ort; it is unclear or not useful">down vote</a> <a class="star-off" href="http://stackoverflow.com/questions/8623924/diction ary-runtime-codility-test/8623980#" title="This is a favorite question (click ag ain to undo)">favorite</a> <div class="favoritecount"><b>1</b></div> </div>

</td> <td class="postcell"> <div> <div class="post-text" itemprop="description"> <p>I tried a codility sample question, answering in python. I am not get ting 100 score because it failed to finish in time on large data set.</p> <p><strong>The following is the question:</strong></p> <blockquote> <p>A non-empty zero-indexed array A consisting of N integers is given. The first covering prefix of array A is the smallest integer P such that 0 P &lt; N and such that every value that occurs in array A also occurs in sequence A[0], A[1], ..., A[P].</p> </blockquote> <p>For example, the first covering prefix of the following 5 element array A:</p>

<pre class="default prettyprint prettyprinted" style=""><code><span class="pln"> A</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]< /span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </s pan><span class="lit">2</span><span class="pln"> A</span><span class="pun">[</s pan><span class="lit">1</span><span class="pun">]</span><span class="pln"> </spa n><span class="pun">=</span><span class="pln"> </span><span class="lit">2</span> <span class="pln"> A</span><span class="pun">[</span><span class="lit">2</span> <span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><s pan class="pln"> </span><span class="lit">1</span><span class="pln"> A</span><span class="pun">[</span><span class="lit">3</span><span class="pun">]< /span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </s pan><span class="lit">0</span><span class="pln"> A</span><span class="pun">[</s pan><span class="lit">4</span><span class="pun">]</span><span class="pln"> </spa n><span class="pun">=</span><span class="pln"> </span><span class="lit">1</span> </code></pre> <p>is 3, because sequence <code>[ A[0], A[1], A[2], A[3] ]</code> equal to <code >[2, 2, 1, 0]</code>, contains all values that occur in array A.</p> <p><strong>My answer is:</strong></p> <pre class="default prettyprint prettyprinted" style=""><code><span class="kwd"> def</span><span class="pln"> ps </span><span class="pun">(</span><span class="pl n"> A </span><span class="pun">):</span><span class="pln"> N </span><span class="pun">=</span><span class="pln"> len</span><span class= "pun">(</span><span class="pln">A</span><span class="pun">);</span><span class=" pln"> </span><span class="kwd">if</span><span class="pln"> N </span><span class="p un">==</span><span class="pln"> </span><span class="lit">0</span><span class="pu n">:</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="p ln"> bit </span><span class="pun">=</span><span class="pln"> </span><span class=" pun">{}</span><span class="pln"> </span><span class="kwd">for</span><span class="pln"> i </span><span class=" kwd">in</span><span class="pln"> range</span><span class="pun">(</span><span cla ss="pln">N</span><span class="pun">):</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class= "kwd">not</span><span class="pln"> A</span><span class="pun">[</span><span class ="pln">i</span><span class="pun">]</span><span class="pln"> </span><span class=" kwd">in</span><span class="pln"> bit</span><span class="pun">.</span><span class

="pln">keys</span><span class="pun">():</span><span class="pln"> bit</span><span class="pun">[</span><span class="pln">A</span><span class="pun">[</span><span class="pln">i</span><span class="pun">]]</span><span c lass="pln"> </span><span class="pun">=</span><span class="pln"> </span><span cla ss="lit">1</span><span class="pln"> P </span><span class="pun">=</span><span class="pln"> i </span><span class="kwd">return</span><span class="pln"> P</span></code></pr e> <p><strong>Result:</strong></p> <p>It doesn't give me 100 for this question because it thinks my algo is O(N**3) , and failed test cases are</p> <pre class="default prettyprint prettyprinted" style=""><code><span class="pln"> random_n_log_100000 random test </span><span class="lit">100</span><span class="pln"> </span><span c lass="lit">000</span><span class="pln"> elements </span><span class="kwd">and</s pan><span class="pln"> n</span><span class="pun">/</span><span class="pln">log_2 n values</span><span class="pun">.</span><span class="pln"> </span><span class ="lit">10.025</span><span class="pln"> s</span><span class="pun">.</span><span c lass="pln"> TIMEOUT ERROR running time</span><span class="pun">:</span><span class="pln"> </span><span cla ss="pun">&gt;</span><span class="lit">10.02</span><span class="pln"> sec</span>< span class="pun">.,</span><span class="pln"> time limit</span><span class="pun"> :</span><span class="pln"> </span><span class="lit">9.82</span><span class="pln" > sec</span><span class="pun">.</span><span class="pln"> random_n_10000 random test </span><span class="lit">10</span><span class="pln"> </span><span cl ass="lit">000</span><span class="pln"> elements </span><span class="kwd">and</sp an><span class="pln"> values</span><span class="pun">.</span><span class="pln"> </span><span class="lit">1.744</span><span class="pln"> s</span><span class="pun ">.</span><span class="pln"> TIMEOUT ERROR running time</span><span class="pun">:</span><span class="pln"> </span><span cla ss="pun">&gt;</span><span class="lit">1.74</span><span class="pln"> sec</span><s pan class="pun">.,</span><span class="pln"> time limit</span><span class="pun">: </span><span class="pln"> </span><span class="lit">1.10</span><span class="pln"> sec</span><span class="pun">.</span><span class="pln"> random_n_100000 random test </span><span class="lit">100</span><span class="pln"> </span><span c lass="lit">000</span><span class="pln"> elements </span><span class="kwd">and</s pan><span class="pln"> values</span><span class="pun">.</span><span class="pln"> </span><span class="lit">10.025</span><span class="pln"> s</span><span class ="pun">.</span><span class="pln"> TIMEOUT ERROR running time</span><span class="pun">:</span><span class="pln"> </span><span cla ss="pun">&gt;</span><span class="lit">10.02</span><span class="pln"> sec</span>< span class="pun">.,</span><span class="pln"> time limit</span><span class="pun"> :</span><span class="pln"> </span><span class="lit">9.94</span><span class="pln" > sec</span><span class="pun">.</span></code></pre> <p><strong>Analysis:</strong></p> <ol> <li><p>At first I believe my code is O(N) as I assume the key part of my code, A [i] in bit.keys(), has constant run-time, i.e. O(1). But perhaps on large data s et, the hash function gives a lot of collision so the runtime is no longer O(1)? </p></li> <li><p>Does O(N**3) means O(N^3)? I have this question because I have seen other

post where codility report an N square algo as O(N^2). So I suppose they will b e consistent in their report?</p></li> <li><p>If they really think my answer is O(N^3), then is it reasonable because m y code only run past their time limit by less than 1 second? Here I assume their time limit is for an O(N) algo because this is what they request in the questio n. If that is the case, I can't see why an O(N^3) algo is just &gt;1 sec slow??< /p></li> </ol> <p>Thanks KM </p> </div> <div class="post-taglist"> <a href="http://stackoverflow.com/questions/tagged/python" class="post-t ag" title="show questions tagged &#39;python&#39;" rel="tag">python</a> <a href= "http://stackoverflow.com/questions/tagged/codility" class="post-tag" title="sho w questions tagged &#39;codility&#39;" rel="tag">codility</a> </div> <table class="fw"> <tbody><tr> <td class="vt">

<div class="post-menu"><a href="http://stackoverflow.com/q/8623924" title="short permalink to this question" class="short-link" id="link-post-8623924">share</a> <span class="lsep">|</span><a href="http://stackoverflow.com/posts/8623924/edit" class="suggest-edit-post" title="">improve this question</a></div> </td> <td align="right" class="post-signature"> <div class="user-info user-hover"> <div class="user-action-time"> <a href="http://stackoverflow.com/posts/8623924/revi sions" title="show all edits to this post">edited <span title="2011-12-24 10:25: 00Z" class="relativetime">Dec 24 '11 at 10:25</span></a> </div> <div class="user-gravatar32"> <a href="http://stackoverflow.com/users/190597/unutbu"><div class="" ><img src="./python - Dictionary runtime (Codility Test) - Stack Overflow_files/ dd069899166bba0f0e53d3097452b00b" alt="" width="32" height="32"></div></a> </div> <div class="user-details"> <a href="http://stackoverflow.com/users/190597/unutbu">unutbu</a><br > <span class="reputation-score" title="reputation score 147428" dir=" ltr">147k</span><span title="8 gold badges"><span class="badge1"></span><span cl ass="badgecount">8</span></span><span title="157 silver badges"><span class="bad ge2"></span><span class="badgecount">157</span></span><span title="279 bronze ba dges"><span class="badge3"></span><span class="badgecount">279</span></span>

</div> </div> </td> <td class="post-signature owner"> <div class="user-info "> <div class="user-action-time"> asked <span title="2011-12-24 10:19:34Z" cla ss="relativetime">Dec 24 '11 at 10:19</span> </div> <div class="user-gravatar32"> <a href="http://stackoverflow.com/users/1114448/gary"><div class=""> <img src="./python - Dictionary runtime (Codility Test) - Stack Overflow_files/b c4786e0ab9e59606d01d1e7e7ff2e03" alt="" width="32" height="32"></div></a> </div> <div class="user-details"> <a href="http://stackoverflow.com/users/1114448/gary">Gary</a><br> <span class="reputation-score" title="reputation score" dir="ltr">66 </span><span title="6 bronze badges"><span class="badge3"></span><span class="ba dgecount">6</span></span> </div> </div> </td> </tr> </tbody></table> </div> </td> </tr> <tr> <td class="votecell"></td> <td> <div id="comments-8623924" class="comments dno"> <table> <tbody> <tr><td></td><td></td></tr> </tbody> </table> </div> </td> </tr> </div> </tbody></table>

<div id="answers"> <a name="tab-top"></a> <div id="answers-header"> <div class="subheader answers-subheader"> <h2> 2 Answers </h2> <div id="tabs">

<a href="http://stackoverflow.com/questions/8623924/dictionary-r untime-codility-test?answertab=active#tab-top" title="Answers with the latest ac tivity first">active</a> <a href="http://stackoverflow.com/questions/8623924/dictionary-runtime-codilitytest?answertab=oldest#tab-top" title="Answers in the order they were provided">o ldest</a> <a class="youarehere" href="http://stackoverflow.com/questions/8623924/dictionar y-runtime-codility-test?answertab=votes#tab-top" title="Answers with the highest score first">votes</a> </div> </div> </div>

<a name="8623980"></a> <div id="answer-8623980" class="answer" data-answerid="8623980" style=""> <table> <tbody><tr> <td class="votecell"> <div class="vote"> <input type="hidden" value="8623980"> <a class="vote-up-off" title="This answer is useful">up vote</a> <span class="vote-count-post ">7</span> <a class="vote-down-off" title="This answer is not useful">down vote</a> </div> </td>

<td class="answercell"> <div class="post-text"><p><code>bit.keys()</code> is a list. Testing if an e lement is in a list is O(n). On the other hand, testing if an element is in a dict is O(1). So change</p> <pre class="default prettyprint prettyprinted" style=""><code><span class="kwd"> if</span><span class="pln"> </span><span class="kwd">not</span><span class="pln" > A</span><span class="pun">[</span><span class="pln">i</span><span class="pun"> ]</span><span class="pln"> </span><span class="kwd">in</span><span class="pln"> bit</span><span class="pun">.</span><span class="pln">keys</span><span class="pu n">():</span></code></pre> <p>to </p> <pre class="default prettyprint prettyprinted" style=""><code><span class="kwd"> if</span><span class="pln"> </span><span class="kwd">not</span><span class="pln" > A</span><span class="pun">[</span><span class="pln">i</span><span class="pun"> ]</span><span class="pln"> </span><span class="kwd">in</span><span class="pln"> bit</span><span class="pun">:</span></code></pre> <p>With this change, I believe your algorithm is O(n).</p>

<p>(Without the change, I believe your algorithm is O(n^2), <strong>not</strong> O(n^3).)</p> </div> <table class="fw"> <tbody><tr> <td class="vt">

<div class="post-menu"><a href="http://stackoverflow.com/a/8623980" title="short permalink to this answer" class="short-link" id="link-post-8623980">share</a><s pan class="lsep">|</span><a href="http://stackoverflow.com/posts/8623980/edit" c lass="suggest-edit-post" title="">improve this answer</a></div> </td>

<td align="right" class="post-signature">

<div class="user-info user-hover"> <div class="user-action-time"> answered <span title="2011-12-24 10:33:4 4Z" class="relativetime">Dec 24 '11 at 10:33</span> </div> <div class="user-gravatar32"> <a href="http://stackoverflow.com/users/190597/unutbu"><div class="" ><img src="./python - Dictionary runtime (Codility Test) - Stack Overflow_files/ dd069899166bba0f0e53d3097452b00b" alt="" width="32" height="32"></div></a> </div> <div class="user-details"> <a href="http://stackoverflow.com/users/190597/unutbu">unutbu</a><br > <span class="reputation-score" title="reputation score 147428" dir=" ltr">147k</span><span title="8 gold badges"><span class="badge1"></span><span cl ass="badgecount">8</span></span><span title="157 silver badges"><span class="bad ge2"></span><span class="badgecount">157</span></span><span title="279 bronze ba dges"><span class="badge3"></span><span class="badgecount">279</span></span> </div> </div> </td> </tr> </tbody></table> </td> </tr>

<tr>

<td class="votecell"></td> <td> <div id="comments-8623980" class="comments dno"> <table> <tbody> <tr><td></td><td></td></tr> </tbody> </table> </div> </td> </tr> </tbody></table> </div> <div class="newsletter-anon"> <img src="./python - Dictionary runtime (Codility Test) - Stack Overflow_fil es/apple-touch-icon.png" class="newsletter-logo"> <div class="newsletter-container"> <h2>Did you find this question interesting? Try our newsletter</h2> <p class="newsletter-description"> Sign up for our newsletter and get our top new questions delivered t o your inbox (<a href="http://stackexchange.com/newsletters/newsletter?site=stac koverflow.com" id="newsletter-preview">see an example</a>). </p> <form id="anon-newsletter-form"> <input type="email" style="opacity: 1; position: absolute; backgroun d-color: white; color: black; -webkit-text-fill-color: black; width: 149px; heig ht: 16px; line-height: normal; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 13px; text-align: start; border: 1px solid rgb(15 3, 153, 153);" class="actual-edit-overlay" disabled="disabled"><input type="emai l" id="newsletter-email-input" style="opacity: 0.4; z-index: 1; position: relati ve;" class="edit-field-overlayed"> <span class="edit-field-overlay">email address</span> <input type="submit" value="Subscribe" id="newsletter-email-submit"> </form> </div> </div> <script> StackExchange.ready(function () { StackExchange.newsletterAd.init(); }); StackExchange.helpers.bindHelpOverlayEvents($("#newsletter-email-input")); StackExchange.using("gps", function () { StackExchange.gps.track("newsletter.show", { newsletter_type: "nlquestio nad" }, true); }); $('#anon-newsletter-form').submit(function () { var $form = $(this); var $input = $form.find('#newsletter-email-input'); var $submit = $form.find('#newsletter-email-submit'); var email = $.trim($input.val()); if (email.length == 0) {

return false; } StackExchange.helpers.addSpinner($form); $.ajax({ url: '/newsletter/signup/anon', type: 'POST', dataType: 'json', data: { email: email, viaAnonNewsletterAd: true }, success: function (data) { if (data.status == 'confirmed' && !data.error) { $input.attr('disabled', true); $submit.replaceWith('<div style="margin-top: 10px;"><strong> Subscribed!</strong></div>'); } else if (data.status == 'unconfirmed' && !data.error) { $input.attr('disabled', true); $submit.replaceWith('<div style="margin-top: 10px;"><strong> Success!</strong> Please click the link in the confirmation email to activate yo ur subscription.</div>'); } else { $form.showErrorMessage(data.error || 'There was a problem si gning up for the newsletter. Please try again later.'); } }, error: function () { $form.showErrorMessage('There was a problem signing up for the n ewsletter. Please try again later.'); }, complete: function () { StackExchange.helpers.removeSpinner($form); } }); return false; }); </script> <a name="17340990"></a> <div id="answer-17340990" class="answer" data-answerid="17340990"> <table> <tbody><tr> <td class="votecell"> <div class="vote"> <input type="hidden" value="17340990"> <a class="vote-up-off" title="This answer is useful">up vote</a> <span class="vote-count-post ">0</span> <a class="vote-down-off" title="This answer is not useful">down vote</a> </div> </td>

<td class="answercell">

<div class="post-text"><pre class="default prettyprint prettyprinted" style= ""><code><span class="typ">Tried</span><span class="pln"> C</span><span class="c om"># code. dont know if it will work for higher values</span><span class="pln">

</span><span class="kwd">class</span><span class="pln"> </span><span class="typ ">Program</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class= "kwd">void</span><span class="pln"> </span><span class="typ">Main</span><span cl ass="pun">(</span><span class="kwd">string</span><span class="pun">[]</span><spa n class="pln"> args</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">int</span><span class="pun">[]</span><span clas s="pln"> A </span><span class="pun">=</span><span class="pln"> </span><span clas s="pun">{</span><span class="lit">2</span><span class="pun">,</span><span class= "lit">1</span><span class="pun">,</span><span class="lit">1</span><span class="p un">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit ">3</span><span class="pun">};</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> i </span><span cla ss="pun">,</span><span class="pln">n</span><span class="pun">=</span><span class ="pln">A</span><span class="pun">.</span><span class="typ">Length</span><span cl ass="pun">;</span><span class="pln"> </span><span class="kwd">for</span><span class="pln"> </span><span class="p un">(</span><span class="pln">i</span><span class="pun">=</span><span class="pln "> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">&lt;</span><span class="pln">n</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><span class= "pun">(</span><span class="pln">A</span><span class="pun">.</span><span class="t yp">Contains</span><span class="pun">(</span><span class="pln">i</span><span cla ss="pun">))</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">//</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> p </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="pun">}</span><span class="pln"> </span><span class="typ">Console</span><span class="pun">.</span><span clas s="typ">WriteLine</span><span class="pun">(</span><span class="str">"p not found "</span><span class="pun">);</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="pun">}</span></code></pre> </div> <table class="fw"> <tbody><tr> <td class="vt">

<div class="post-menu"><a href="http://stackoverflow.com/a/17340990" title="shor t permalink to this answer" class="short-link" id="link-post-17340990">share</a> <span class="lsep">|</span><a href="http://stackoverflow.com/posts/17340990/edit " class="suggest-edit-post" title="">improve this answer</a></div> </td>

<td align="right" class="post-signature">

<div class="user-info "> <div class="user-action-time"> answered <span title="2013-06-27 10:42:2 8Z" class="relativetime">Jun 27 at 10:42</span> </div> <div class="user-gravatar32"> <a href="http://stackoverflow.com/users/2521798/user2521798"><div cl ass=""><img src="./python - Dictionary runtime (Codility Test) - Stack Overflow_ files/3ee467a43002dc846b8db4c43d5a5058" alt="" width="32" height="32"></div></a> </div> <div class="user-details"> <a href="http://stackoverflow.com/users/2521798/user2521798">user252 1798</a><br> <span class="reputation-score" title="reputation score" dir="ltr">11 </span><span title="1 bronze badge"><span class="badge3"></span><span class="bad gecount">1</span></span> </div> </div> </td> </tr> </tbody></table> </td> </tr>

<tr> <td class="votecell"></td> <td> <div id="comments-17340990" class="comments dno"> <table> <tbody> <tr><td></td><td></td></tr> </tbody> </table> </div>

</td> </tr> </tbody></table> </div> <a name="new-answer"></a> <form id="post-form" action="http://stackoverflow.com/questions/8623924/answ er/submit" method="post" class="post-form"> <input type="hidden" id="post-id" value="8623924"> <h2 class="space">Your Answer</h2>

<script type="text/javascript"> StackExchange.ready(function() { initTagRenderer("".split(" "), "".split(" ")); prepareEditor({ heartbeatType: 'answer', bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".discard-answer" ,immediatelyShowMarkdownHelp:true }); }); </script> <div id="post-editor" class="post-editor"> <div style="position: relative;"> <div class="wmd-container"> <div id="wmd-button-bar" class="wmd-button-bar"><ul id="wmd-button-r ow" class="wmd-button-row"><li id="wmd-bold-button" class="wmd-button" style="le ft: 0px;"><span style="background-position: 0px -20px;"></span></li><li id="wmditalic-button" class="wmd-button" style="left: 25px;"><span style="background-po sition: -20px -20px;"></span></li><li id="wmd-spacer1" class="wmd-spacer" style= "left: 50px;"><span style="background-position: -40px -20px;"></span></li><li id ="wmd-link-button" class="wmd-button" style="left: 75px;"><span style="backgroun d-position: -40px -20px;"></span></li><li id="wmd-quote-button" class="wmd-butto n" style="left: 100px;"><span style="background-position: -60px -20px;"></span>< /li><li id="wmd-code-button" class="wmd-button" style="left: 125px;"><span style ="background-position: -80px -20px;"></span></li><li id="wmd-image-button" class ="wmd-button" style="left: 150px;"><span style="background-position: -100px -20p x;"></span></li><li id="wmd-spacer2" class="wmd-spacer" style="left: 175px;"><sp an style="background-position: -120px -20px;"></span></li><li id="wmd-olist-butt on" class="wmd-button" style="left: 200px;"><span style="background-position: -1 20px -20px;"></span></li><li id="wmd-ulist-button" class="wmd-button" style="lef t: 225px;"><span style="background-position: -140px -20px;"></span></li><li id=" wmd-heading-button" class="wmd-button" style="left: 250px;"><span style="backgro und-position: -160px -20px;"></span></li><li id="wmd-hr-button" class="wmd-butto n" style="left: 275px;"><span style="background-position: -180px -20px;"></span> </li><li id="wmd-spacer3" class="wmd-spacer" style="left: 300px;"><span style="b ackground-position: -200px -20px;"></span></li><li id="wmd-undo-button" class="w md-button" style="left: 325px;"><span style="background-position: -200px -20px;" ></span></li><li id="wmd-redo-button" class="wmd-button" style="left: 350px;"><s

pan style="background-position: -220px -20px;"></span></li></ul></div> <textarea id="wmd-input" class="wmd-input" name="post-text" cols="92 " rows="15" tabindex="101" data-min-length=""></textarea> </div> </div> <div class="fl" style="margin-top: 8px; height:24px;">&nbsp;</div> <div id="draft-saved" class="draft-saved community-option fl" style="margintop: 8px; height:24px; display:none;">draft saved</div> <div id="draft-discarded" class="draft-discarded community-option fl" style= "margin-top: 8px; height:24px; display:none;">draft discarded</div>

<div id="wmd-preview" class="wmd-preview"></div> <div></div> <div class="edit-block"> <input id="fkey" name="fkey" type="hidden" value="9336b12e86af343415687d 9e813eec5f"> <input id="author" name="author" type="text"> </div> </div> <div style="position: relative;"> <div class="form-item new-post-login"> <div class="new-login-form"> <div class="new-login-left"> <h3>Sign up or <a id="login-link" href="http://stackover flow.com/users/login?returnurl=%2fquestions%2f8623924%2fdictionary-runtime-codil ity-test%23new-answer">log in</a></h3> <script type="text/javascript"> StackExchange.ready(function () { StackExchange.helpers.onClickDraftSave('#login-l ink'); }); </script> <div class="preferred-login google-login"> <p><span class="icon"></span><span>Sign up using Goo gle</span></p> </div> <div class="preferred-login facebook-login"> <p><span class="icon"></span><span>Sign up using Fac ebook</span></p> </div> <div class="preferred-login stackexchange-login"> <p><span class="icon"></span><span>Sign up using Sta ck Exchange</span></p> </div> </div> <input type="hidden" name="manual-openid" class="manual-open id"> <input type="hidden" name="use-facebook" class="use-facebook " value="false"> <input type="button" class="submit-openid" value="Submit" st yle="display:none"> <div class="new-login-right"> <h3>Post as a guest</h3> <div class="form-item"> <table>

<tbody><tr> <script type="text/javascript"> StackExchange.ready(function () { StackExchange.helpers.bindHelpOverlayEvents($('.vm input')); }); </script> <td class="vm"> <div> <label for="display-name">Name</label> <input id="display-name" name="display-name" type="text" siz e="30" maxlength="30" value="" tabindex="105"> </div> <div> <label for="m-address">Email</label> <input id="m-address" name="m-address" type="text" size="30" maxlength="100" value="" tabindex="106"> <span class="edit-field-overlay">required, but not shown</sp an> </div> </td> </tr> </tbody></table> </div> </div> </div> </div> <script type="text/javascript"> StackExchange.ready( function () { StackExchange.openid.initPostLogin('.new-post-login', '% 2fquestions%2f8623924%2fdictionary-runtime-codility-test%23new-answer'); } ); </script> <noscript> &lt;h3&gt;Post as a guest&lt;/h3&gt; &lt;div class="form-item"&gt; &lt;table&gt; &lt;tr&gt; &lt;script type="text/javascript"&gt; StackExchange.ready(function () { StackExchange.helpers.bindHelpOverlayEvents($('.vm input')); }); &lt;/script&gt; &lt;td class="vm"&gt; &lt;div&gt; &lt;label for="display-name"&gt;Name&lt;/label&gt; &lt;input id="display-name" name="display-name" type="text" size="30" maxlength="30" value="" tabindex="105"&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="m-address"&gt;Email&lt;/label&gt; &lt;input id="m-address" name="m-address" type="text" size=" 30" maxlength="100" value="" tabindex="106"&gt; &lt;span class="edit-field-overlay"&gt;required, but not sho wn&lt;/span&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt;

&lt;/table&gt; &lt;/div&gt; </noscript> </div> <div class="form-submit cbt"> <input id="submit-button" type="submit" value="Post Your Answer" tab index="110"> <a href="http://stackoverflow.com/questions/8623924/dictionary-runti me-codility-test/8623980#" class="discard-answer dno">discard</a> <p class="privacy-policy-agreement"> By posting your answer, you agree to the <a href="http://stackexchange.com/legal/privacy-policy" target="_blank"> privacy policy</a> and <a href="http://stackexchange.com/legal/terms-of-service" target="_blank ">terms of service</a>. </p> <input type="hidden" name="legalLinksShown" value="1"> </div> </form>

<h2 class="bottom-notice"> Not the answer you're looking for? Browse other questions tagged <a href="http://stackoverflow.com/ques tions/tagged/python" class="post-tag" title="show questions tagged &#39;python&# 39;" rel="tag">python</a> <a href="http://stackoverflow.com/questions/tagged/cod ility" class="post-tag" title="show questions tagged &#39;codility&#39;" rel="ta g">codility</a> or <a href="http://stackoverflow.com/questions/ask">ask your own question</a>. </h2> </div> </div> <div id="sidebar" class="show-votes"> <div class="module question-stats"> <p class="label-key">tagged</p> <div class="tagged"><a href="http://stackoverflow.com/questions/tagged/p ython" class="post-tag" title="show questions tagged &#39;python&#39;" rel="tag" >python</a>&nbsp;<span class="item-multiplier"><span class="item-multiplier-x"> </s pan>&nbsp;<span class="item-multiplier-count">199713</span></span><br> <a href="http://stackoverflow.com/questions/tagged/codility" class="post-tag" ti tle="show questions tagged &#39;codility&#39;" rel="tag">codility</a>&nbsp;<span class="item-multiplier"><span class="item-multiplier-x"> </span>&nbsp;<span class= "item-multiplier-count">21</span></span><br> </div> <table id="qinfo"> <tbody><tr> <td><p class="label-key">asked</p></td> <td style="padding-left:10px"><p class="label-key" title="2011-1 2-24 10:19:34Z"><b>1 year ago</b></p></td> </tr> <tr> <td><p class="label-key">viewed</p></td> <td style="padding-left:10px"> <p class="label-key"> <b>2195 times</b>

</p> </td> </tr> <tr> <td><p class="label-key">active</p></td> <td style="padding-left:10px"><p class="label-key"><b><a href="h ttp://stackoverflow.com/questions/8623924/dictionary-runtime-codility-test/86239 80?lastactivity" class="lastactivity-link" title="2013-06-27 10:42:28Z">4 days a go</a></b></p></td> </tr> </tbody></table> </div> <div class="module community-bulletin" data-tracker="cb=1"> <h4>Community Bulletin</h4> <div class="related"> <div class="spacer"> <div class="bulletin-item-type"><a href="http://blog.stackoverflow.c om/?cb=1" class="event-date" target="_blank">blog</a></div> <div class="bulletin-item-content"> <a href="http://blog.stackoverflow.com/2013/07/say-hi-to-nine-of -our-newest-newbies/?cb=1" class="question-hyperlink" target="_blank">Say Hi to Nine of Our Newest Newbies</a> </div> <br class="cbt"> </div> </div> </div> <script type="text/javascript"> var scriptSrc = "http://engine.adzerk.net/z/8277/adzerk1_2_4 _43,adzerk2_2_17_45,adzerk3_2_4_44?keywords=python,codility"; if (document.referrer) { if (/\?/.test(scriptSrc)) scriptSrc += "&"; else scriptSrc += "?"; scriptSrc += "xReferrer=" + document.referrer; } StackExchange.ready(function() { var z = document.createElement("script"); z.type = "text/javascript"; z.async = "true"; z.src = scriptSrc; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(z, s); }); </script> <div class="everyonelovesstackoverflow adzerk-vote" id="adzerk2"><a href="http://engine.adzerk.net/r?e=eyJhdiI6NDE0LCJhdCI6MTcsImNtIjo4NDcsImNoIjoxM Tc4LCJjciI6ODIxMSwiZGkiOiIxNmFjMDI3NDI2ZjI0YjBiODdkMTM0MDE4ZDJkMzVmNSIsImRtIjoxL CJmYyI6MTMwMzksImZsIjoyNDQ0LCJrdyI6InB5dGhvbixjb2RpbGl0eSIsIm53IjoyMiwicmYiOiJod HRwOi8vc3RhY2tvdmVyZmxvdy5jb20vdGFncy9jb2RpbGl0eS9ob3QiLCJydiI6MCwicHIiOjE1NjgsI nN0Ijo4Mjc3LCJ6biI6NDUsInVyIjoiaHR0cDovL2NhcmVlcnMuc3RhY2tvdmVyZmxvdy5jb20vIn0&s =-ypqBG2Hiou9Q9BvF-y8QW6W0cc" rel="nofollow" target="_blank" title=""><img src=" ./python - Dictionary runtime (Codility Test) - Stack Overflow_files/bd294ce7ff4 c43b6aad4aa4169fb819b.jpg" title="" alt="" border="0" width="220" height="250">< /a><div class="adzerk-vote-controls" style="display:none;"><div class="adzerk-vo te-option adzerk-vote-up"><div class="adzerk-vote-icon"></div></div><div class=" adzerk-vote-option adzerk-vote-down"><div class="adzerk-vote-icon"></div></div>< /div><div class="adzerk-vote-survey" style="display:none;"><form><span>No proble

m. We won't show you that ad again. Why didn't you like it?</span><ul><li><label ><input type="radio" value="12" name="downvoteReason">Uninteresting</label></li> <li><label><input type="radio" value="13" name="downvoteReason">Misleading</labe l></li><li><label><input type="radio" value="14" name="downvoteReason">Offensive </label></li><li><label><input type="radio" value="15" name="downvoteReason">Rep etitive</label></li></ul><a href="http://stackoverflow.com/questions/8623924/dic tionary-runtime-codility-test/8623980#" class="adzerk-vote-cancel">Oops! I didn' t mean to do this.</a></form></div><img height="0px" width="0px" border="0" src= "./python - Dictionary runtime (Codility Test) - Stack Overflow_files/i(1).gif"> </div> <div id="hireme"> <a href="http://careers.stackoverflow.com/jobs?a=12" class ="top" target="_blank"></a> <ul class="jobs"> <li> <a href="http://careers.stack overflow.com/jobs/34545/worship-worthy-frontend-developer-wanted-idyllic-softwar e?a=EOwfwmA" target="_blank" title="Worship-worthy Frontend Developer Wanted! Ja vascript // Html // CSS at Idyllic Software. Click to learn more."> Worship-wort hy Frontend Developer Wanted! Javascript // <br> <span class="company">Idyllic Softw are</span> <span class="location">Pune, India</span> </a> </li> <li> <a href="ht tp://careers.stackoverflow.com/jobs/34476/go-hackers-thomson-reuters?a=EJrJsha" target="_blank" title="Go Hackers at Thomson Reuters. Click to learn more."> Go Hackers<br> <span class="company">Thomson Reuters</span> <span class="location"> New York, NY / remote</span> </a> </li> <li> <a href="http://careers.stackoverfl ow.com/jobs/36108/customer-support-consultant-engineer-bigmachines?a=GEZHcJO" ta rget="_blank" title="Customer Support Consultant/Engineer at BigMachines. Click to learn more."> Customer Support Consultant/Engineer<br> <span class="company"> BigMachines</span> <span class="location">Chicago, IL</span> </a> </li> </ul> <i mg alt="" class="impression" src="./python - Dictionary runtime (Codility Test) - Stack Overflow_files/EOwfwmA-EJrJsha-GEZHcJO-12" style="display:none"></div>

<div class="module sidebar-linked"> <h4 id="h-linked">Linked</h4> <div class="linked" data-tracker="lq=1"> <div class="spacer"> <a href="http://stackoverflow.com/q/8624083?lq=1" title="Vote score (upvotes - d ownvotes)"> <div class="answer-votes default">0</div> </a> <a href="http://stackoverflow.com/questions/8624083/dictionary-runtime-codilitytest-repost?lq=1" class="question-hyperlink">Dictionary runtime (Codility Test) Repost</a> </div> </div> </div> <div class="module sidebar-related"> <h4 id="h-related">Related</h4> <div class="related" data-tracker="rq=1"> <div class="spacer"> <a href="http://stackoverflow.com/q/4703047?rq=1" title="Vote score (upvotes - d ownvotes)"> <div class="answer-votes answered-accepted default">4</div> </a> <a href="http://stackoverflow.com/questions/4703047/review-of-a-codility-test-pa ir-sum-even-count?rq=1" class="question-hyperlink">review of a codility test - p air_sum_even_count</a> </div> <div class="spacer">

<a href="http://stackoverflow.com/q/8624083?rq=1" title="Vote score (upvotes - d ownvotes)"> <div class="answer-votes default">0</div> </a> <a href="http://stackoverflow.com/questions/8624083/dictionary-runtime-codilitytest-repost?rq=1" class="question-hyperlink">Dictionary runtime (Codility Test) Repost</a> </div> <div class="spacer"> <a href="http://stackoverflow.com/q/9439352?rq=1" title="Vote score (upvotes - d ownvotes)"> <div class="answer-votes answered-accepted default">2</div> </a> <a href="http://stackoverflow.com/questions/9439352/codility-fibonacci-solution? rq=1" class="question-hyperlink">Codility Fibonacci Solution</a> </div> <div class="spacer"> <a href="http://stackoverflow.com/q/10146093?rq=1" title="Vote score (upvotes downvotes)"> <div class="answer-votes default">0</div> </a> <a href="http://stackoverflow.com/questions/10146093/codility-extreme-large-numb er-error?rq=1" class="question-hyperlink">Codility extreme large Number error</a > </div> <div class="spacer"> <a href="http://stackoverflow.com/q/12417383?rq=1" title="Vote score (upvotes downvotes)"> <div class="answer-votes answered-accepted default">9</div> </a> <a href="http://stackoverflow.com/questions/12417383/programming-test-codility-d ominator?rq=1" class="question-hyperlink">Programming Test - Codility - Dominato r</a> </div> <div class="spacer"> <a href="http://stackoverflow.com/q/15490659?rq=1" title="Vote score (upvotes downvotes)"> <div class="answer-votes default">0</div> </a> <a href="http://stackoverflow.com/questions/15490659/concrete-disks-codility-err or?rq=1" class="question-hyperlink">Concrete Disks Codility Error</a> </div> <div class="spacer"> <a href="http://stackoverflow.com/q/15740266?rq=1" title="Vote score (upvotes downvotes)"> <div class="answer-votes default">1</div> </a> <a href="http://stackoverflow.com/questions/15740266/do-you-know-any-codility-li ke-tests-for-front-end-developement?rq=1" class="question-hyperlink">Do you know any Codility-like tests for Front-end Developement?</a> </div> <div class="spacer"> <a href="http://stackoverflow.com/q/16737810?rq=1" title="Vote score (upvotes downvotes)"> <div class="answer-votes answered-accepted default">1</div> </a> <a href="http://stackoverflow.com/questions/16737810/is-this-related-to-a-graphcut-edge-bridge-find-the-fast-path-in-time-from-ho?rq=1" class="question-hyperli nk">Is this related to a graph cut-edge (bridge)? Find the fast path in time fro m home to a shop/store</a>

</div> <div class="spacer"> <a href="http://stackoverflow.com/q/16953803?rq=1" title="Vote score (upvotes downvotes)"> <div class="answer-votes default">0</div> </a> <a href="http://stackoverflow.com/questions/16953803/codility-certification-june -2013?rq=1" class="question-hyperlink">codility certification june 2013</a> </div> <div class="spacer"> <a href="http://stackoverflow.com/q/17164164?rq=1" title="Vote score (upvotes downvotes)"> <div class="answer-votes default">0</div> </a> <a href="http://stackoverflow.com/questions/17164164/javascript-codility-demo-so lution?rq=1" class="question-hyperlink">JavaScript Codility Demo Solution</a> </div> </div> </div> </div> <div id="feed-link"> <div id="feed-link-text"><a href="http://stackoverflow.com/feeds/question/86 23924" title="feed of this question and its answers"><span class="feed-icon"></s pan>question feed</a></div> </div> <script type="text/javascript"> StackExchange.ready(function(){$.get('/posts/8623924/ivc/7ea7');}); </script> <noscript> &lt;div&gt;&lt;img src="/posts/8623924/ivc/7ea7" class="dno" alt="" width="0 " height="0"&gt;&lt;/div&gt; </noscript><div style="display:none" id="prettify-lang">default</div></div> </div> </div> <div id="footer" class="categories"> <div class="footerwrap"> <div id="footer-menu"> <div class="top-footer-links"> <a href="http://stackoverflow.com/about">about</a> <a href="http://stackoverflow.com/help">help</a> <a href="http://stackoverflow.com/help/badges">badges</a > <a href="http://blog.stackexchange.com/?blb=1">blog</a> <a href="http://chat.stackoverflow.com/">chat</a> <a href="http://data.stackexchange.com/">data</a> <a href="http://stackexchange.com/legal">legal</a> <a href="http://stackexchange.com/legal/privacy-policy">priv acy policy</a> <a href="http://stackexchange.com/about/hiring">jobs</a> <a href="http://engine.adzerk.net/redirect/0/2776/2751/0/4de 3c60f719c4dfcb1a57531c7050090/0">advertising info</a> <a onclick="StackExchange.switchMobile(&quot;on&quot;, &quot ;/questions/8623924/dictionary-runtime-codility-test/8623980&quot;)">mobile</a> <b><a href="http://stackoverflow.com/contact">contact us</a> </b>

<b><a href="http://meta.stackoverflow.com/">feedback</a> </b> </div> <div id="footer-sites"> <table> <tbody><tr> <th colspan="3"> Technology </th> <th> Life / Arts </th> <th> Culture / Recreation </th> <th> Science </th> <th> Other </th> </tr> <tr> <td> <ol> <li><a href="http://stackoverflow.com/" title="professio nal and enthusiast programmers">Stack Overflow</a></li> <li><a href="http://serverfault.com/" title="professiona l system and network administrators">Server Fault</a></li> <li><a href="http://superuser.com/" title="computer enth usiasts and power users">Super User</a></li> <li><a href="http://webapps.stackexchange.com/" title="p ower users of web applications">Web Applications</a></li> <li><a href="http://askubuntu.com/" title="Ubuntu users and developers">Ask Ubuntu</a></li> <li><a href="http://webmasters.stackexchange.com/" title ="pro webmasters">Webmasters</a></li> <li><a href="http://gamedev.stackexchange.com/" title="p rofessional and independent game developers">Game Development</a></li> <li><a href="http://tex.stackexchange.com/" title="users of TeX, LaTeX, ConTeXt, and related typesetting systems">TeX - LaTeX</a></li> </ol></td><td><ol> <li><a href="http://programmers.stackexchange.com/" titl e="professional programmers interested in conceptual questions about software de velopment">Programmers</a></li> <li><a href="http://unix.stackexchange.com/" title="user s of Linux, FreeBSD and other Un*x-like operating systems.">Unix &amp; Linux</a> </li> <li><a href="http://apple.stackexchange.com/" title="pow er users of Apple hardware and software">Ask Different (Apple)</a></li> <li><a href="http://wordpress.stackexchange.com/" title= "WordPress developers and administrators">WordPress Answers</a></li> <li><a href="http://gis.stackexchange.com/" title="carto graphers, geographers and GIS professionals">Geographic Information Systems</a>< /li> <li><a href="http://electronics.stackexchange.com/" titl e="electronics and electrical engineering professionals, students, and enthusias ts">Electrical Engineering</a></li> <li><a href="http://android.stackexchange.com/" title="e nthusiasts and power users of the Android operating system">Android Enthusiasts<

/a></li> <li><a href="http://security.stackexchange.com/" title=" IT security professionals">IT Security</a></li> </ol></td><td><ol> <li><a href="http://dba.stackexchange.com/" title="datab ase professionals who wish to improve their database skills and learn from other s in the community">Database Administrators</a></li> <li><a href="http://drupal.stackexchange.com/" title="Dr upal developers and administrators">Drupal Answers</a></li> <li><a href="http://sharepoint.stackexchange.com/" title ="SharePoint enthusiasts">SharePoint</a></li> <li><a href="http://ux.stackexchange.com/" title="user e xperience researchers and experts">User Experience</a></li> <li><a href="http://mathematica.stackexchange.com/" titl e="users of Mathematica">Mathematica</a></li> <li> <a href="http://stackexchange.com/sites#technology" class="more"> more (13) </a> </li> </ol> </td> <td> <ol> <li><a href="http://photo.stackexchange.com/" title="pro fessional, enthusiast and amateur photographers">Photography</a></li> <li><a href="http://scifi.stackexchange.com/" title="sci ence fiction and fantasy enthusiasts">Science Fiction &amp; Fantasy</a></li> <li><a href="http://cooking.stackexchange.com/" title="p rofessional and amateur chefs">Seasoned Advice (cooking)</a></li> <li><a href="http://diy.stackexchange.com/" title="contr actors and serious DIYers">Home Improvement</a></li> <li> <a href="http://stackexchange.com/sites#lifearts" cl ass="more"> more (13) </a> </li> </ol> </td> <td> <ol> <li><a href="http://english.stackexchange.com/" title="l inguists, etymologists, and serious English language enthusiasts">English Langua ge &amp; Usage</a></li> <li><a href="http://skeptics.stackexchange.com/" title=" scientific skepticism">Skeptics</a></li> <li><a href="http://judaism.stackexchange.com/" title="t hose who base their lives on Jewish law and tradition and anyone interested in l earning more">Mi Yodeya (Judaism)</a></li> <li><a href="http://travel.stackexchange.com/" title="ro ad warriors and seasoned travelers">Travel</a></li> <li><a href="http://christianity.stackexchange.com/" tit le="committed Christians, experts in Christianity and those interested in learni ng more">Christianity</a></li> <li><a href="http://gaming.stackexchange.com/" title="pa ssionate videogamers on all platforms">Arqade (gaming)</a></li>

<li><a href="http://bicycles.stackexchange.com/" title=" people who build and repair bicycles, people who train cycling, or commute on bi cycles">Bicycles</a></li> <li><a href="http://rpg.stackexchange.com/" title="gamem asters and players of tabletop, paper-and-pencil role-playing games">Role-playin g Games</a></li> <li> <a href="http://stackexchange.com/sites#culturerecre ation" class="more"> more (21) </a> </li> </ol> </td> <td> <ol> <li><a href="http://math.stackexchange.com/" title="peop le studying math at any level and professionals in related fields">Mathematics</ a></li> <li><a href="http://stats.stackexchange.com/" title="sta tisticians, data analysts, data miners and data visualization experts">Cross Val idated (stats)</a></li> <li><a href="http://cstheory.stackexchange.com/" title=" theoretical computer scientists and researchers in related fields">Theoretical C omputer Science</a></li> <li><a href="http://physics.stackexchange.com/" title="a ctive researchers, academics and students of physics">Physics</a></li> <li><a href="http://mathoverflow.net/" title="mathematic ians">MathOverflow</a></li> <li> <a href="http://stackexchange.com/sites#science" cla ss="more"> more (7) </a> </li> </ol> </td> <td> <ol> <li><a href="http://stackapps.com/" title="apps, scripts , and development with the Stack Exchange API">Stack Apps</a></li> <li><a href="http://meta.stackoverflow.com/" title="meta -discussion of the Stack Exchange family of Q&amp;A websites">Meta Stack Overflo w</a></li> <li><a href="http://area51.stackexchange.com/" title="pr oposing new sites in the Stack Exchange network">Area 51</a></li> <li><a href="http://careers.stackoverflow.com/">Stack Ov erflow Careers</a></li> </ol> </td> </tr> </tbody></table> </div> </div> <div id="copyright"> site design / logo 2013 stack exchange inc;

user contributions licensed under <a href="http://creativecommon s.org/licenses/by-sa/3.0/" rel="license">cc-wiki</a> with <a href="http://blog.stackoverflow.com/2009/06/attributionrequired/" rel="license">attribution required</a> </div> <div id="footer-flair"> <a href="http://creativecommons.org/licenses/by-sa/3.0/" class=" cc-wiki-link"></a> </div> <div id="svnrev"> rev 2013.7.1.798 </div> </div> </div> <noscript> &lt;div id="noscript-warning"&gt;Stack Overflow works best with JavaScri pt enabled&lt;img src="http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" al t="" class="dno"&gt;&lt;/div&gt; </noscript> <script type="text/javascript">var _gaq=_gaq||[];_gaq.push(['_setAccount','U A-5620270-1']); _gaq.push(['_setCustomVar', 1, 'tags', '|python|codility|']); _gaq.push(['_trackPageview']); var _qevents = _qevents || []; (function(){ var s=document.getElementsByTagName('script')[0]; var ga=document.createElement('script'); ga.type='text/javascript'; ga.async=true; ga.src='http://www.google-analytics.com/ga.js'; s.parentNode.insertBefore(ga,s); var sc=document.createElement('script'); sc.type='text/javascript'; sc.async=true; sc.src='http://edge.quantserve.com/quant.js'; s.parentNode.insertBefore(sc,s); })(); </script> <script type="text/javascript"> _qevents.push({ qacct: "p-c1rF4kxgLUzNc" }); </script> </body></html>

You might also like