{"id":307916,"date":"2020-08-03T15:01:08","date_gmt":"2020-08-03T15:01:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=307916"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=307916","title":{"rendered":"\u0412\u044b\u043f\u0443\u0441\u043a#40: IT\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u2014 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0442 \u0432\u0435\u0434\u0443\u0449\u0438\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/spice\/blog\/506354\/\">\u041f\u0440\u0438\u0432\u0435\u0442-\u043f\u0440\u0438\u0432\u0435\u0442! \u0421 \u0432\u0430\u043c\u0438 (\u043d\u0435)\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0440\u0443\u0431\u0440\u0438\u043a\u0430 IT\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430. \u0421\u043e\u0441\u043a\u0443\u0447\u0438\u043b\u0438\u0441\u044c? \u041c\u044b \u0442\u043e\u0436\u0435! <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1g\/ua\/yf\/1guayf3-57lapuy7zpfrbhdjqjo.png\"><\/p>\n<p>  \u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u0432\u0430\u043c \u043d\u0430 \u0435\u0436\u0435\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0441\u0435\u043d\u044c\u044e, \u0430 \u043f\u043e\u043a\u0430 \u0436\u0435 \u043b\u043e\u0432\u0438\u0442\u0435 \u043e\u0442 \u043d\u0430\u0441 \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0435\u043a \u0441 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439 \u0432 \u043d\u043e\u0440\u0432\u0435\u0436\u0441\u043a\u0443\u044e \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e Opera Software!<br \/>  \u0420\u0443\u0431\u0440\u0438\u043a\u0430 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u0440\u0435\u043a\u0440\u0443\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0433\u043e \u0430\u0433\u0435\u043d\u0442\u0441\u0442\u0432\u0430 <a href=\"http:\/\/www.spice-agency.ru\/ru\/\">Spice IT<\/a>.<a name=\"habracut\"><\/a><\/p>\n<h2>\u0412\u043e\u043f\u0440\u043e\u0441\u044b<\/h2>\n<p>  1. <b>Chinchillas Relations<\/b>  <\/p>\n<blockquote><p>A young pair of chinchillas (one of each sex) is placed on an island. A pair of chinchillas does not breed until they are 2 months old. After they are 2 months old, each pair of chinchillas produces another pair each month (See pic below). Find a recurrence relation for the number of pairs of chinchillas on the island after n months, assuming that no chinchillas ever die.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/87\/39\/mc\/8739mcfrylwudkiseyd20hh9vzg.png\"><\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u041c\u043e\u043b\u043e\u0434\u0430\u044f \u043f\u0430\u0440\u0430 \u0448\u0438\u043d\u0448\u0438\u043b\u043b (\u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043e\u0442 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u0430) \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u0442\u0440\u043e\u0432. \u041f\u0430\u0440\u0430 \u0448\u0438\u043d\u0448\u0438\u043b\u043b \u043d\u0435 \u0440\u0430\u0437\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u043a\u0430 \u0438\u043c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f 2 \u043c\u0435\u0441\u044f\u0446\u0430. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0438\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f 2 \u043c\u0435\u0441\u044f\u0446\u0430, \u043a\u0430\u0436\u0434\u0430\u044f \u043f\u0430\u0440\u0430 \u0448\u0438\u043d\u0448\u0438\u043b\u043b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u043f\u0430\u0440\u0443 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0441\u044f\u0446 (\u0441\u043c. \u0440\u0438\u0441 \u0432\u044b\u0448\u0435). \u041d\u0430\u0439\u0434\u0438\u0442\u0435 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0447\u0438\u0441\u043b\u0430 \u043f\u0430\u0440 \u0448\u0438\u043d\u0448\u0438\u043b\u043b \u043d\u0430 \u043e\u0441\u0442\u0440\u043e\u0432\u0435 \u0447\u0435\u0440\u0435\u0437 n \u043c\u0435\u0441\u044f\u0446\u0435\u0432, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044f, \u0447\u0442\u043e \u043d\u0438 \u043e\u0434\u043d\u0430 \u0448\u0438\u043d\u0448\u0438\u043b\u043b\u0430 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0443\u043c\u0440\u0435\u0442.<\/div>\n<\/p><\/div>\n<p>  2. <b>Priests in Temple<\/b>  <\/p>\n<blockquote><p>There are 20 priests in a temple. One day, Lord Shiva appears before them and tells them that some of them have sinned, and that a black spot would appear on the forehead of all the priests who have sinned. The priests are not allowed to look into a mirror or communicate with each other. When any priest finds out that there is a spot on his forehead, he should leave the temple on that day itself. At least 1 priest has sinned. How can a priest find out whether he has a spot on his forehead. What would be the pattern of the priests leaving the temple?<\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u0412 \u0445\u0440\u0430\u043c\u0435 \u0435\u0441\u0442\u044c 20 \u0441\u0432\u044f\u0449\u0435\u043d\u043d\u0438\u043a\u043e\u0432. \u041e\u0434\u043d\u0430\u0436\u0434\u044b \u0413\u043e\u0441\u043f\u043e\u0434\u044c \u0428\u0438\u0432\u0430 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c\u0438 \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0438\u043c, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0441\u043e\u0433\u0440\u0435\u0448\u0438\u043b\u0438, \u0438 \u0447\u0442\u043e \u0447\u0435\u0440\u043d\u043e\u0435 \u043f\u044f\u0442\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u043d\u0430 \u043b\u0431\u0443 \u0432\u0441\u0435\u0445 \u0441\u0432\u044f\u0449\u0435\u043d\u043d\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0433\u0440\u0435\u0448\u0438\u043b\u0438. \u0421\u0432\u044f\u0449\u0435\u043d\u043d\u0438\u043a\u0430\u043c \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0437\u0435\u0440\u043a\u0430\u043b\u043e \u0438\u043b\u0438 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c. \u041a\u043e\u0433\u0434\u0430 \u043b\u044e\u0431\u043e\u0439 \u0441\u0432\u044f\u0449\u0435\u043d\u043d\u0438\u043a \u0443\u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0443 \u043d\u0435\u0433\u043e \u043d\u0430 \u043b\u0431\u0443 \u0435\u0441\u0442\u044c \u043f\u044f\u0442\u043d\u043e, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043a\u0438\u043d\u0443\u0442\u044c \u0445\u0440\u0430\u043c \u0432 \u044d\u0442\u043e\u0442 \u0436\u0435 \u0434\u0435\u043d\u044c. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u043e\u0434\u0438\u043d \u0441\u0432\u044f\u0449\u0435\u043d\u043d\u0438\u043a \u0441\u043e\u0433\u0440\u0435\u0448\u0438\u043b. \u041a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0441\u0432\u044f\u0449\u0435\u043d\u043d\u0438\u043a \u0443\u0437\u043d\u0430\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0443 \u043d\u0435\u0433\u043e \u043f\u044f\u0442\u043d\u043e \u043d\u0430 \u043b\u0431\u0443? \u041a\u0430\u043a\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0445\u043e\u0434\u0430 \u0441\u0432\u044f\u0449\u0435\u043d\u043d\u0438\u043a\u043e\u0432 \u0438\u0437 \u0445\u0440\u0430\u043c\u0430?<\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>  1. <b>Prime Number of Set Bits in Binary Representation<\/b>  <\/p>\n<blockquote><p>Given two integers <b>L<\/b> and <b>R<\/b>, find the count of numbers in the range <b>[L, R]<\/b> (inclusive) having a prime number of set bits in their binary representation.<\/p>\n<p>  (Recall that the number of set bits an integer has is the number of 1s present when written in binary. For example, <b>21<\/b> written in binary is <b>10101<\/b> which has 3 set bits. Also, 1 is not a prime.)<\/p>\n<p>  <b>Example 1:<\/b><br \/>  <b>Input:<\/b> L = 6, R = 10<br \/>  <b>Output:<\/b> 4<br \/>  <b>Explanation:<\/b><br \/>  6 -&gt; 110 (2 set bits, 2 is prime)<br \/>  7 -&gt; 111 (3 set bits, 3 is prime)<br \/>  9 -&gt; 1001 (2 set bits, 2 is prime)<br \/>  10-&gt;1010 (2 set bits, 2 is prime)<\/p>\n<p>  <b>Example 2:<\/b><br \/>  <b>Input:<\/b> L = 10, R = 15<br \/>  <b>Output:<\/b> 5<br \/>  <b>Explanation:<\/b><br \/>  10 -&gt; 1010 (2 set bits, 2 is prime)<br \/>  11 -&gt; 1011 (3 set bits, 3 is prime)<br \/>  12 -&gt; 1100 (2 set bits, 2 is prime)<br \/>  13 -&gt; 1101 (3 set bits, 3 is prime)<br \/>  14 -&gt; 1110 (3 set bits, 3 is prime)<br \/>  15 -&gt; 1111 (4 set bits, 4 is not prime)<\/p>\n<p>  <b>Note:<\/b><br \/>  L, R will be integers L &lt;= R in the range [1, 10^6].<br \/>  R \u2014 L will be at most 10000.<\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u0414\u0430\u043d\u044b \u0434\u0432\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 <b>L<\/b> \u0438 <b>R<\/b>, \u043d\u0430\u0439\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0438\u0441\u0435\u043b \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 <b>[L, R]<\/b> (\u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e), \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432 \u0432 \u0438\u0445 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438.<\/p>\n<p>  (\u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u0431\u0438\u0442\u043e\u0432 \u043d\u0430\u0431\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043c\u0435\u0435\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u2014 \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e 1s, \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u043a\u043e\u0434\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 21 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u2014 10101, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043c\u0435\u0435\u0442 3 \u043d\u0430\u0431\u043e\u0440 \u0431\u0438\u0442\u043e\u0432. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, 1 \u2014 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.)<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 1:<\/b><br \/>  <b>\u0412\u0445\u043e\u0434:<\/b> L = 6, R = 10<br \/>  <b>\u0412\u044b\u0445\u043e\u0434: <\/b>4<br \/>  <b>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/b><br \/>  6 \u2014 &gt; 110 (2 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 2 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e)<br \/>  7 \u2014 &gt; 111 (3 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 3 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e)<br \/>  9 \u2014 &gt; 1001 (2 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 2 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e)<br \/>  10-&gt;1010 (2 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 2 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e)<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 2:<\/b><br \/>  <b>\u0412\u0445\u043e\u0434: <\/b>L = 10, R = 15<br \/>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b> 5<br \/>  <b>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/b><br \/>  10 -&gt; 1010 (2 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 2 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e)<br \/>  11 \u2014 &gt; 1011 (3 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 3 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e)<br \/>  12 \u2014 &gt; 1100 (2 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 2 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e)<br \/>  13 -&gt; 1101 (3 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 3 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e)<br \/>  14 \u2014 &gt; 1110 (3 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 3 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e)<br \/>  15 \u2014 &gt; 1111 (4 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u0438\u0442\u043e\u0432, 4 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c)<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/b><br \/>  L, R \u0431\u0443\u0434\u0443\u0442 \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 L &lt;= R \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 [1, 10^6].<br \/>  R-L \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 10000.<\/div>\n<\/p><\/div>\n<p>  2. <b>Maximum Sum Circular Subarray<\/b>  <\/p>\n<blockquote><p>Given a <b>circular array C<\/b> of integers represented by <b>A<\/b>, find the maximum possible sum of a non-empty subarray of <b>C<\/b>.<\/p>\n<p>  Here, a <i>circular array<\/i> means the end of the array connects to the beginning of the array. (Formally, <b>C[i] = A[i]<\/b> when <b>0 &lt;= i &lt; A.length<\/b>, and <b>C[i+A.length] = C[i] when i &gt;= 0<\/b>.)<\/p>\n<p>  Also, a subarray may only include each element of the fixed buffer <b>A<\/b> at most once. (Formally, for a subarray <b>C[i], C[i+1], &#8230;, C[j]<\/b>, there does not exist <b>i &lt;= k1, k2 &lt;= j<\/b> with <b>k1 % A.length = k2 % A.length<\/b>.)<\/p>\n<p>  <b>Example 1:<\/b><br \/>  <b>Input: <\/b>[1,-2,3,-2]<br \/>  <b>Output: <\/b>3<br \/>  <b>Explanation: <\/b>Subarray [3] has maximum sum 3<\/p>\n<p>  <b>Example 2:<\/b><br \/>  <b>Input:<\/b> [5,-3,5]<br \/>  <b>Output: <\/b>10<br \/>  <b>Explanation: <\/b>Subarray [5,5] has maximum sum 5 + 5 = 10<\/p>\n<p>  <b>Example 3:<\/b><br \/>  <b>Input: <\/b>[3,-1,2,-1]<br \/>  <b>Output: <\/b>4<br \/>  <b>Explanation:<\/b> Subarray [2,-1,3] has maximum sum 2 + (-1) + 3 = 4<\/p>\n<p>  <b>Example 4:<\/b><br \/>  <b>Input: <\/b>[3,-2,2,-3]<br \/>  <b>Output:<\/b> 3<br \/>  <b>Explanation:<\/b> Subarray [3] and [3,-2,2] both have maximum sum 3<\/p>\n<p>  <b>Example 5:<\/b><br \/>  <b>Input:<\/b> [-2,-3,-1]<br \/>  <b>Output:<\/b> -1<br \/>  <b>Explanation: <\/b>Subarray [-1] has maximum sum -1<\/p>\n<p>  <b>Note:<\/b><br \/>  <code>-30000 &lt;= A[i] &lt;= 30000<br \/>  1 &lt;= A.length &lt;= 30000<\/code><\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u0414\u0430\u043d <b>\u043a\u0440\u0443\u0433\u043e\u0432\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0421<\/b> \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 <b>A<\/b>, \u043d\u0430\u0439\u0434\u0438\u0442\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043d\u0435\u043f\u0443\u0441\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432\u0430<b> C<\/b>.<\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c <i>\u043a\u0440\u0443\u0433\u043e\u0432\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432<\/i> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043d\u0435\u0446 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u0441 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0430. (\u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e <b>C[i] = A[i]<\/b>, <b>0 &lt;= i &lt; A.length<\/b>, \u0438<b>C[i+A.length] = C[i]<\/b>, \u043a\u043e\u0433\u0434\u0430 <b>i &gt;= 0<\/b>.)<br \/>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u043e\u0436\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430 \u0410 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0430. (\u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432\u0430 <b>C[i], C[i+1],&#8230;, C[j]<\/b>, \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 <b>i &lt;= k1, k2 &lt;= j <\/b>\u0441 <b>k1 % A.length = k2 % A.length<\/b>.)<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 1:<\/b><br \/>  <b>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: <\/b>[1, -2,3, -2]<br \/>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b> 3<br \/>  <b>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/b> \u041f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432 [3] \u0438\u043c\u0435\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 3<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 2:<\/b><br \/>  <b>\u0412\u0445\u043e\u0434:<\/b> [5,-3,5]<br \/>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b> 10<br \/>  <b>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435: <\/b>\u041f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432 [5,5] \u0438\u043c\u0435\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 5 + 5 = 10<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 3:<\/b><br \/>  <b>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: <\/b>[3,-1,2, -1]<br \/>  <b>\u0412\u044b\u0445\u043e\u0434: <\/b>4<br \/>  <b>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/b> \u041f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432 [2, -1,3] \u0438\u043c\u0435\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 2 + (-1) + 3 = 4<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 4:<\/b><br \/>  <b>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: <\/b>[3,-2,2,-3]<br \/>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b> 3<br \/>  <b>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/b> \u041f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432\u044b [3] \u0438 [3,-2,2] \u0438\u043c\u0435\u044e\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 3<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 5:<\/b><br \/>  <b>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: <\/b>[-2,-3, -1]<br \/>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b> -1<br \/>  <b>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/b> \u041f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432 [-1] \u0438\u043c\u0435\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 -1<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/b><br \/>  <code>-30000 &lt;= A[i] &lt;= 30000<br \/>  1 &lt;= A.length &lt;= 30000<\/code><\/div>\n<\/p><\/div>\n<p>  3. <b>Shortest Path Visiting All Nodes<\/b>  <\/p>\n<blockquote><p>An undirected, connected graph of N nodes (labeled <b>0, 1, 2, &#8230;, N-1<\/b>) is given as graph.<\/p>\n<p>  <b>graph.length = N<\/b>, and <b>j != i<\/b> is in the list <b>graph[i]<\/b> exactly once, if and only if nodes <b>i<\/b> and <b>j<\/b> are connected.<\/p>\n<p>  Return the length of the shortest path that visits every node. You may start and stop at any node, you may revisit nodes multiple times, and you may reuse edges.<\/p>\n<p>  <b>Example 1:<\/b><br \/>  <b>Input: <\/b>[[1,2,3],[0],[0],[0]]<br \/>  <b>Output: <\/b>4<br \/>  <b>Explanation: <\/b>One possible path is [1,0,2,0,3]<\/p>\n<p>  <b>Example 2:<\/b><br \/>  <b>Input:<\/b> [[1],[0,2,4],[1,3,4],[2],[1,2]]<br \/>  <b>Output:<\/b> 4<br \/>  <b>Explanation:<\/b> One possible path is [0,1,4,2,3]<\/p>\n<p>  <b>Note:<\/b><br \/>  <code>1 &lt;= graph.length &lt;= 12<br \/>  0 &lt;= graph[i].length &lt; graph.length<\/code><\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u041d\u0435\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0432\u044f\u0437\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 \u0438\u0437 <b>N<\/b> \u0443\u0437\u043b\u043e\u0432 (\u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 <b>0, 1, 2, &#8230;, N-1<\/b>) \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0430.<\/p>\n<p>  <b>graph.length = N<\/b> \u0438 <b>j != i <\/b>\u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 <b>graph[i]<\/b> \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0435\u0441\u043b\u0438 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0443\u0437\u043b\u044b <b>i<\/b> \u0438 <b>j<\/b> \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u044b.<\/p>\n<p>  \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0434\u043b\u0438\u043d\u0443 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u0435\u0449\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043b\u044e\u0431\u043e\u043c \u0443\u0437\u043b\u0435, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0443\u0437\u043b\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0431\u0440\u0430.<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 1:<\/b><br \/>  <b>\u0412\u0445\u043e\u0434\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f: <\/b>[[1,2,3],[0],[0],[0]]<br \/>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b> 4<br \/>  <b>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/b> \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u0443\u0442\u0435\u0439 \u2014 [1,0,2,0,3]<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 2:<\/b><br \/>  <b>\u0412\u0445\u043e\u0434\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f:<\/b> [[1],[0,2,4],[1,3,4],[2],[1,2]]<br \/>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b> 4<br \/>  <b>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/b> \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u0443\u0442\u0435\u0439 \u2014 \u044d\u0442\u043e [0,1,4,2,3]<\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/b><br \/>  <code>1 &lt;= graph.length &lt;= 12<br \/>  0 &lt;= graph[i].length &lt; graph.length<\/code><\/div>\n<\/p><\/div>\n<p>  \u041e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u0430\u043d\u044b \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043d\u0435\u0434\u0435\u043b\u0438 \u2014 \u0443\u0441\u043f\u0435\u0439\u0442\u0435 \u0440\u0435\u0448\u0438\u0442\u044c. \u0423\u0434\u0430\u0447\u0438!<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/spice\/blog\/506354\/\"> https:\/\/habr.com\/ru\/company\/spice\/blog\/506354\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/spice\/blog\/506354\/\">\u041f\u0440\u0438\u0432\u0435\u0442-\u043f\u0440\u0438\u0432\u0435\u0442! \u0421 \u0432\u0430\u043c\u0438 (\u043d\u0435)\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0440\u0443\u0431\u0440\u0438\u043a\u0430 IT\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430. \u0421\u043e\u0441\u043a\u0443\u0447\u0438\u043b\u0438\u0441\u044c? \u041c\u044b \u0442\u043e\u0436\u0435! <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1g\/ua\/yf\/1guayf3-57lapuy7zpfrbhdjqjo.png\"><\/p>\n<p>  \u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u0432\u0430\u043c \u043d\u0430 \u0435\u0436\u0435\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0441\u0435\u043d\u044c\u044e, \u0430 \u043f\u043e\u043a\u0430 \u0436\u0435 \u043b\u043e\u0432\u0438\u0442\u0435 \u043e\u0442 \u043d\u0430\u0441 \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0435\u043a \u0441 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439 \u0432 \u043d\u043e\u0440\u0432\u0435\u0436\u0441\u043a\u0443\u044e \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e Opera Software!<br \/>  \u0420\u0443\u0431\u0440\u0438\u043a\u0430 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u0440\u0435\u043a\u0440\u0443\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0433\u043e \u0430\u0433\u0435\u043d\u0442\u0441\u0442\u0432\u0430 <a href=\"http:\/\/www.spice-agency.ru\/ru\/\">Spice IT<\/a>.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-307916","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=307916"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307916\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}