<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-7833753242240216799</atom:id><lastBuildDate>Sun, 21 Jun 2026 06:46:49 +0000</lastBuildDate><category>Algorithm</category><category>Implementation</category><category>Warm Up</category><title>Gotitt</title><description></description><link>http://gotitt.blogspot.com/</link><managingEditor>noreply@blogger.com (Dinesh)</managingEditor><generator>Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7833753242240216799.post-5386510519222806460</guid><pubDate>Sun, 18 Sep 2016 18:19:00 +0000</pubDate><atom:updated>2016-09-29T13:09:18.343-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Algorithm</category><category domain="http://www.blogger.com/atom/ns#">Implementation</category><title>Strange Counter</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b style=&quot;background-color: white; color: #39424e; font-family: Times, &amp;quot;Times New Roman&amp;quot;, serif; font-size: 16px; line-height: 1.5em;&quot;&gt;Bob has a&amp;nbsp;&lt;em style=&quot;border: 0px; font-stretch: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;strange counter&lt;/em&gt;. At the first second,&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 2196.1 936.9&quot; width=&quot;5.101ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(639,0)&quot;&gt;&lt;path d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1695,0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, it displays the number&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 500.5 936.9&quot; width=&quot;1.162ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;. At each subsequent second, the number displayed by the counter decrements by&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 500.5 936.9&quot; width=&quot;1.162ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;The counter counts down in cycles. In the second after the counter counts down to&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 500.5 936.9&quot; width=&quot;1.162ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, the number becomes&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-5-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 1279 936.9&quot; width=&quot;2.971ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(500,0)&quot;&gt;&lt;path d=&quot;M630 29Q630 9 609 9Q604 9 587 25T493 118L389 222L284 117Q178 13 175 11Q171 9 168 9Q160 9 154 15T147 29Q147 36 161 51T255 146L359 250L255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489Q178 487 284 383L389 278L493 382Q570 459 587 475T609 491Q630 491 630 471Q630 464 620 453T522 355L418 250L522 145Q606 61 618 48T630 29Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;the initial number for that countdown cycle and then continues counting down from the new initial number in a new cycle. The diagram below shows the counter values for each time&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-6-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -719.6 361.5 865.1&quot; width=&quot;0.84ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;in the first three cycles:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKelT3l34o_2G5DYcj0LCoJH9W7Gci-RRjLQCROxnjfahFvsiXxvVD-WR5Dsok5nNXrqMt3kF1HqFWBj9En8eUFdX4wCngYyj4lzXb3BMdewFALOqjeOni9TIDIG6xIDfutL-yes3n9gw/s1600/strange+counter.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKelT3l34o_2G5DYcj0LCoJH9W7Gci-RRjLQCROxnjfahFvsiXxvVD-WR5Dsok5nNXrqMt3kF1HqFWBj9En8eUFdX4wCngYyj4lzXb3BMdewFALOqjeOni9TIDIG6xIDfutL-yes3n9gw/s320/strange+counter.png&quot; width=&quot;279&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;challenge_problem_statement&quot; style=&quot;background-color: white; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 22.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;msB challenge_problem_statement_body&quot; style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;hackdown-content&quot; style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;Given a time,&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-7-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -719.6 361.5 865.1&quot; width=&quot;0.84ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, find and print the value displayed by the counter at time&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-8-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -719.6 361.5 865.1&quot; width=&quot;0.84ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 1.5em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Hints:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;The last &amp;nbsp;&#39;time&#39; value of cycle 1 is 3 which is 3*1=3*(2^1-1).&lt;/li&gt;
&lt;li&gt;The last &#39;time&#39; value of cycle 2 is 9 which is 3*3=3*(2^2-1).&amp;nbsp;&lt;/li&gt;
&lt;li&gt;The last &#39;time&#39; value of cycle 3 is 21 which is 3*7=3*(2^3-1).&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 1.5em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;So, we will use a while loop and keep doubling n, which will represents &amp;nbsp;2^1, 2^2, 2^3 part. The loop stops when it reaches to a cycle whose max time is bigger than the real time t, then we know that it has reached the last cycle.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 1.5em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;For example :&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In the second cycle, &amp;nbsp;time =7 has value=3, and the max time of the second cycle is 9. We find the relationship between them is 3 = 9 - 7 + 1, which is why we print (3 * (n - 1) - t + 1) to get the output of 3 when t is 7.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Here is my code:&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;int main(){&lt;/b&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;long long t,n=2;&lt;/b&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; cin &amp;gt;&amp;gt; t;&lt;/b&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; while(3*(n-1)&amp;lt;t)n*=2;&lt;/b&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;3*(n-1)-t+1&amp;lt;&amp;lt;endl;&lt;/b&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;}&lt;/b&gt;&lt;/h3&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;div&gt;
&amp;nbsp;Question source:-&amp;nbsp;&lt;a href=&quot;https://www.hackerrank.com/challenges/strange-code&quot; target=&quot;_blank&quot;&gt;hackerrank.com&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;//feedburner.google.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;vertical-align:middle;border:0&quot;/&gt;&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><link>http://gotitt.blogspot.com/2016/09/strange-counter.html</link><author>noreply@blogger.com (Dinesh)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKelT3l34o_2G5DYcj0LCoJH9W7Gci-RRjLQCROxnjfahFvsiXxvVD-WR5Dsok5nNXrqMt3kF1HqFWBj9En8eUFdX4wCngYyj4lzXb3BMdewFALOqjeOni9TIDIG6xIDfutL-yes3n9gw/s72-c/strange+counter.png" height="72" width="72"/><thr:total>9</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7833753242240216799.post-4336841112328963575</guid><pubDate>Sun, 18 Sep 2016 15:55:00 +0000</pubDate><atom:updated>2019-06-07T05:50:23.934-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Algorithm</category><category domain="http://www.blogger.com/atom/ns#">Implementation</category><title>Almost Sorted</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #39424e; font-family: inherit; font-size: 16px;&quot;&gt;&lt;b&gt;Given an array with&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;1.676ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -576.1 600.5 721.6&quot; width=&quot;1.395ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;elements, can you sort this array in&amp;nbsp;&lt;span style=&quot;border: 0px; font-stretch: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;ascending order&lt;/span&gt;&amp;nbsp;using only one of the following operations?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol style=&quot;background-color: white; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; line-height: inherit; margin: 10px 0px 20px 20px; outline: 0px; padding: 0px; text-align: left; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;li&gt;&lt;b style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;Swap two elements.&lt;/b&gt;&lt;/li&gt;
&lt;li style=&quot;border: 0px; font-stretch: inherit; font-variant: inherit; line-height: inherit; margin: 0px 0px 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;Reverse one sub-segment.&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;border: 0px; font-stretch: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;&lt;b&gt;Input Format&lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;br style=&quot;word-break: break-word; word-wrap: break-word;&quot; /&gt;The first line contains a single integer,&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;1.676ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -576.1 600.5 721.6&quot; width=&quot;1.395ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, which indicates the size of the array.&amp;nbsp;&lt;br style=&quot;word-break: break-word; word-wrap: break-word;&quot; /&gt;The next line contains&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;1.676ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -576.1 600.5 721.6&quot; width=&quot;1.395ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;integers separated by spaces.&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background: rgb(244, 250, 255); border-radius: 2px; border: 0px; color: #454c59; font-size: 14px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 18px; margin-bottom: 9px; margin-top: 12px; outline: 0px; padding: 20px; vertical-align: baseline; white-space: pre-wrap; word-break: break-word; word-wrap: break-word;&quot;&gt;&lt;code style=&quot;background: transparent; border-radius: 3px; border: 0px; color: #26a655; font-size: 1em; font-stretch: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;n  
d1 d2 ... dn  &lt;b&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b style=&quot;font-family: Roboto, sans-serif;&quot;&gt;&lt;br style=&quot;word-break: break-word; word-wrap: break-word;&quot; /&gt;&lt;/b&gt;&lt;strong style=&quot;border: 0px; font-family: &amp;quot;Whitney SSm A&amp;quot;, &amp;quot;Whitney SSm B&amp;quot;, Avenir, &amp;quot;Segoe UI&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, Ubuntu, sans-serif; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;Constraints&lt;/strong&gt;&lt;span style=&quot;font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif; font-stretch: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.343ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.505ex;&quot; viewbox=&quot;0 -791.3 6772.1 1008.6&quot; width=&quot;15.729ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;path d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1834,0)&quot;&gt;&lt;path d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2712,0)&quot;&gt;&lt;path d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3769,0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(1001,0)&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(1501,0)&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(2002,0)&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(2502,0)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;font-family: &amp;quot;Whitney SSm A&amp;quot;, &amp;quot;Whitney SSm B&amp;quot;, Avenir, &amp;quot;Segoe UI&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, Ubuntu, sans-serif; word-break: break-word; word-wrap: break-word;&quot; /&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-5-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif; font-stretch: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.343ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.505ex;&quot; viewbox=&quot;0 -791.3 2358.1 1008.6&quot; width=&quot;5.477ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;path d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1834,0)&quot;&gt;&lt;path d=&quot;M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;border: 0px; bottom: -0.25em; font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif; font-size: 12px; font-stretch: inherit; line-height: 0; margin: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-6-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 345.5 936.9&quot; width=&quot;0.802ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-7-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif; font-stretch: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.343ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.505ex;&quot; viewbox=&quot;0 -791.3 4559.8 1008.6&quot; width=&quot;10.59ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(1056,0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(1001,0)&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(1501,0)&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(2002,0)&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(2502,0)&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(3003,0)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;font-family: &amp;quot;Whitney SSm A&amp;quot;, &amp;quot;Whitney SSm B&amp;quot;, Avenir, &amp;quot;Segoe UI&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, Ubuntu, sans-serif; word-break: break-word; word-wrap: break-word;&quot; /&gt;&lt;span style=&quot;font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif;&quot;&gt;All&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-8-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif; font-stretch: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 523.5 936.9&quot; width=&quot;1.216ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;border: 0px; bottom: -0.25em; font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif; font-size: 12px; font-stretch: inherit; line-height: 0; margin: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-9-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 345.5 936.9&quot; width=&quot;0.802ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;whitney ssm a&amp;quot; , &amp;quot;whitney ssm b&amp;quot; , &amp;quot;avenir&amp;quot; , &amp;quot;segoe ui&amp;quot; , &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;ubuntu&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;are distinct.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;border: 0px; font-stretch: inherit; font-variant: inherit; font-weight: bold; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;border: 0px; font-stretch: inherit; font-variant: inherit; font-weight: bold; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;Output Format&lt;/span&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;ol style=&quot;border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; line-height: inherit; margin: 10px 0px 20px 20px; outline: 0px; padding: 0px; text-align: left; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;If the array is already sorted, output&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #d9ead3; border: 0px; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;yes&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&amp;nbsp;on the first line. You do not need to output anything else.&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-color: white;&quot;&gt;If you can sort this array using one single operation (from the two permitted operations) then output&amp;nbsp;&lt;span style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;yes&lt;/span&gt;&lt;span style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&amp;nbsp;on the first line and then:&lt;/span&gt;
&lt;ol&gt;

&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;If you can sort the array by swapping&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-10-Frame&quot; style=&quot;border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-family: inherit; font-size: 16px; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 523.5 936.9&quot; width=&quot;1.216ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;border: 0px; bottom: -0.25em; color: #39424e; font-family: inherit; font-size: 12px; font-stretch: inherit; font-variant: inherit; line-height: 0; margin: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-11-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 298.5 936.9&quot; width=&quot;0.693ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: inherit; font-size: 16px;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-12-Frame&quot; style=&quot;border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-family: inherit; font-size: 16px; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 523.5 936.9&quot; width=&quot;1.216ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;border: 0px; bottom: -0.25em; color: #39424e; font-family: inherit; font-size: 12px; font-stretch: inherit; font-variant: inherit; line-height: 0; margin: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-13-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;1.676ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -576.1 451.5 721.6&quot; width=&quot;1.049ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M21 287Q22 290 23 295T28 317T38 348T53 381T73 411T99 433T132 442Q161 442 183 430T214 408T225 388Q227 382 228 382T236 389Q284 441 347 441H350Q398 441 422 400Q430 381 430 363Q430 333 417 315T391 292T366 288Q346 288 334 299T322 328Q322 376 378 392Q356 405 342 405Q286 405 239 331Q229 315 224 298T190 165Q156 25 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 114 189T154 366Q154 405 128 405Q107 405 92 377T68 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: inherit; font-size: 16px;&quot;&gt;, output&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;border: 0px; color: #39424e; font-family: inherit; font-size: 16px; font-stretch: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;swap l r&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: inherit; font-size: 16px;&quot;&gt;&amp;nbsp;in the second line.&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-14-Frame&quot; style=&quot;border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-family: inherit; font-size: 16px; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 298.5 936.9&quot; width=&quot;0.693ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: inherit; font-size: 16px;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-15-Frame&quot; style=&quot;border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-family: inherit; font-size: 16px; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;1.676ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -576.1 451.5 721.6&quot; width=&quot;1.049ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M21 287Q22 290 23 295T28 317T38 348T53 381T73 411T99 433T132 442Q161 442 183 430T214 408T225 388Q227 382 228 382T236 389Q284 441 347 441H350Q398 441 422 400Q430 381 430 363Q430 333 417 315T391 292T366 288Q346 288 334 299T322 328Q322 376 378 392Q356 405 342 405Q286 405 239 331Q229 315 224 298T190 165Q156 25 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 114 189T154 366Q154 405 128 405Q107 405 92 377T68 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: inherit; font-size: 16px;&quot;&gt;&amp;nbsp;are the indices of the elements to be swapped, assuming that the array is indexed from&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-16-Frame&quot; style=&quot;border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-family: inherit; font-size: 16px; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 500.5 936.9&quot; width=&quot;1.162ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: inherit; font-size: 16px;&quot;&gt;&amp;nbsp;to&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-17-Frame&quot; style=&quot;border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-family: inherit; font-size: 16px; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;1.676ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -576.1 600.5 721.6&quot; width=&quot;1.395ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: inherit; font-size: 16px;&quot;&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;span style=&quot;border: 0px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-family: inherit;&quot;&gt;&lt;span style=&quot;font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Else if it is possible to sort the array by reversing the segment&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px;&quot;&gt;d [&lt;i&gt;l....r&lt;/i&gt;]&amp;nbsp;,&amp;nbsp;output&amp;nbsp;&lt;/span&gt;&lt;em style=&quot;background-color: #d9ead3; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;reverse l r&lt;/em&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px;&quot;&gt;&amp;nbsp;in the second line. &lt;i&gt;l&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px;&quot;&gt;and&lt;i&gt; r&lt;/i&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #39424e;&quot;&gt;are the indices of the first and last elements of the&amp;nbsp;sub-sequence&amp;nbsp;to be reversed, assuming that the array is indexed from 1&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px;&quot;&gt;to n.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-color: white; color: #39424e; font-size: 16px; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;represents the sub-sequence of the array, beginning at index&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-24-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 298.5 936.9&quot; width=&quot;0.693ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&amp;nbsp;and ending at index&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-25-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;1.676ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -576.1 451.5 721.6&quot; width=&quot;1.049ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M21 287Q22 290 23 295T28 317T38 348T53 381T73 411T99 433T132 442Q161 442 183 430T214 408T225 388Q227 382 228 382T236 389Q284 441 347 441H350Q398 441 422 400Q430 381 430 363Q430 333 417 315T391 292T366 288Q346 288 334 299T322 328Q322 376 378 392Q356 405 342 405Q286 405 239 331Q229 315 224 298T190 165Q156 25 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 114 189T154 366Q154 405 128 405Q107 405 92 377T68 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;, both inclusive. &amp;nbsp;d [&lt;i&gt;l....r&lt;/i&gt;]&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;epresents the sub-sequence of the array, beginning at index&lt;/span&gt;&lt;span style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&amp;nbsp;&lt;i&gt;&lt;b&gt;l&lt;/b&gt;&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;and ending at index&lt;/span&gt;&lt;span style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&amp;nbsp;&lt;i&gt;&lt;b&gt;r&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&amp;nbsp;, both inclusive.&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-color: white; color: #39424e; font-size: 16px; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&lt;div style=&quot;border: 0px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;If an array can be sorted by either swapping or reversing, stick to the swap-based method.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/span&gt;&lt;/ul&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;If you cannot sort the array in either of the above ways, output no in the first line&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;border: 0px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-family: inherit; font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Here are my tips.&lt;/h4&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Create a &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;dynamic Array&amp;nbsp;&lt;b&gt;A&lt;/b&gt;&amp;nbsp;&lt;/span&gt;of size&amp;nbsp;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;n+2&lt;/b&gt;,&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;i&lt;/span&gt;nput the values in the array with &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;A[0]=0 and A[ n+2] =max_value of n&lt;/b&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Starting from index 1, loop through it till you get the first anomaly (i.e when&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: #d9ead3;&quot;&gt;A[ i ]&amp;gt;A[ i+1]&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp;)&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;take note of the index and&lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;break the loop.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Now starting from index n till index j, loop though it and check for all the anomaly, take the index of the first anomaly. Now take note of all the anomaly whether it&#39;s a peak or valley as well as number of anomaly (peak in case when&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: #d9ead3;&quot;&gt;A[ i ]&amp;gt;A[ i+1] &amp;amp;&amp;amp; A[ i ] &amp;gt;A[ i-1]&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt; &lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;and valley is case when&lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/b&gt;&lt;b style=&quot;background-color: #d9ead3;&quot;&gt;A[ i ]&amp;lt;A[ i+1] &amp;amp;&amp;amp; A[ i ] &amp;lt;A[ i-1]&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp;). &lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;See my code below for more clarification. Keep track of the index of the peak/valley &amp;nbsp;with the help of a vector.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Now if the output is yes than the following will be true.&lt;/span&gt;
&lt;ul&gt;
&lt;ol&gt;
&lt;li&gt;if no anomaly than the array is already sorted.&lt;/li&gt;
&lt;li&gt;swap when the there are exactly &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;1 peak and 1 valley&lt;/span&gt; &amp;nbsp;OR &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;2 peaks and 2 valleys&lt;/span&gt; and difference between the consecutive index of a peak and a valley is 1.&lt;/li&gt;
&lt;li&gt;reverse when only 1 peak and 1 valley and the difference between the their index is not 1.&lt;/li&gt;
&lt;/ol&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&amp;nbsp;if all of 4 is not there than we cannot sort the array in one operation so output &quot;no&quot;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
Here are few sample input to boost your thinking.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Input:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;6&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;1 5 4 3 2 6&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Output : reverse 2 5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Input&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;9&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;1 2 9 4 5 6 7 8 3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Output: swap 3 9&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Input&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;9&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;1 2 9 4 5 8 7 6 3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Output: no&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Input:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;10&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;1 2 10 4 5 8 7 6 9 3&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Output: no&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Input&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;1 2 4 3 5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Output: swap 2 5&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;My solution:&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;#include &amp;lt;vector&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;using namespace std;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;int main() {&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; int n,j=0,k=0,count=0,dn=0,up=0; &lt;/b&gt;&lt;i&gt;/*initializing &lt;b&gt;j &lt;/b&gt;and &lt;b&gt;k&lt;/b&gt; to take note of the first anomaly from&amp;nbsp;beginning&amp;nbsp;and end, &lt;b&gt;count&lt;/b&gt; to keep track of the number of anomaly, &lt;b&gt;dn&lt;/b&gt; for valley and &lt;b&gt;up&lt;/b&gt; for peak */&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;n;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; vector&amp;lt;int&amp;gt; s;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; int* A=new int[n+2]; &lt;/b&gt;&lt;i&gt;/* initializing a dynamic array A of size n+2 */&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; A[0]=0; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;i&gt;/*&amp;nbsp;assigning&amp;nbsp;A[0] =0 */&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; for(int i=1 ; i&amp;lt;=n; i++){&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;A[ i ]; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/b&gt;&lt;i&gt;/* Filling the array */&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; A[n+1]=1000001; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/b&gt;&lt;i&gt;/*&amp;nbsp;assigning&amp;nbsp;A[n+1]= Max_value of n i.e 100001 */&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; for(int i=1 ; i&amp;lt;=n-1 ; i++){ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(A[ i ]&amp;gt;A[ i+1] ){&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(count==0){j=i ;count++ ;break ; &amp;nbsp; &lt;/b&gt;&lt;i&gt;&amp;nbsp;/* searching for first anomaly from index 1 */&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}}&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; for(int i=n ; i&amp;gt;j-1 ;i--){&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(A[i]&amp;lt;A[i-1]){ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(count==1){ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;i&gt;/* searching for first anomaly from index n */&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; k=i ; dn++ ; s.push_back(i); &lt;/b&gt;&lt;i&gt;/* taking note of the first anomaly from the end &amp;nbsp;i.e. k=i . this will be a valley so increasing the value of dn by 1 and also noting it&#39;s index in the vector*/&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(A[ i ]&amp;lt;A[ i+1] &amp;amp;&amp;amp; count&amp;gt;1){&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dn++ ; s.push_back(i); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;i&gt;/* counting the number of valley&#39;s and noting their index in the vector */&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; count++; &amp;nbsp; &lt;/b&gt;&lt;i&gt;/* counting the number of anomaly */&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(A[ i ]&amp;gt;A[ i+1 ] &amp;amp;&amp;amp; A[ i ]&amp;gt;A[ i-1]){&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; up++; s.push_back(i); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;i&gt;/* counting the number of peaks and noting their index &amp;nbsp;in the vector*/&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if(count==0){cout&amp;lt;&amp;lt;&quot;yes&quot;;} &amp;nbsp; &amp;nbsp; &lt;/b&gt;&lt;i&gt;/* if &amp;nbsp;no anomaly */&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;else if(n==2){&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(A[1]&amp;gt;A[2])cout&amp;lt;&amp;lt;&quot;yes&quot;&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;&quot;swap &quot;&amp;lt;&amp;lt;1&amp;lt;&amp;lt;&quot; &quot;&amp;lt;&amp;lt;2; &amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/b&gt;&lt;i&gt;/* if n=2 than we can directly compare the values and output accordingly */&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; else if(A[ j ]&amp;lt;A[ k+1] &amp;amp;&amp;amp; A[ k]&amp;gt;A[ j-1] &amp;amp;&amp;amp; ((s.size()==4 &amp;amp;&amp;amp;s[0]-s[1]==1 &amp;amp;&amp;amp; s[2]-s[3]==1)|| (s.size()==2 &amp;amp;&amp;amp; s[0]-s[1]==1)) ) {&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;yes&quot;&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;&quot;swap &quot;&amp;lt;&amp;lt;j&amp;lt;&amp;lt;&quot; &quot;&amp;lt;&amp;lt;k;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &lt;/b&gt;&lt;i&gt;/* this is a very big condition so take a look properly, remember that j is the first anomaly from&amp;nbsp;beginning&amp;nbsp;and k is the first anomaly from the end. After swap, the array will be sorted only when&amp;nbsp;&lt;/i&gt;&lt;i&gt;A[ j ]&amp;lt;A[ k+1] &amp;amp;&amp;amp; A[ k]&amp;gt;A[ j-1]&lt;/i&gt;&lt;i&gt;&amp;nbsp; and &amp;nbsp;i have already explained&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;i&gt;the other conditions&amp;nbsp;&lt;/i&gt;&lt;i&gt;in the points above */&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp;else if(A[ j ]&amp;lt;A[k+1] &amp;amp;&amp;amp; A[k]&amp;gt;A[ j-1] &amp;nbsp;&amp;amp;&amp;amp; &amp;nbsp;count==(k-j+1))&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;yes&quot;&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;&quot;reverse &quot;&amp;lt;&amp;lt;j&amp;lt;&amp;lt;&quot; &quot;&amp;lt;&amp;lt;k;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;i style=&quot;background-color: white;&quot;&gt;/* Reverse operation will be applicable only when number of anomaly i.e. &lt;/i&gt;&lt;i style=&quot;background-color: #d9ead3;&quot;&gt;count&lt;/i&gt;&lt;i style=&quot;background-color: white;&quot;&gt; is equal to the difference in their index +1 i.e. ( count =k-j+1 ), see the sample input&#39;s for more clarification */&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else cout&amp;lt;&amp;lt;&quot;no&quot;; &lt;/b&gt;&lt;i&gt;/* if all the above are not true than we cannot sort the array in one&amp;nbsp;operation&amp;nbsp;*/&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;}&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;*****&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;If you have a better solution in mind than please do share it in the comment section below &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Want me to explain any&amp;nbsp;particular&amp;nbsp;question, than comment below&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;*****&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Question source : &lt;a href=&quot;https://www.hackerrank.com/challenges/almost-sorted/copy-from/28196406&quot; target=&quot;_blank&quot;&gt;hackerrank.com&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;//feedburner.google.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;vertical-align:middle;border:0&quot;/&gt;&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><link>http://gotitt.blogspot.com/2016/09/almost-sorted.html</link><author>noreply@blogger.com (Dinesh)</author><thr:total>7</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7833753242240216799.post-2297328806163658229</guid><pubDate>Mon, 12 Sep 2016 19:06:00 +0000</pubDate><atom:updated>2016-10-04T07:43:46.970-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Algorithm</category><category domain="http://www.blogger.com/atom/ns#">Implementation</category><title>Bigger is Greater</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
In this problem i will explain the following problem taken from &lt;a href=&quot;https://www.hackerrank.com/challenges/bigger-is-greater&quot; target=&quot;_blank&quot;&gt;hackerrank.com&lt;/a&gt;&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC-rcOR4X5cmTNPXZDbEqe0cUiAGPRHS22eQLEo7I9T-cd2l8x8z5OTjJRNfmllJnHANCAndURHliNjqL2L9oJUn0GMGU7bYPvwC9CXBtLVpX-R-hVh7I1nT4nhhoYyUqUusUxnCSfadU/s1600/Bigger+is+greater.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;332&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC-rcOR4X5cmTNPXZDbEqe0cUiAGPRHS22eQLEo7I9T-cd2l8x8z5OTjJRNfmllJnHANCAndURHliNjqL2L9oJUn0GMGU7bYPvwC9CXBtLVpX-R-hVh7I1nT4nhhoYyUqUusUxnCSfadU/s640/Bigger+is+greater.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Lexicographically greater means that suppose if we were to arrange these words on a dictionary than s should come just after w.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #363636; font-size: 16.752px; font-weight: inherit; line-height: 1.35;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #363636; font-size: 16.752px; font-weight: inherit; line-height: 1.35;&quot;&gt;We will use the word &quot;mekhfa&quot;&lt;/span&gt;&lt;span style=&quot;color: #363636; font-size: 16.752px; font-weight: inherit; line-height: 22.6152px;&quot;&gt;&amp;nbsp;in our example.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; color: #363636; font-size: 16.752px; line-height: 1.35; margin: 0.7em 0em; padding: 0px;&quot;&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 16.0pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 16.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 19.2pt;&quot; valign=&quot;top&quot; width=&quot;26&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;m&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 16.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 19.2pt;&quot; valign=&quot;top&quot; width=&quot;26&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;e&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 16.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 19.2pt;&quot; valign=&quot;top&quot; width=&quot;26&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;k&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 16.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 19.2pt;&quot; valign=&quot;top&quot; width=&quot;26&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;h&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 16.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 19.2pt;&quot; valign=&quot;top&quot; width=&quot;26&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;f&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 16.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 19.2pt;&quot; valign=&quot;top&quot; width=&quot;26&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;a&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #363636; font-family: inherit;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 16.752px; line-height: 1.35;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #363636; font-size: 16.752px; line-height: 1.35;&quot;&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 1.35;&quot;&gt;The key observation in this algorithm is that when we want to compute the next word &amp;nbsp;in a dictionary &quot;s&quot; such that it contains all the&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;letters&lt;/span&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 1.35;&quot;&gt;&amp;nbsp;as &quot;w&quot; OR&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;equivalently&lt;/span&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 1.35;&quot;&gt;&amp;nbsp;when we want to&amp;nbsp;compute the next permutation of the word &quot;w&quot;, we must “increase” the sequence&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;em style=&quot;font-size: 16.752px; line-height: 1.35;&quot;&gt;as little as possible&lt;/em&gt;&lt;span style=&quot;color: #363636; font-size: 16.752px; line-height: 1.35;&quot;&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 1.35;&quot;&gt;. Just like when we count up using numbers, we try to modify the rightmost elements and leave the left side alone (ex. if we want to fin the next permutation of the number 234 we would start from the right most element rather than the first element).&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; color: #363636; font-size: 16.752px; line-height: 1.35; margin: 0.7em 0em; padding: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Similarly here also we will start from the end and find the largest sub-string that is non-increasing, non increasing means &lt;i&gt;string[i-1]&lt;/i&gt; &amp;gt;&lt;i&gt; string[ i ], &amp;nbsp;&lt;/i&gt;in our case it&#39;s &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 13.9pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;k&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;h&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;f&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;a&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div style=&quot;border: none; margin: 0.7em 0em; padding: 0px;&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #363636; font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;This&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #363636;&quot;&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;sub-string&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #363636; font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;&amp;nbsp;is already in the highest permutation, so we can’t make a next permutation just by&amp;nbsp;modifying it – we need to modify some element(s) to the left of it.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #363636; font-size: 16.752px; line-height: 1.35;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Now, look at the element immediately to the left of the index of &quot;k&quot; (in the example it’s &quot;e&quot;) and call it the pivot. (If there is no such element – i.e. the entire sequence is non-decreasing – then this is already the last permutation.) The pivot is necessarily less than the head of the sub-string (in the example it’s &quot;k&quot;). So some element in the sub-string is greater than the pivot. If we swap the pivot with the smallest element in the sub-string that is greater than the pivot (&quot;f&quot; in our case), then the beginning (i.e. m, f ) of the string is minimized. (The string is everything in the sequence except for the new sub-string. i.e.&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 13.9pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;k&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;h&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;e&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;a&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;color: #363636; font-size: 16.752px; line-height: 1.35;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;(Note that if the sub-string has multiple copies of the new pivot, we should take the rightmost copy – this plays into the next step.)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border: none; line-height: 1.35; margin: 0.7em 0em; padding: 0px;&quot;&gt;
&lt;div style=&quot;color: #363636; font-size: 16.752px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Finally, we sort the sub-string in non-decreasing (i.e. weakly increasing) order because we increased the prefix, so we want to make the new suffix as low as possible. In fact, we can avoid sorting and simply reverse the suffix, because the replaced element respects the weakly decreasing order. So finally, we get the sequence&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; color: #363636; font-size: 16.752px;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 13.9pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;m&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.6pt;&quot; valign=&quot;top&quot; width=&quot;22&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;f&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.6pt;&quot; valign=&quot;top&quot; width=&quot;22&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;a&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.6pt;&quot; valign=&quot;top&quot; width=&quot;22&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;e&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.3pt;&quot; valign=&quot;top&quot; width=&quot;22&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;h&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 13.9pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 16.1pt;&quot; valign=&quot;top&quot; width=&quot;21&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;k&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;color: #363636; font-family: Arial, Helvetica, sans-serif; font-size: 16.752px;&quot;&gt;which is the next permutation that we wanted.&lt;/span&gt;&lt;div style=&quot;color: #363636; font-size: 16.752px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: black; font-size: medium; line-height: normal;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Here are the steps.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #363636; font-size: 16.752px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: normal;&quot;&gt;
&lt;ol style=&quot;border: none; color: #363636; font-size: 16.752px; margin: 0px; padding: 0px;&quot;&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; font-size: inherit; font-weight: inherit; line-height: inherit; margin: 0.4em 0em 0.4em 2em; padding: 0px;&quot;&gt;&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; font-size: inherit; font-weight: inherit; line-height: 1.35; margin: 0.7em 0em; padding: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Start from the end and find the index&amp;nbsp;&lt;var&gt;i&lt;/var&gt;&amp;nbsp;such that&amp;nbsp;&lt;var&gt;string&lt;/var&gt;[&amp;nbsp;&lt;var&gt;i&lt;/var&gt;&amp;nbsp;] &amp;lt;&amp;nbsp;&lt;var&gt;string&lt;/var&gt;[&amp;nbsp;&lt;var&gt;i&amp;nbsp;+1&lt;/var&gt;].&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; font-size: inherit; font-weight: inherit; line-height: inherit; margin: 0.4em 0em 0.4em 2em; padding: 0px;&quot;&gt;&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; font-size: inherit; font-weight: inherit; line-height: 1.35; margin: 0.7em 0em; padding: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The element at index &lt;i&gt;i &lt;/i&gt;(i.e. &lt;i&gt;string&lt;/i&gt;[&amp;nbsp;&lt;i&gt;i&amp;nbsp;&lt;/i&gt;] )&amp;nbsp;is called pivot. Now Search the elements with &lt;i&gt;index&lt;/i&gt; &amp;gt; &lt;i&gt;i&lt;/i&gt;&amp;nbsp; and find the element which is next greater than&amp;nbsp;&lt;i style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;string&lt;/i&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;[&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;i&amp;nbsp;&lt;/i&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;]&amp;nbsp;&lt;/span&gt;. Let say we find the element at index &amp;nbsp;&lt;i&gt;j &lt;/i&gt;to be next greater than&amp;nbsp;&lt;i style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;string&lt;/i&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;[&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;i&amp;nbsp;&lt;/i&gt;&lt;span style=&quot;font-size: 16.752px; line-height: 22.6152px;&quot;&gt;]&amp;nbsp;&lt;/span&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; font-size: inherit; font-weight: inherit; line-height: inherit; margin: 0.4em 0em 0.4em 2em; padding: 0px;&quot;&gt;&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; font-size: inherit; font-weight: inherit; line-height: 1.35; margin: 0.7em 0em; padding: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Swap&amp;nbsp;&lt;var&gt;string&amp;nbsp;&lt;/var&gt;[&amp;nbsp;&lt;var&gt;j&amp;nbsp;&lt;/var&gt;] and&amp;nbsp;&lt;var&gt;string&lt;/var&gt;[&amp;nbsp;&lt;var&gt;i&lt;/var&gt;&amp;nbsp;].&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; font-size: inherit; font-weight: inherit; line-height: inherit; margin: 0.4em 0em 0.4em 2em; padding: 0px;&quot;&gt;&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; font-size: inherit; font-weight: inherit; line-height: 1.35; margin: 0.7em 0em; padding: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Reverse Or sort the sub-string starting at&amp;nbsp;&lt;var&gt;string&lt;/var&gt;[&amp;nbsp;&lt;var&gt;i+1&lt;/var&gt;] .&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;color: #363636;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 16.752px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #363636;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 16.752px;&quot;&gt;Here is my code for reference.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;#include &amp;lt;algorithm&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;using namespace std;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;int main() {&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; int t;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;t;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; for (int i = 0; i &amp;lt; t; i++){&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string s;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cin &amp;gt;&amp;gt; s;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int n = s.length();&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int j, k;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (j = n - 2; j &amp;gt;= 0; j--)&lt;/b&gt;&lt;b&gt;&amp;nbsp;{ &amp;nbsp;&lt;/b&gt;&lt;i&gt;/* initializing j which is pointing to element at index n-2 */&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (k = n - 1; k &amp;gt; j &amp;amp;&amp;amp; s[k] &amp;lt;= s[j]; k--); &amp;nbsp;&lt;i&gt;/* &lt;/i&gt;&lt;/b&gt;&lt;i&gt;finding the largest non-increasing sub-string */&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (k == j)&lt;/b&gt;&lt;b&gt;&amp;nbsp;continue;&lt;/b&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char tmp = s[k];&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s[k] = s[j];&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s[j] = tmp; &amp;nbsp; &lt;/b&gt;&lt;i&gt;/* swaping the elements */&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sort(s.begin() + j + 1, s.end()); &lt;/b&gt;&lt;i&gt;/* sorting the sub-string */&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (j &amp;lt; 0)&lt;/b&gt;&lt;b&gt;&amp;nbsp;cout &amp;lt;&amp;lt; &quot;no answer&quot; &amp;lt;&amp;lt; endl; &lt;/b&gt;&amp;nbsp;&lt;i&gt;/* if &amp;nbsp;no permutation exist than this will get executed */&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;/b&gt;&lt;b&gt;&amp;nbsp; cout &amp;lt;&amp;lt; s &amp;lt;&amp;lt; endl; &lt;/b&gt;&lt;i&gt;&amp;nbsp;/* if permutation exist than print it */&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;/blockquote&gt;
&lt;div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #656565; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; text-align: center; vertical-align: baseline;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;*****&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #656565; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; text-align: center; vertical-align: baseline;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;IF YOU WANT ME TO EXPLAIN A PERTICULAR PROBLEM THAN PLEASE LEAVE A LINK TO THE PROBLEM IN THE COMMENT SECTION&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b style=&quot;background-color: white; color: #656565; font-size: 14px;&quot;&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;-webkit-text-stroke-width: 0px; background-color: white; border: 0px; color: #656565; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal; letter-spacing: normal; margin: 0px; orphans: 2; outline: 0px; padding: 0px; text-align: center; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
&lt;b style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;*****&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;//feedburner.google.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;vertical-align:middle;border:0&quot;/&gt;&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><link>http://gotitt.blogspot.com/2016/09/next-lexicographical-permutation-algorithm.html</link><author>noreply@blogger.com (Dinesh)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC-rcOR4X5cmTNPXZDbEqe0cUiAGPRHS22eQLEo7I9T-cd2l8x8z5OTjJRNfmllJnHANCAndURHliNjqL2L9oJUn0GMGU7bYPvwC9CXBtLVpX-R-hVh7I1nT4nhhoYyUqUusUxnCSfadU/s72-c/Bigger+is+greater.JPG" height="72" width="72"/><thr:total>13</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7833753242240216799.post-32536209292619482</guid><pubDate>Mon, 12 Sep 2016 09:15:00 +0000</pubDate><atom:updated>2016-09-29T14:01:07.662-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Algorithm</category><category domain="http://www.blogger.com/atom/ns#">Implementation</category><title>Kangaroo</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;tr_bq&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px; font-style: inherit; font-weight: inherit;&quot;&gt;There are two kangaroos on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot; style=&quot;background-color: white; border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.671ex;&quot; viewbox=&quot;0 -576.1 1026.4 865.1&quot; width=&quot;2.384ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(572,-150)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px; font-style: inherit; font-weight: inherit;&quot;&gt;&amp;nbsp;and moves at a rate of&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot; style=&quot;background-color: white; border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.671ex;&quot; viewbox=&quot;0 -576.1 939.4 865.1&quot; width=&quot;2.182ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M173 380Q173 405 154 405Q130 405 104 376T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Q21 294 29 316T53 368T97 419T160 441Q202 441 225 417T249 361Q249 344 246 335Q246 329 231 291T200 202T182 113Q182 86 187 69Q200 26 250 26Q287 26 319 60T369 139T398 222T409 277Q409 300 401 317T383 343T365 361T357 383Q357 405 376 424T417 443Q436 443 451 425T467 367Q467 340 455 284T418 159T347 40T241 -11Q177 -11 139 22Q102 54 102 117Q102 148 110 181T151 298Q173 362 173 380Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(485,-150)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px; font-style: inherit; font-weight: inherit;&quot;&gt;&amp;nbsp;meters per jump. The second kangaroo starts at location&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot; style=&quot;background-color: white; border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.671ex;&quot; viewbox=&quot;0 -576.1 1026.4 865.1&quot; width=&quot;2.384ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(572,-150)&quot;&gt;&lt;path d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px; font-style: inherit; font-weight: inherit;&quot;&gt;&amp;nbsp;and moves at a rate of&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot; style=&quot;background-color: white; border: 0px; color: #39424e; direction: ltr; display: inline-block; float: none; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.671ex;&quot; viewbox=&quot;0 -576.1 939.4 865.1&quot; width=&quot;2.182ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M173 380Q173 405 154 405Q130 405 104 376T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Q21 294 29 316T53 368T97 419T160 441Q202 441 225 417T249 361Q249 344 246 335Q246 329 231 291T200 202T182 113Q182 86 187 69Q200 26 250 26Q287 26 319 60T369 139T398 222T409 277Q409 300 401 317T383 343T365 361T357 383Q357 405 376 424T417 443Q436 443 451 425T467 367Q467 340 455 284T418 159T347 40T241 -11Q177 -11 139 22Q102 54 102 117Q102 148 110 181T151 298Q173 362 173 380Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(485,-150)&quot;&gt;&lt;path d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px; font-style: inherit; font-weight: inherit;&quot;&gt;&amp;nbsp;meters per jump. Given the starting locations and movement rates for each kangaroo, can you determine if they&#39;ll ever land&amp;nbsp;&lt;/span&gt;&lt;em style=&quot;background-color: white; border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;at the same location at the same time&lt;/em&gt;&lt;span style=&quot;background-color: white; color: #39424e; font-size: 16px; font-style: inherit; font-weight: inherit;&quot;&gt;?&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-weight: normal;&quot;&gt;&lt;div class=&quot;challenge_input_format&quot; style=&quot;background-color: white; border: 0px; color: #39424e; font-family: arial, helvetica, sans-serif; font-size: 16px; font-stretch: inherit; font-weight: normal; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;msB challenge_input_format_title&quot; style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;strong style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Input Format&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;msB challenge_input_format_body&quot; style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;hackdown-content&quot; style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;A single line of four space-separated integers denoting the respective values of&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.671ex;&quot; viewbox=&quot;0 -576.1 1026.4 865.1&quot; width=&quot;2.384ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(572,-150)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;,&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.671ex;&quot; viewbox=&quot;0 -576.1 939.4 865.1&quot; width=&quot;2.182ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M173 380Q173 405 154 405Q130 405 104 376T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Q21 294 29 316T53 368T97 419T160 441Q202 441 225 417T249 361Q249 344 246 335Q246 329 231 291T200 202T182 113Q182 86 187 69Q200 26 250 26Q287 26 319 60T369 139T398 222T409 277Q409 300 401 317T383 343T365 361T357 383Q357 405 376 424T417 443Q436 443 451 425T467 367Q467 340 455 284T418 159T347 40T241 -11Q177 -11 139 22Q102 54 102 117Q102 148 110 181T151 298Q173 362 173 380Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(485,-150)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;,&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.671ex;&quot; viewbox=&quot;0 -576.1 1026.4 865.1&quot; width=&quot;2.384ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(572,-150)&quot;&gt;&lt;path d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, and&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.671ex;&quot; viewbox=&quot;0 -576.1 939.4 865.1&quot; width=&quot;2.182ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M173 380Q173 405 154 405Q130 405 104 376T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Q21 294 29 316T53 368T97 419T160 441Q202 441 225 417T249 361Q249 344 246 335Q246 329 231 291T200 202T182 113Q182 86 187 69Q200 26 250 26Q287 26 319 60T369 139T398 222T409 277Q409 300 401 317T383 343T365 361T357 383Q357 405 376 424T417 443Q436 443 451 425T467 367Q467 340 455 284T418 159T347 40T241 -11Q177 -11 139 22Q102 54 102 117Q102 148 110 181T151 298Q173 362 173 380Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(485,-150)&quot;&gt;&lt;path d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;challenge_constraints&quot; style=&quot;background-color: white; border: 0px; font-stretch: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;msB challenge_constraints_title&quot; style=&quot;border: 0px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 1.5em; margin-bottom: 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;challenge_constraints&quot; style=&quot;border: 0px; font-stretch: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;msB challenge_constraints_title&quot; style=&quot;border: 0px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-variant-numeric: inherit; line-height: 1.5em; margin-bottom: 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-family: inherit; font-size: 16px; font-style: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit; font-weight: inherit;&quot;&gt;
&lt;strong style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;Constraints&lt;/strong&gt;&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;0&amp;lt;= x1 &amp;lt; x2 &amp;lt;= 10000&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;1 &amp;lt;= x1 &amp;lt;= 10000&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px 0px 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;1&amp;lt;= v2 &amp;lt;= 10000&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;color: #39424e; font-family: inherit; font-size: 16px; font-style: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit; font-weight: inherit;&quot;&gt;
&lt;strong style=&quot;border: 0px; font-family: arial, helvetica, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Output Format&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;challenge_output_format&quot; style=&quot;background-color: white; border: 0px; font-family: arial, helvetica, sans-serif; font-stretch: inherit; font-weight: normal; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;msB challenge_output_format_body&quot; style=&quot;border: 0px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;hackdown-content&quot; style=&quot;border: 0px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: normal; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;Print&amp;nbsp;&lt;code style=&quot;background: rgb(248, 248, 248); border-radius: 3px; border: 0px; color: #26a655; font-size: 1em; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 3px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;YES&lt;/code&gt;&amp;nbsp;if they can land on the same location at the same time; otherwise, print&amp;nbsp;&lt;code style=&quot;background: rgb(248, 248, 248); border-radius: 3px; border: 0px; color: #26a655; font-size: 1em; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 3px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;NO&lt;/code&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-weight: normal; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;span style=&quot;color: #39424e; font-family: inherit;&quot;&gt;&lt;span style=&quot;font-style: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;MY&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;EXPLANATION&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: inherit;&quot;&gt;&lt;span style=&quot;font-style: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;:&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: normal; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;background-color: transparent; font-weight: normal;&quot;&gt;This is a simple high school maths problem like 2 trains start at different location,given their velocity can you find whether they will ever meet or not?&lt;/span&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-style: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;Let&#39;s name the kangaroo&#39;s as K1 and K2 and given K2 starts ahead of K1 (i.e. x2 &amp;gt; x1).&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;font-weight: normal;&quot;&gt;
&lt;span style=&quot;background-color: transparent;&quot;&gt;Now, they will meet only when distance traveled by K1 is equal to the sum of distance traveled by K2 and their initial separation(i.e. (x1-x2)&amp;nbsp;+ distance(K2) ). This is visualized below.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-weight: normal; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieQuTKEpwHhxSjymdCVDvC1jrH3xgLnwl1ImvZOTypazeveIeuWhai1ZYLrEiYhwJv9c1aywZ1LXKRYPhsoVPyORghvqf-7brWUSzhCcb2CrvnhDrYUm78GRHdhVDt8KGCtKnjyyVzfuY/s1600/kangaroo1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieQuTKEpwHhxSjymdCVDvC1jrH3xgLnwl1ImvZOTypazeveIeuWhai1ZYLrEiYhwJv9c1aywZ1LXKRYPhsoVPyORghvqf-7brWUSzhCcb2CrvnhDrYUm78GRHdhVDt8KGCtKnjyyVzfuY/s1600/kangaroo1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: normal;&quot;&gt;
&lt;span style=&quot;background-color: transparent; font-style: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: transparent; font-style: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;let say they meet after time &lt;/span&gt;T&lt;span style=&quot;font-weight: normal;&quot;&gt; then the condition will be&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: normal; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;background-color: transparent;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;b&gt;v1*T = (x2 - x1)&amp;nbsp;+ v2*T&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: normal; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;background-color: transparent; font-weight: normal;&quot;&gt;In other word, they will meet if&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: normal; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;b style=&quot;background-color: transparent;&quot;&gt;T = ( x2 - x1 ) % ( v1 - v2 ) &amp;nbsp;is equal to 0 &lt;/b&gt;&lt;i style=&quot;background-color: transparent;&quot;&gt;( zero)&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #39424e; font-size: 16px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: normal; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
&lt;span style=&quot;background-color: transparent; font-weight: normal;&quot;&gt;Now try to write your own code keeping these things in mind.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/h4&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;If you don&#39;t succeed than take a look at my solution.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;int main(){&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;int x1, x2, v1, v2;&lt;i&gt; &lt;/i&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;/* Initializing variables */&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;cin &amp;gt;&amp;gt; x1 &amp;gt;&amp;gt; v1 &amp;gt;&amp;gt; x2 &amp;gt;&amp;gt; v2; &lt;/b&gt;&lt;i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;/* assigining values to the variables&amp;nbsp; */&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;if( v1&amp;gt;v2 &amp;nbsp;&amp;amp;&amp;amp; &amp;nbsp;(x2-x1)%(v1-v2)==0 )cout&amp;lt;&amp;lt;&quot;YES&quot;; &lt;/b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;i&gt;/* if this is the case than they will meet , so print &lt;/i&gt;YES&amp;nbsp;&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;*/&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;else cout&amp;lt;&amp;lt;&quot;NO&quot;;&lt;/b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;i&gt; &lt;/i&gt;&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;/* In any other case they wont meet */&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;return 0;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;}&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/blockquote&gt;
&lt;br /&gt;
&lt;br /&gt;
Question Source: &lt;a href=&quot;https://www.hackerrank.com/challenges/kangaroo/copy-from/29088437&quot; target=&quot;_blank&quot;&gt;hackerrank.com&lt;/a&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;//feedburner.google.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;vertical-align:middle;border:0&quot;/&gt;&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><link>http://gotitt.blogspot.com/2016/09/kangaroo.html</link><author>noreply@blogger.com (Dinesh)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieQuTKEpwHhxSjymdCVDvC1jrH3xgLnwl1ImvZOTypazeveIeuWhai1ZYLrEiYhwJv9c1aywZ1LXKRYPhsoVPyORghvqf-7brWUSzhCcb2CrvnhDrYUm78GRHdhVDt8KGCtKnjyyVzfuY/s72-c/kangaroo1.png" height="72" width="72"/><thr:total>7</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7833753242240216799.post-1311827946259341102</guid><pubDate>Sat, 10 Sep 2016 09:30:00 +0000</pubDate><atom:updated>2016-10-04T07:41:28.251-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Algorithm</category><category domain="http://www.blogger.com/atom/ns#">Implementation</category><title>Lisa&#39;s Workbook</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;In this post i will explain the solution of the &lt;span data-mce-style=&quot;color: #3366ff;&quot; style=&quot;color: #3366ff;&quot;&gt;&lt;a data-mce-href=&quot;https://www.hackerrank.com/challenges/lisa-workbook/&quot; data-mce-style=&quot;color: #3366ff;&quot; href=&quot;https://www.hackerrank.com/challenges/lisa-workbook/&quot; style=&quot;color: #3366ff;&quot; target=&quot;_blank&quot;&gt;following problem&lt;/a&gt; &lt;/span&gt;at &lt;span data-mce-style=&quot;color: #3366ff;&quot; style=&quot;color: #3366ff;&quot;&gt;&lt;a data-mce-href=&quot;https://www.hackerrank.com/&quot; data-mce-style=&quot;color: #3366ff;&quot; href=&quot;https://www.hackerrank.com/&quot; style=&quot;color: #3366ff;&quot; target=&quot;_blank&quot;&gt;hackerrank.com&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Here is the problem statement.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVe0piS_dhZ3i3OVoaecG7m3YutKaF4EEwOYuTu69n20stuEgC4UqoebWm4fbuMvb1izSbX-H5rOqnHEP7YtFrEtkN1gYqtju3ZO23AX1naZplw-unWWgZA0Fjy4hJKtNPx1tkufu-1L0/s1600/lisa%2527s+workbook.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVe0piS_dhZ3i3OVoaecG7m3YutKaF4EEwOYuTu69n20stuEgC4UqoebWm4fbuMvb1izSbX-H5rOqnHEP7YtFrEtkN1gYqtju3ZO23AX1naZplw-unWWgZA0Fjy4hJKtNPx1tkufu-1L0/s1600/lisa%2527s+workbook.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;This problem looks difficult at the first sight but it&#39;s not too&amp;nbsp;difficult if you go step by step.&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Create a loop which runs through the chapters.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Inside that loop create another loop which runs through all the problems in &amp;nbsp;that particular chapter and checks whether the problem number is equal to chapter number or not.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;AN ADVICE : Try writing a code before reading further.Keep in mind the above 2 steps. If you don&#39;t succeed than come back here and read further.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;First of all initialize two int variables to keep track of the page number and the number of special problem,i have initialized&amp;nbsp;&lt;b&gt;pagenum &lt;/b&gt;and&lt;strong&gt;&amp;nbsp;spb &lt;/strong&gt;as these two variables.Initialize another three variables for the number of chapters, maximum number of problems per page and the number of problems per chapter.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Take the inputs i.e. the number of chapters and the maximum number of problems per chapter. Now create a loop which runs through the chapters.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Now take another input which will be the number of problems per chapter. After that create another loop which will run through the problems in a particular chapter and check whether the problem number is equal to the page number or not. If equal than increase the variable &lt;b&gt;&amp;nbsp;spb &lt;/b&gt;by 1, if not than continue. Take a look at my solution.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Hope it helped you :)&lt;/span&gt;&lt;br /&gt;
&lt;blockquote&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;using namespace std;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;int main() { &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int n,k,pagenum=1,spb=0, numprob;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;n&amp;gt;&amp;gt;k;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;for(int i=1;i&amp;lt;=n;i++){&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;numprob;&lt;/b&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(int j=1;&amp;nbsp;j&amp;amp;lt&amp;nbsp;=numprob;&amp;nbsp;j++){ &amp;nbsp; &lt;/strong&gt;/* looping through the problems. */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(&amp;nbsp;pagenum==j&amp;amp;nbsp)spb++;&lt;/strong&gt;&amp;nbsp;/*if problem number is equal to page number than increase spb.*/&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(&amp;nbsp;j==numprob || j%k==0&amp;nbsp;)&lt;/strong&gt;&lt;strong&gt;&amp;nbsp;pagenum++; &lt;/strong&gt;/*if j reaches&amp;nbsp;the problem number or j%k=0 then increase the page number.*/&lt;/span&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt; cout&amp;lt;&amp;lt;spb;&amp;nbsp;&lt;/strong&gt;/*print the number of special problems.*/&lt;/span&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;return 0;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/strong&gt;&lt;/blockquote&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;*****&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;IF YOU WANT ME TO EXPLAIN A PERTICULAR PROBLEM THAN PLEASE LEAVE A LINK TO THE PROBLEM IN THE COMMENT SECTION&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;*****&lt;/b&gt;&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;//feedburner.google.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;vertical-align:middle;border:0&quot;/&gt;&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><link>http://gotitt.blogspot.com/2016/09/lisas-workbook.html</link><author>noreply@blogger.com (Dinesh)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVe0piS_dhZ3i3OVoaecG7m3YutKaF4EEwOYuTu69n20stuEgC4UqoebWm4fbuMvb1izSbX-H5rOqnHEP7YtFrEtkN1gYqtju3ZO23AX1naZplw-unWWgZA0Fjy4hJKtNPx1tkufu-1L0/s72-c/lisa%2527s+workbook.jpg" height="72" width="72"/><thr:total>34</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7833753242240216799.post-4227909137417614220</guid><pubDate>Sat, 10 Sep 2016 09:29:00 +0000</pubDate><atom:updated>2016-10-04T07:48:05.496-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Algorithm</category><category domain="http://www.blogger.com/atom/ns#">Implementation</category><title>Absolute Permutation</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;This is the most efficient solution of the &lt;span data-mce-style=&quot;text-decoration: underline; color: #0000ff;&quot; style=&quot;color: blue; text-decoration: underline;&quot;&gt;&lt;a data-mce-href=&quot;https://www.hackerrank.com/challenges/absolute-permutation&quot; data-mce-style=&quot;color: #0000ff; text-decoration: underline;&quot; href=&quot;https://www.hackerrank.com/challenges/absolute-permutation&quot; style=&quot;color: blue; text-decoration: underline;&quot; target=&quot;_blank&quot;&gt;Absolute Permutation&lt;/a&gt;&lt;/span&gt;&amp;nbsp;question asked &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;at&amp;nbsp;&lt;span data-mce-style=&quot;text-decoration: underline;&quot; style=&quot;text-decoration: underline;&quot;&gt;&lt;span data-mce-style=&quot;color: #0000ff;&quot; style=&quot;color: blue;&quot;&gt;&lt;a data-mce-href=&quot;https://www.hackerrank.com/&quot; data-mce-style=&quot;color: #0000ff; text-decoration: underline;&quot; href=&quot;https://www.hackerrank.com/&quot; style=&quot;color: blue; text-decoration: underline;&quot; target=&quot;_blank&quot;&gt;hackerrank.com&lt;/a&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;.&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Here is the question.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;div class=&quot;challenge_problem_statement&quot; style=&quot;background-color: white; border: 0px; color: #39424e; font-family: &amp;quot;Whitney SSm A&amp;quot;, &amp;quot;Whitney SSm B&amp;quot;, Avenir, &amp;quot;Segoe UI&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, Ubuntu, sans-serif; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;msB challenge_problem_statement_body&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;hackdown-content&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
We define&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 751.5 936.9&quot; width=&quot;1.745ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;to be a permutation of the first&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 888.5 936.9&quot; width=&quot;2.064ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;natural numbers in the range&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.843ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.838ex;&quot; viewbox=&quot;0 -863.1 2391.2 1223.9&quot; width=&quot;5.554ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M118 -250V750H255V710H158V-210H255V-250H118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(278,0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(779,0)&quot;&gt;&lt;path d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1224,0)&quot;&gt;&lt;path d=&quot;M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2112,0)&quot;&gt;&lt;path d=&quot;M22 710V750H159V-250H22V-210H119V710H22Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;. Let&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.009ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.671ex;&quot; viewbox=&quot;-38.5 -576.1 1841.3 865.1&quot; width=&quot;4.277ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(503,0)&quot;&gt;&lt;path d=&quot;M201 -11Q126 -11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441Q333 441 341 440Q354 437 367 433T402 417T438 387T464 338T476 268Q476 161 390 75T201 -11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375Q346 405 306 405Q243 405 195 347Q158 303 140 230T121 120Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(989,0)&quot;&gt;&lt;path d=&quot;M131 289Q131 321 147 354T203 415T300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372T367 378Q368 378 368 379Q368 382 361 388T336 399T297 405Q249 405 227 379T204 326Q204 301 223 291T278 274T330 259Q396 230 396 163Q396 135 385 107T352 51T289 7T195 -10Q118 -10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34T201 27Q237 27 263 38T301 66T318 97T323 122Q323 150 302 164T254 181T195 196T148 231Q131 256 131 289Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(469,-150)&quot;&gt;&lt;path d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;denote the position of&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-5-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 345.5 936.9&quot; width=&quot;0.802ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;in permutation&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-6-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 751.5 936.9&quot; width=&quot;1.745ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;(please use&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-7-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 500.5 936.9&quot; width=&quot;1.162ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;-based indexing).&lt;/div&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-8-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 751.5 936.9&quot; width=&quot;1.745ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;is considered to be an&amp;nbsp;&lt;em style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;absolute permutation&lt;/em&gt;&amp;nbsp;if&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-9-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.843ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.838ex;&quot; viewbox=&quot;0 -863.1 7802.3 1223.9&quot; width=&quot;18.122ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(529,0)&quot;&gt;&lt;path d=&quot;M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402Q231 442 283 442Q345 442 383 396T422 280Q422 169 343 79T173 -11Q123 -11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640T73 647ZM336 325V331Q336 405 275 405Q258 405 240 397T207 376T181 352T163 330L157 322L136 236Q114 150 114 114Q114 66 138 42Q154 26 178 26Q211 26 245 58Q270 81 285 114T318 219Q336 291 336 325Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(959,0)&quot;&gt;&lt;path d=&quot;M131 289Q131 321 147 354T203 415T300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372T367 378Q368 378 368 379Q368 382 361 388T336 399T297 405Q249 405 227 379T204 326Q204 301 223 291T278 274T330 259Q396 230 396 163Q396 135 385 107T352 51T289 7T195 -10Q118 -10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34T201 27Q237 27 263 38T301 66T318 97T323 122Q323 150 302 164T254 181T195 196T148 231Q131 256 131 289Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1428,0)&quot;&gt;&lt;path d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1818,0)&quot;&gt;&lt;path d=&quot;M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2321,0)&quot;&gt;&lt;path d=&quot;M201 -11Q126 -11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441Q333 441 341 440Q354 437 367 433T402 417T438 387T464 338T476 268Q476 161 390 75T201 -11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375Q346 405 306 405Q243 405 195 347Q158 303 140 230T121 120Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2807,0)&quot;&gt;&lt;path d=&quot;M131 289Q131 321 147 354T203 415T300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372T367 378Q368 378 368 379Q368 382 361 388T336 399T297 405Q249 405 227 379T204 326Q204 301 223 291T278 274T330 259Q396 230 396 163Q396 135 385 107T352 51T289 7T195 -10Q118 -10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34T201 27Q237 27 263 38T301 66T318 97T323 122Q323 150 302 164T254 181T195 196T148 231Q131 256 131 289Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(469,-150)&quot;&gt;&lt;path d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3843,0)&quot;&gt;&lt;path d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(4843,0)&quot;&gt;&lt;path d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(5189,0)&quot;&gt;&lt;path d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(5856,0)&quot;&gt;&lt;path d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(6912,0)&quot;&gt;&lt;path d=&quot;M285 628Q285 635 228 637Q205 637 198 638T191 647Q191 649 193 661Q199 681 203 682Q205 683 214 683H219Q260 681 355 681Q389 681 418 681T463 682T483 682Q500 682 500 674Q500 669 497 660Q496 658 496 654T495 648T493 644T490 641T486 639T479 638T470 637T456 637Q416 636 405 634T387 623L306 305Q307 305 490 449T678 597Q692 611 692 620Q692 635 667 637Q651 637 651 648Q651 650 654 662T659 677Q662 682 676 682Q680 682 711 681T791 680Q814 680 839 681T869 682Q889 682 889 672Q889 650 881 642Q878 637 862 637Q787 632 726 586Q710 576 656 534T556 455L509 418L518 396Q527 374 546 329T581 244Q656 67 661 61Q663 59 666 57Q680 47 717 46H738Q744 38 744 37T741 19Q737 6 731 0H720Q680 3 625 3Q503 3 488 0H478Q472 6 472 9T474 27Q478 40 480 43T491 46H494Q544 46 544 71Q544 75 517 141T485 216L427 354L359 301L291 248L268 155Q245 63 245 58Q245 51 253 49T303 46H334Q340 37 340 35Q340 19 333 5Q328 0 317 0Q314 0 280 1T180 2Q118 2 85 2T49 1Q31 1 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;holds true for every&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-10-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.843ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.838ex;&quot; viewbox=&quot;0 -863.1 3959.7 1223.9&quot; width=&quot;9.197ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(623,0)&quot;&gt;&lt;path d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1568,0)&quot;&gt;&lt;path d=&quot;M118 -250V750H255V710H158V-210H255V-250H118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1847,0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2347,0)&quot;&gt;&lt;path d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2792,0)&quot;&gt;&lt;path d=&quot;M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3681,0)&quot;&gt;&lt;path d=&quot;M22 710V750H159V-250H22V-210H119V710H22Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.&lt;/div&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
Given&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-11-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 888.5 936.9&quot; width=&quot;2.064ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-12-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 889.5 936.9&quot; width=&quot;2.066ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M285 628Q285 635 228 637Q205 637 198 638T191 647Q191 649 193 661Q199 681 203 682Q205 683 214 683H219Q260 681 355 681Q389 681 418 681T463 682T483 682Q500 682 500 674Q500 669 497 660Q496 658 496 654T495 648T493 644T490 641T486 639T479 638T470 637T456 637Q416 636 405 634T387 623L306 305Q307 305 490 449T678 597Q692 611 692 620Q692 635 667 637Q651 637 651 648Q651 650 654 662T659 677Q662 682 676 682Q680 682 711 681T791 680Q814 680 839 681T869 682Q889 682 889 672Q889 650 881 642Q878 637 862 637Q787 632 726 586Q710 576 656 534T556 455L509 418L518 396Q527 374 546 329T581 244Q656 67 661 61Q663 59 666 57Q680 47 717 46H738Q744 38 744 37T741 19Q737 6 731 0H720Q680 3 625 3Q503 3 488 0H478Q472 6 472 9T474 27Q478 40 480 43T491 46H494Q544 46 544 71Q544 75 517 141T485 216L427 354L359 301L291 248L268 155Q245 63 245 58Q245 51 253 49T303 46H334Q340 37 340 35Q340 19 333 5Q328 0 317 0Q314 0 280 1T180 2Q118 2 85 2T49 1Q31 1 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, print the lexicographically smallest absolute permutation,&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-13-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 751.5 936.9&quot; width=&quot;1.745ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;; if no absolute permutation exists, print&amp;nbsp;&lt;code style=&quot;background: rgb(248, 248, 248); border-radius: 3px; border: 0px; color: #26a655; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 3px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;-1&lt;/code&gt;.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;challenge_input_format&quot; style=&quot;background-color: white; border: 0px; color: #39424e; font-family: &amp;quot;Whitney SSm A&amp;quot;, &amp;quot;Whitney SSm B&amp;quot;, Avenir, &amp;quot;Segoe UI&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, Ubuntu, sans-serif; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;msB challenge_input_format_title&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;strong style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;Input Format&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;msB challenge_input_format_body&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;hackdown-content&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
The first line of input contains a single integer,&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 704.5 936.9&quot; width=&quot;1.636ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, denoting the number of test cases.&amp;nbsp;&lt;br style=&quot;word-break: break-word; word-wrap: break-word;&quot; /&gt;Each of the&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 704.5 936.9&quot; width=&quot;1.636ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;subsequent lines contains&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 500.5 936.9&quot; width=&quot;1.162ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;space-separated integers describing the respective&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 888.5 936.9&quot; width=&quot;2.064ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-5-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.176ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.338ex;&quot; viewbox=&quot;0 -791.3 889.5 936.9&quot; width=&quot;2.066ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M285 628Q285 635 228 637Q205 637 198 638T191 647Q191 649 193 661Q199 681 203 682Q205 683 214 683H219Q260 681 355 681Q389 681 418 681T463 682T483 682Q500 682 500 674Q500 669 497 660Q496 658 496 654T495 648T493 644T490 641T486 639T479 638T470 637T456 637Q416 636 405 634T387 623L306 305Q307 305 490 449T678 597Q692 611 692 620Q692 635 667 637Q651 637 651 648Q651 650 654 662T659 677Q662 682 676 682Q680 682 711 681T791 680Q814 680 839 681T869 682Q889 682 889 672Q889 650 881 642Q878 637 862 637Q787 632 726 586Q710 576 656 534T556 455L509 418L518 396Q527 374 546 329T581 244Q656 67 661 61Q663 59 666 57Q680 47 717 46H738Q744 38 744 37T741 19Q737 6 731 0H720Q680 3 625 3Q503 3 488 0H478Q472 6 472 9T474 27Q478 40 480 43T491 46H494Q544 46 544 71Q544 75 517 141T485 216L427 354L359 301L291 248L268 155Q245 63 245 58Q245 51 253 49T303 46H334Q340 37 340 35Q340 19 333 5Q328 0 317 0Q314 0 280 1T180 2Q118 2 85 2T49 1Q31 1 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&amp;nbsp;values for a test case.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;challenge_constraints&quot; style=&quot;background-color: white; border: 0px; color: #39424e; font-family: &amp;quot;Whitney SSm A&amp;quot;, &amp;quot;Whitney SSm B&amp;quot;, Avenir, &amp;quot;Segoe UI&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, Ubuntu, sans-serif; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;msB challenge_constraints_title&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;strong style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;Constraints&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;msB challenge_constraints_body&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;hackdown-content&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;ul style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; list-style-image: initial; list-style-position: initial; margin: 10px 0px 20px 20px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;li style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.343ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.505ex;&quot; viewbox=&quot;0 -791.3 4874.1 1008.6&quot; width=&quot;11.321ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;path d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1834,0)&quot;&gt;&lt;path d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2816,0)&quot;&gt;&lt;path d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3873,0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.843ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.505ex;&quot; viewbox=&quot;0 -1006.6 5512 1223.9&quot; width=&quot;12.802ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;path d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1834,0)&quot;&gt;&lt;path d=&quot;M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3000,0)&quot;&gt;&lt;path d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(4057,0)&quot;&gt;&lt;path d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(1001,393)&quot;&gt;&lt;path d=&quot;M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z&quot; stroke-width=&quot;1&quot; transform=&quot;scale(0.707)&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot; style=&quot;border: 0px; direction: ltr; display: inline-block; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;&quot;&gt;&lt;svg focusable=&quot;false&quot; height=&quot;2.343ex&quot; role=&quot;img&quot; style=&quot;vertical-align: -0.505ex;&quot; viewbox=&quot;0 -791.3 4946.6 1008.6&quot; width=&quot;11.489ex&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;g fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; stroke=&quot;currentColor&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;path d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;path d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1834,0)&quot;&gt;&lt;path d=&quot;M285 628Q285 635 228 637Q205 637 198 638T191 647Q191 649 193 661Q199 681 203 682Q205 683 214 683H219Q260 681 355 681Q389 681 418 681T463 682T483 682Q500 682 500 674Q500 669 497 660Q496 658 496 654T495 648T493 644T490 641T486 639T479 638T470 637T456 637Q416 636 405 634T387 623L306 305Q307 305 490 449T678 597Q692 611 692 620Q692 635 667 637Q651 637 651 648Q651 650 654 662T659 677Q662 682 676 682Q680 682 711 681T791 680Q814 680 839 681T869 682Q889 682 889 672Q889 650 881 642Q878 637 862 637Q787 632 726 586Q710 576 656 534T556 455L509 418L518 396Q527 374 546 329T581 244Q656 67 661 61Q663 59 666 57Q680 47 717 46H738Q744 38 744 37T741 19Q737 6 731 0H720Q680 3 625 3Q503 3 488 0H478Q472 6 472 9T474 27Q478 40 480 43T491 46H494Q544 46 544 71Q544 75 517 141T485 216L427 354L359 301L291 248L268 155Q245 63 245 58Q245 51 253 49T303 46H334Q340 37 340 35Q340 19 333 5Q328 0 317 0Q314 0 280 1T180 2Q118 2 85 2T49 1Q31 1 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3001,0)&quot;&gt;&lt;path d=&quot;M694 -11T694 -19T688 -33T678 -40Q671 -40 524 29T234 166L90 235Q83 240 83 250Q83 261 91 266Q664 540 678 540Q681 540 687 534T694 519T687 505Q686 504 417 376L151 250L417 124Q686 -4 687 -5Q694 -11 694 -19Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g transform=&quot;translate(4058,0)&quot;&gt;&lt;path d=&quot;M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z&quot; stroke-width=&quot;1&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;challenge_output_format&quot; style=&quot;background-color: white; border: 0px; color: #39424e; font-family: &amp;quot;Whitney SSm A&amp;quot;, &amp;quot;Whitney SSm B&amp;quot;, Avenir, &amp;quot;Segoe UI&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, Ubuntu, sans-serif; font-size: 16px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;msB challenge_output_format_title&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;strong style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;Output Format&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;msB challenge_output_format_body&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div class=&quot;hackdown-content&quot; style=&quot;border: 0px; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
&lt;div style=&quot;border: 0px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; margin-bottom: 1em; margin-top: 12px; outline: 0px; padding: 0px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;
On a new line for each test case, print the lexicographically smallest absolute permutation; if no absolute permutation exists, print&amp;nbsp;&lt;code style=&quot;background: rgb(248, 248, 248); border-radius: 3px; border: 0px; color: #26a655; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 1em; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: 0px; padding: 3px; vertical-align: baseline; word-break: break-word; word-wrap: break-word;&quot;&gt;-1&lt;/code&gt;.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Key observations.&lt;/span&gt;&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The value of &amp;nbsp;k should be less than &amp;nbsp;or equal to n/2 other wise &lt;b&gt;abs(pos¡ &amp;nbsp;-i) =k &amp;nbsp;&lt;/b&gt;will not hold&amp;nbsp;true for every &lt;b&gt;i&lt;/b&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;K should be a divisor of n (i.e.n%k=0) .Take a pen and a paper and experiment with different k (divisor and non-divisor of n). It&#39;s better for you if you try it yourself.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The quotient of n/k should be divisible by 2. (i.e. (n/k)%2=0) Again think!!&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;If&amp;nbsp;you still didn&#39;t get this than a detailed explanation is there at the end of this post.I&amp;nbsp;have not&amp;nbsp;given the full explanation here since i want you all to try with these hint&#39;s first.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;That&#39;s it . That was all the hidden tricks that was there in this problem.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Here is my code.&lt;/span&gt;&lt;/div&gt;
&lt;blockquote style=&quot;text-align: left;&quot;&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;#include &amp;lt;vector&amp;gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;using namespace std;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;int main(){&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int t,n,k,dev;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cin &amp;gt;&amp;gt; t; &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; for(int a0 = 0; a0 &amp;lt; t; a0++){&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; k;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dev=n/k;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vector&amp;lt;int&amp;gt; pos(n);&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(k==0){ &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/strong&gt;//if k=0 print the array itself without manipulating any thing&lt;/span&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(int i=1;i&amp;lt;=n;i++)cout&amp;lt;&amp;lt;i&amp;lt;&amp;lt;&quot; &quot;;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else if ((k&amp;lt;=n/2)&amp;amp;&amp;amp;(n%k==0)&amp;amp;&amp;amp;(dev%2 ==0)){ &amp;nbsp;&lt;/strong&gt; //else if k&amp;lt;=n/2 and n%k==0 and (n/k)%2==0 than do this&lt;/span&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;for(int i=0;i&amp;lt;n;i++){&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if((i/k)%2 == 0)&lt;/strong&gt;&lt;strong&gt;&amp;nbsp;pos[i] = i + k+1; &amp;nbsp;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;/strong&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp;pos[i] = i - k+1;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (int i = 0; i&amp;lt; n; i++)&lt;/strong&gt;&lt;strong&gt;&amp;nbsp; cout &amp;lt;&amp;lt; pos[i] &amp;lt;&amp;lt; &quot; &quot;;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else &amp;nbsp;&amp;nbsp;cout &amp;lt;&amp;lt; &quot;-1&quot;;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt;endl;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; }&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; return 0;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;/strong&gt;&lt;/blockquote&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Here is the complete explanation in case someone is still struggling.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; k&amp;lt;=n/2 is very apparent so I have not discussed that here.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Please forgive me for explaining this in paper since I don&#39;t have enough time to type it in my computer.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwZGQXsMV-CKhPpghKKVvhGNIq8KP02CfPgSLfiAf1_fRHfFOzhfxK7zCFw7Br4LFw11yhfaGbKaGvzF5WSIKkDDLjkqmaT8gQYbOxoaWn7B_roNvXiuDFl8TYTZmkE9cdbGzW5c-cD7c/s1600/Abspermutation.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwZGQXsMV-CKhPpghKKVvhGNIq8KP02CfPgSLfiAf1_fRHfFOzhfxK7zCFw7Br4LFw11yhfaGbKaGvzF5WSIKkDDLjkqmaT8gQYbOxoaWn7B_roNvXiuDFl8TYTZmkE9cdbGzW5c-cD7c/s640/Abspermutation.jpg&quot; width=&quot;453&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;*****&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;IF YOU WANT ME TO EXPLAIN A PERTICULAR PROBLEM THAN PLEASE LEAVE A LINK TO THE PROBLEM IN THE COMMENT SECTION&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;*****&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;//feedburner.google.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;vertical-align:middle;border:0&quot;/&gt;&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><link>http://gotitt.blogspot.com/2016/09/absolute-permutation.html</link><author>noreply@blogger.com (Dinesh)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwZGQXsMV-CKhPpghKKVvhGNIq8KP02CfPgSLfiAf1_fRHfFOzhfxK7zCFw7Br4LFw11yhfaGbKaGvzF5WSIKkDDLjkqmaT8gQYbOxoaWn7B_roNvXiuDFl8TYTZmkE9cdbGzW5c-cD7c/s72-c/Abspermutation.jpg" height="72" width="72"/><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7833753242240216799.post-5350431266201930372</guid><pubDate>Sat, 10 Sep 2016 09:24:00 +0000</pubDate><atom:updated>2016-10-29T00:33:45.403-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Algorithm</category><category domain="http://www.blogger.com/atom/ns#">Warm Up</category><title>Circular Array Rotation</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: center;&quot;&gt;
In this post i will&amp;nbsp;&amp;nbsp;explain the Circular array rotation problem in the most efficient way. Here is the problem statement taken directly from&amp;nbsp;&lt;span data-mce-style=&quot;text-decoration: underline;&quot; style=&quot;text-decoration: underline;&quot;&gt;&lt;a data-mce-href=&quot;https://www.hackerrank.com/challenges/circular-array-rotation&quot; href=&quot;https://www.hackerrank.com/challenges/circular-array-rotation&quot; target=&quot;_blank&quot;&gt;hackerrank.com&lt;/a&gt;.&lt;/span&gt;&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQYZ92l9JmufSssHgb1qgGe7U3ZA7zWqbVGv5pxIDBiPGWrorZY8KregS-xCsl7RU7b3FLoNoCDkDxvjPL4RRhNppCBJfJRAnnYHTKqKnu87kbV-ESxoh5J71b0FqlauOkNy9VPLUDTK0/s1600/CircularAR.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;472&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQYZ92l9JmufSssHgb1qgGe7U3ZA7zWqbVGv5pxIDBiPGWrorZY8KregS-xCsl7RU7b3FLoNoCDkDxvjPL4RRhNppCBJfJRAnnYHTKqKnu87kbV-ESxoh5J71b0FqlauOkNy9VPLUDTK0/s640/CircularAR.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span data-mce-style=&quot;text-decoration: underline;&quot; style=&quot;text-decoration: underline;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the trick. We will consider 2 cases, 1st is &amp;nbsp;when k&amp;lt;m and 2nd is when k&amp;gt;m, you will get to know why we are considering these two cases as we go on.&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Let the input parameters be n, k=4 and m=5, so the numbers would be (1,2,3,4,5,6,7,8,9...n-1,n) keep note of the number at index m-k (i.e. at index 1). Now after &amp;nbsp;k=4 &amp;nbsp;rotations &amp;nbsp;the resulting numbers will be (n-3,n-2,n-1,n,1,2,3,4 ...n-5,n-4). Note that the current number at index m=5(which in this case is 2) was at an index &amp;nbsp;1 (i.e. at &lt;b&gt;m-k&lt;/b&gt;).&amp;nbsp;So we can directly find the element at index m=5 without actually rotating the array by outputting the element at index (&lt;b&gt;m-k&lt;/b&gt;).&lt;/li&gt;
&lt;li&gt;Now let k=4 and m=3. In this case the number that is at index m=3 was actually at an index (&lt;b&gt;n-k+m&lt;/b&gt;). Here also we can find the element at m=3 without rotating the array by outputting the element at index (&lt;b&gt;n-k+m&lt;/b&gt;).&lt;/li&gt;
&lt;/ol&gt;
In case you are wondering what about the case when &lt;b&gt;k&amp;gt;n&lt;/b&gt; well we can tackle that by using the&amp;nbsp;&lt;a data-mce-href=&quot;https://en.m.wikipedia.org/wiki/Modulo_operation&quot; data-mce-style=&quot;text-decoration: underline; color: blue;&quot; href=&quot;https://en.m.wikipedia.org/wiki/Modulo_operation&quot; style=&quot;color: blue; text-decoration: underline;&quot; target=&quot;_blank&quot;&gt;mod&lt;/a&gt;(%) operator.For those of you who do not know how mod(%) operator works. Basically it returns the remainder, let&lt;b&gt; k=r%n&lt;/b&gt;, so if rotation(i.e. &lt;b&gt;r&lt;/b&gt;) is greater than &lt;b&gt;n&lt;/b&gt;, due to the mod(%) operator the value of &lt;b&gt;k&lt;/b&gt; will be remainder of &lt;b&gt;r/n&lt;/b&gt;. e.x. if r=9, n=6 than k=3 and if &lt;b&gt;r&lt;/b&gt; is multiple of &lt;b&gt;n&lt;/b&gt; i.e. if r=5,10,15,20..... and n=5 than k=0 after the operation.&lt;br /&gt;
Here is my code.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
&lt;b&gt; #include &amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt; using namespace std;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt; int main() {&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int n,k,q,m,j;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cin&amp;gt;&amp;gt;n&amp;gt;&amp;gt;k&amp;gt;&amp;gt;q;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;k%=n; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;i&gt; &lt;/i&gt;&lt;/b&gt;&lt;i&gt;/* Or k=k%n which will make sure that the rotation is in circular manner. The &amp;nbsp;mod(%) operator returns the remainder so if rotation(i.e. k) is greater than n, due to the mod(%) operator the value of k will be remainder of k/n. e.x. if k=9, n=6 than k=3 after this operation and if k is multiple of n i.e. if k=5,10,15,20..... and n=5 than k=0 after the operation. */&lt;/i&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;b&gt;int *A= new int[n]&lt;/b&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;i&gt;&amp;nbsp;/* &amp;nbsp;OR int A[n] ---initializing an array A of size n . To know more about the format and it&#39;s use search for &lt;b&gt;dynamic array&lt;/b&gt; &amp;nbsp;*/&lt;/i&gt;&lt;br /&gt;
&lt;b&gt; for(int i=0;i&amp;lt;n;i++)&lt;/b&gt;&lt;b&gt;&amp;nbsp;cin&amp;gt;&amp;gt;A[i]; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;i&gt; /* filling the array */&lt;/i&gt;&lt;br /&gt;
&lt;b&gt; for(int i=0;i&amp;lt;q;i++){&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cin&amp;gt;&amp;gt;m; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;i&gt;/* taking the index */&lt;/i&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; j=m-k;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(j&amp;lt;0) cout&amp;lt;&amp;lt;A[n+j]&amp;lt;&amp;lt;endl; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;i&gt; /* the case when k&amp;gt;m. The output is A[n+j] &lt;/i&gt;which is nothing but A[n+m-k]. */&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else cout&amp;lt;&amp;lt;A[j]&amp;lt;&amp;lt;endl; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;i&gt;/* the case when k&amp;lt;m. The output is A[j] which is nothing but A[m-k]. */&lt;/i&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt; }&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt; return 0;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt; };&lt;/b&gt;&lt;/blockquote&gt;
&lt;br /&gt;
&lt;b&gt;*****IF YOU WANT ME TO EXPLAIN A PERTICULAR PROBLEM THAN PLEASE LEAVE A LINK TO THE PROBLEM IN THE COMMENT*****&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;&lt;img src=&quot;//feedburner.google.com/fb/images/pub/feed-icon32x32.png&quot; alt=&quot;&quot; style=&quot;vertical-align:middle;border:0&quot;/&gt;&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://feeds.feedburner.com/blogspot/vPctp&quot; rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot;&gt;Subscribe in a reader&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><link>http://gotitt.blogspot.com/2016/09/circular-array-rotation.html</link><author>noreply@blogger.com (Dinesh)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQYZ92l9JmufSssHgb1qgGe7U3ZA7zWqbVGv5pxIDBiPGWrorZY8KregS-xCsl7RU7b3FLoNoCDkDxvjPL4RRhNppCBJfJRAnnYHTKqKnu87kbV-ESxoh5J71b0FqlauOkNy9VPLUDTK0/s72-c/CircularAR.JPG" height="72" width="72"/><thr:total>30</thr:total></item></channel></rss>