{"id":66,"date":"2017-05-19T10:45:45","date_gmt":"2017-05-19T03:45:45","guid":{"rendered":"https:\/\/dangnhsite.wordpress.com\/?p=66"},"modified":"2018-01-02T05:01:53","modified_gmt":"2018-01-02T05:01:53","slug":"lam-toan-giai-tri-mot-ti-nhi","status":"publish","type":"post","link":"https:\/\/dangnh.cf\/vi\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/","title":{"rendered":"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9?"},"content":{"rendered":"<p>Ok, ch\u00e0o t\u1ea5t c\u1ea3 anh em <img decoding=\"async\" class=\"emoji\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/2.2.1\/svg\/1f600.svg\" alt=\"\ud83d\ude00\" \/><\/p>\n<p>Ch\u1ea3 l\u00e0 cu\u1ed1i tu\u1ea7n, \u1edf nh\u00e0 r\u1ea3nh rang, tr\u1eddi th\u00ec se se l\u1ea1nh, m\u0169i h\u01a1i t\u1eafc, ch\u1ec9 mu\u1ed1n co ro qu\u1ea5n ch\u0103n \u00f4m laptop cho \u1ea5m. Lang thang thi c\u00e1i cu\u1ed9c thi l\u1eadp tr\u00ecnh c\u1ee7a b\u1ecdn Top Career g\u00ec \u0111\u00f3 :v v\u00f4 t\u00ecnh v\u1ea5p ph\u1ea3i 1 b\u00e0i test demo, m\u00e0 m\u00ecnh th\u1ea5y kh\u00e1 hay, n\u00ean mu\u1ed1n chia s\u1ebb l\u00ean \u0111\u00e2y cho c\u1ea3 nh\u00e0 <img decoding=\"async\" class=\"emoji\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/2.2.1\/svg\/1f609.svg\" alt=\"\ud83d\ude09\" \/><\/p>\n<p><span id=\"more-3887\"><\/span><br \/>\n\u0110\u1ec1 b\u00e0i:<\/p>\n<pre>A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 \u2264 P &lt; N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e.\nA[0] + A[1] + ... + A[P\u22121] = A[P+1] + ... + A[N\u22122] + A[N\u22121].\nSum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N\u22121.\nFor example, consider the following array A consisting of N = 8 elements:\nA[0] = -1 A[1] = 3 A[2] = -4 A[3] = 5 A[4] = 1 A[5] = -6 A[6] = 2 A[7] = 1\nP = 1 is an equilibrium index of this array, because:\nA[0] = \u22121 = A[2] + A[3] + A[4] + A[5] + A[6] + A[7]\nP = 3 is an equilibrium index of this array, because:\nA[0] + A[1] + A[2] = \u22122 = A[4] + A[5] + A[6] + A[7]\nP = 7 is also an equilibrium index, because:\nA[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] = 0\nand there are no elements with indices greater than 7.\nP = 8 is not an equilibrium index, because it does not fulfill the condition 0 \u2264 P &lt; N.\nWrite a function:\nfunction solution($A);\nthat, given a zero-indexed array A consisting of N integers, returns any of its equilibrium indices. The function should return \u22121 if no equilibrium index exists.\nFor example, given array A shown above, the function may return 1, 3 or 7, as explained above.\nAssume that:\nN is an integer within the range [0..100,000];\neach element of array A is an integer within the range [\u22122,147,483,648..2,147,483,647].\nComplexity:\nexpected worst-case time complexity is O(N);\nexpected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).\nElements of input arrays can be modified.\n<\/pre>\n<div class=\"crayon-line crayon-striped-line\">\n<p>D\u1ecbch \u0111\u1ea1i kh\u00e1i l\u00e0:<\/p>\n<pre>Ta c\u00f3 1 indexed array A g\u1ed3m N ph\u1ea7n t\u1eed l\u00e0 c\u00e1c s\u1ed1 t\u1ef1 nhi\u00ean b\u1ea5t k\u1ef3. T\u00ecm ch\u1ec9 s\u1ed1 c\u00e2n b\u1eb1ng P sao cho P l\u00e0\n\n- Key c\u1ee7a array A\n- Th\u1ecfa m\u00e3n \u0111i\u1ec1u ki\u1ec7n: A[0] + A[1] + ... + A[P\u22121] = A[P+1] + ... + A[N\u22122] + A[N\u22121].\n- P = 0 ho\u1eb7c P= N-1 \u0111\u1ec1u c\u00f3 th\u1ec3 l\u00e0 gi\u00e1 tr\u1ecb \u0111\u00fang\n- C\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u ho\u1eb7c 1 gi\u00e1 tr\u1ecb P\n- N\u1ebfu kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb n\u00e0o, function c\u1ea7n return -1\nC\u00e1c \u0111i\u1ec1u ki\u1ec7n v\u1ec1 complexity, assumption m\u1eddi xem ph\u1ea7n ti\u1ebfng Anh nh\u00e9, l\u01b0\u1eddi d\u1ecbch :D\n<\/pre>\n<div id=\"crayon-591e688ea2fb0018149760\" class=\"crayon-syntax crayon-theme-sublime-text crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped\">\n<div class=\"crayon-line crayon-striped-line\">\n<p>R\u1ed3i, \u0111\u1ec1 b\u00e0i l\u00e0 nh\u01b0 v\u1eady, y\u00eau c\u1ea7u vi\u1ebft 1 function d\u01b0\u1edbi ng\u00f4n ng\u1eef n\u00e0o c\u0169ng \u0111\u01b0\u1ee3c, th\u1eddi gian l\u00e0m b\u00e0i l\u00e0\u00a0<strong>30 ph\u00fat<\/strong>.<\/p>\n<hr \/>\n<p style=\"text-align: center;\"><strong>GI\u1ea2I<\/strong><\/p>\n<p><em>(\u0110\u00e2y l\u00e0 c\u00e1ch gi\u1ea3i c\u1ee7a m\u00ecnh, ai c\u00f3 c\u00e1ch n\u00e0o hay h\u01a1n th\u00ec comment nh\u00e9 <img decoding=\"async\" class=\"emoji\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/2.2.1\/svg\/1f600.svg\" alt=\"\ud83d\ude00\" \/> )<\/em><\/p>\n<p><em>H\u01b0\u1edbng gi\u1ea3i c\u1ee7a m\u00ecnh l\u00e0 s\u1ebd chia m\u1ea3ng 1 chi\u1ec1u n\u00e0y th\u00e0nh 2 ph\u1ea7n, <strong>T\u1ed5ng\u00a0<\/strong><strong>Tr\u00e1i\u00a0<\/strong>v\u00e0 <strong>T\u1ed5ng\u00a0<\/strong><strong>Ph\u1ea3i<\/strong>. Sau \u0111\u00f3 ch\u1ea1y d\u1ea7n t\u1eeb tr\u00e1i qua ph\u1ea3i c\u1ee7a m\u1ea3ng v\u00e0 so s\u00e1nh 2 t\u1ed5ng n\u00e0y v\u1edbi nhau. EZPZ ph\u1ea3i kh\u00f4ng? :))<\/em><\/p>\n<p>M\u00ecnh code PHP nh\u00e9, \u0111\u1ea7u ti\u00ean g\u00e1n gi\u00e1 tr\u1ecb default ph\u00e1t\u00a0<em>(th\u00f3i quen th\u00f4i, PHP kh\u00f4ng c\u1ea7n initialize bi\u1ebfn)<\/em><\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction ($A)\r\n{\r\n    $sumLeft = 0;\r\n    $sumRight = array_sum($A);\r\n    $equi = -1;\r\n}\r\n \r\n\/\/$A l\u00e0 arrray nh\u1eadp v\u00e0o\r\n\/\/$equi l\u00e0 s\u1ed1 P c\u1ea7n t\u00ecm\r\n<\/pre>\n<div id=\"crayon-591e688ea2fb6407053776\" class=\"crayon-syntax crayon-theme-eclipse crayon-font-monaco crayon-os-pc print-yes notranslate\">\n<p>R\u1ed3i, b\u00e2y gi\u1edd l\u1eb7p qua c\u00e1i array A xem sao nh\u1ec9?<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction ($A)\r\n{\r\n    $sumLeft = 0;\r\n    $sumRight = array_sum($A);\r\n    $equi = \u20131;\r\n    for ($index = 0; $index &lt; count($A); $index++) {\r\n        \/\/So s\u00e1nh $sumLeft v\u1edbi $sumRight trong n\u00e0y\r\n        \/\/M\u00ecnh d\u00f9ng for thay v\u00ec foreach do l\u00fd do performance\r\n    }\r\n    return $equi;\r\n}\r\n<\/pre>\n<div class=\"crayon-line crayon-striped-line\">\n<p>B\u1eaft \u0111\u1ea7u so s\u00e1nh, v\u00e0 ph\u1ea3i tr\u1eeb d\u1ea7n\u00a0<strong>$sumRight\u00a0<\/strong> t\u0103ng d\u1ea7n\u00a0<strong>$sumLeft\u00a0<\/strong>v\u1edbi gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed7i element<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction ($A)\r\n{\r\n    $sumLeft = 0;\r\n    $sumRight = array_sum($A);\r\n    $equi = \u20131;\r\n    for ($index = 0; $index &lt; count($A); $index++) {\r\n        $tempRight = $sumRight \u2013 $A&#x5B;$index];\r\n        if ($sumLeft === $tempRight) {\r\n            $equi = $index;\r\n            return $equi;\r\n        } else {\r\n            $sumLeft += $A&#x5B;$index];\r\n            $sumRight = $tempRight;\r\n        }\r\n    }\r\n    return $equi;\r\n}\r\n<\/pre>\n<div class=\"crayon-syntax crayon-theme-eclipse crayon-font-monaco crayon-os-pc print-yes notranslate\">\n<p>Tr\u00f4ng c\u00f3 v\u1ebb \u1ed5n \u1ed5n r\u1ed3i \u0111\u1ea5y nh\u1ec9 :))<\/p>\n<p>Nh\u01b0ng th\u1ef1c ra l\u00e0 \u0111\u1ebfch \u1ed5n, m\u00ecnh c\u00f2n ch\u01b0a check null c\u01a1 m\u00e0 =)) c\u00e1i c\u01a1 b\u1ea3n nh\u1ea5t c\u00f2n su\u1ed1t ng\u00e0y qu\u00ean \u0111\u00e2y<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction ($A)\r\n{\r\n    $sumLeft = 0;\r\n    $sumRight = array_sum($A);\r\n    $equi = \u20131;\r\n    if (count($A)) {\r\n        for ($index = 0; $index &lt; count($A); $index++) {\r\n            $tempRight = $sumRight \u2013 $A&#x5B;$index];\r\n            if ($sumLeft === $tempRight) {\r\n                $equi = $index;\r\n                return $equi;\r\n            }\r\n            $sumLeft += $A&#x5B;$index];\r\n            $sumRight = $tempRight;\r\n        }\r\n        return $equi;\r\n    }\r\n    return \u20131;\r\n}\r\n<\/pre>\n<div class=\"crayon-line\">\n<p>Ok done! N\u00e0o, b\u00e2y gi\u1edd test th\u00f4i!<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\necho demo(&#x5B;4, 35, 80, 123, 12345, 44, 8, 5, 24, 3]);\r\n<\/pre>\n<figure id=\"attachment_100\" aria-describedby=\"caption-attachment-100\" style=\"width: 509px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"100\" data-permalink=\"https:\/\/dangnh.cf\/vi\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/result-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-1.png?fit=509%2C167&amp;ssl=1\" data-orig-size=\"509,167\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"result-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-1.png?fit=509%2C167&amp;ssl=1\" class=\" size-full wp-image-100 aligncenter\" src=\"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-1.png?resize=509%2C167\" alt=\"result-1\" width=\"509\" height=\"167\" srcset=\"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-1.png?w=509&amp;ssl=1 509w, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-1.png?resize=300%2C98&amp;ssl=1 300w\" sizes=\"auto, (max-width: 509px) 100vw, 509px\" \/><figcaption id=\"caption-attachment-100\" class=\"wp-caption-text\">Result<\/figcaption><\/figure>\n<p>Chu\u1ea9n \u0111\u00e9t :)) Test th\u1eed v\u1edbi d\u1eef li\u1ec7u\u00a0kh\u00e1c xem sao<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\necho demo(&#x5B;-1, 3, -4, 5, 1, -6, 2, 1]);\r\n<\/pre>\n<figure id=\"attachment_106\" aria-describedby=\"caption-attachment-106\" style=\"width: 404px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"106\" data-permalink=\"https:\/\/dangnh.cf\/vi\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/result-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-2.png?fit=404%2C127&amp;ssl=1\" data-orig-size=\"404,127\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"result-2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-2.png?fit=404%2C127&amp;ssl=1\" class=\" size-full wp-image-106 aligncenter\" src=\"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-2.png?resize=404%2C127\" alt=\"result-2\" width=\"404\" height=\"127\" srcset=\"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-2.png?w=404&amp;ssl=1 404w, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/result-2.png?resize=300%2C94&amp;ssl=1 300w\" sizes=\"auto, (max-width: 404px) 100vw, 404px\" \/><figcaption id=\"caption-attachment-106\" class=\"wp-caption-text\">Result<\/figcaption><\/figure>\n<p><strong>Done! <img decoding=\"async\" class=\"emoji aligncenter\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/2.2.1\/svg\/1f642.svg\" alt=\"\ud83d\ude42\" \/><\/strong><\/p>\n<p>Hy v\u1ecdng anh em gi\u1ea3i to\u00e1n vui v\u1ebb :)) c\u00f3 solution n\u00e0o ngon h\u01a1n nh\u1edb comment -_- \u0111\u1eebng c\u00f3 \u00e9m h\u00e0ng<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Ok, ch\u00e0o t\u1ea5t c\u1ea3 anh em Ch\u1ea3 l\u00e0 cu\u1ed1i tu\u1ea7n, \u1edf nh\u00e0 r\u1ea3nh rang, tr\u1eddi th\u00ec se se l\u1ea1nh, m\u0169i h\u01a1i t\u1eafc, ch\u1ec9 mu\u1ed1n co ro qu\u1ea5n ch\u0103n \u00f4m laptop cho \u1ea5m. Lang thang thi c\u00e1i cu\u1ed9c thi l\u1eadp tr\u00ecnh c\u1ee7a b\u1ecdn Top Career g\u00ec \u0111\u00f3 :v v\u00f4 t\u00ecnh v\u1ea5p ph\u1ea3i 1 b\u00e0i test demo, m\u00e0 m\u00ecnh th\u1ea5y kh\u00e1 hay, n\u00ean mu\u1ed1n chia s\u1ebb l\u00ean \u0111\u00e2y cho c\u1ea3 nh\u00e0 \u0110\u1ec1 b\u00e0i: A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 \u2264 P &lt; N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e. A[0] + A[1] + &#8230; + A[P\u22121] = A[P+1] + &#8230; + A[N\u22122] + A[N\u22121]. Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N\u22121. For example, consider the following array A consisting of N = 8 elements: A[0] = -1 A[1] = 3 A[2] = -4 A[3] = 5 A[4] = 1 A[5] = -6 A[6] = 2 A[7] = 1 P = 1 is an equilibrium index of this array, because: A[0] = \u22121 = A[2] + A[3] + A[4] + A[5] + A[6] + A[7] P = 3 is an equilibrium index of this array, because: A[0] + A[1] + A[2] = \u22122 = A[4] + A[5] + A[6] + A[7] P = 7 is also an equilibrium index, because: A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] = 0 and there are no elements with indices greater than 7. P = 8 is not an equilibrium index, because it does not fulfill the condition 0 \u2264 P &lt; N. Write a function: function solution($A); that, given a zero-indexed array A consisting of N integers, returns any of its equilibrium indices. The function should return \u22121 if no equilibrium index exists. For example, given array A shown above, the function may return 1, 3 or 7, as explained above. Assume that: N is an integer within the range [0..100,000]; each element of array A is an integer within the range [\u22122,147,483,648..2,147,483,647]. Complexity: expected worst-case time complexity is O(N); expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments). Elements of input arrays can be modified. D\u1ecbch \u0111\u1ea1i kh\u00e1i l\u00e0: Ta c\u00f3 1 indexed array A g\u1ed3m N ph\u1ea7n t\u1eed l\u00e0 c\u00e1c s\u1ed1 t\u1ef1 nhi\u00ean b\u1ea5t k\u1ef3. T\u00ecm ch\u1ec9 s\u1ed1 c\u00e2n b\u1eb1ng P sao cho P l\u00e0 &#8211; Key c\u1ee7a array A &#8211; Th\u1ecfa m\u00e3n \u0111i\u1ec1u ki\u1ec7n: A[0] + A[1] + &#8230; + A[P\u22121] = A[P+1] + &#8230; + A[N\u22122] + A[N\u22121]. &#8211; P = 0 ho\u1eb7c P= N-1 \u0111\u1ec1u c\u00f3 th\u1ec3 l\u00e0 gi\u00e1 tr\u1ecb \u0111\u00fang &#8211; C\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u ho\u1eb7c 1 gi\u00e1 tr\u1ecb P &#8211; N\u1ebfu kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb n\u00e0o, function c\u1ea7n return -1 C\u00e1c \u0111i\u1ec1u ki\u1ec7n v\u1ec1 complexity, assumption m\u1eddi xem ph\u1ea7n ti\u1ebfng Anh nh\u00e9, l\u01b0\u1eddi d\u1ecbch \ud83d\ude00 R\u1ed3i, \u0111\u1ec1 b\u00e0i l\u00e0 nh\u01b0 v\u1eady, y\u00eau c\u1ea7u vi\u1ebft 1 function d\u01b0\u1edbi ng\u00f4n ng\u1eef n\u00e0o c\u0169ng \u0111\u01b0\u1ee3c, th\u1eddi gian l\u00e0m b\u00e0i l\u00e0\u00a030 ph\u00fat. GI\u1ea2I (\u0110\u00e2y l\u00e0 c\u00e1ch gi\u1ea3i c\u1ee7a m\u00ecnh, ai c\u00f3 c\u00e1ch n\u00e0o hay h\u01a1n th\u00ec comment nh\u00e9 ) H\u01b0\u1edbng gi\u1ea3i c\u1ee7a m\u00ecnh l\u00e0 s\u1ebd chia m\u1ea3ng 1 chi\u1ec1u n\u00e0y th\u00e0nh 2 ph\u1ea7n, T\u1ed5ng\u00a0Tr\u00e1i\u00a0v\u00e0 T\u1ed5ng\u00a0Ph\u1ea3i. Sau \u0111\u00f3 ch\u1ea1y d\u1ea7n t\u1eeb tr\u00e1i qua ph\u1ea3i c\u1ee7a m\u1ea3ng v\u00e0 so s\u00e1nh 2 t\u1ed5ng n\u00e0y v\u1edbi nhau. EZPZ ph\u1ea3i kh\u00f4ng? :)) M\u00ecnh code PHP nh\u00e9, \u0111\u1ea7u ti\u00ean g\u00e1n gi\u00e1 tr\u1ecb default ph\u00e1t\u00a0(th\u00f3i quen th\u00f4i, PHP kh\u00f4ng c\u1ea7n initialize bi\u1ebfn) function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = -1; } \/\/$A l\u00e0 arrray nh\u1eadp v\u00e0o \/\/$equi l\u00e0 s\u1ed1 P c\u1ea7n t\u00ecm R\u1ed3i, b\u00e2y gi\u1edd l\u1eb7p qua c\u00e1i array A xem sao nh\u1ec9? function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = \u20131; for ($index = 0; $index &lt; count($A); $index++) { \/\/So s\u00e1nh $sumLeft v\u1edbi $sumRight trong n\u00e0y \/\/M\u00ecnh d\u00f9ng for thay v\u00ec foreach do l\u00fd do performance } return $equi; } B\u1eaft \u0111\u1ea7u so s\u00e1nh, v\u00e0 ph\u1ea3i tr\u1eeb d\u1ea7n\u00a0$sumRight\u00a0 t\u0103ng d\u1ea7n\u00a0$sumLeft\u00a0v\u1edbi gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed7i element function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = \u20131; for ($index = 0; $index &lt; count($A); $index++) { $tempRight = $sumRight \u2013 $A&#x5B;$index]; if ($sumLeft === $tempRight) { $equi = $index; return $equi; } else { $sumLeft += $A&#x5B;$index]; $sumRight = $tempRight; } } return $equi; } Tr\u00f4ng c\u00f3 v\u1ebb \u1ed5n \u1ed5n r\u1ed3i \u0111\u1ea5y nh\u1ec9 :)) Nh\u01b0ng th\u1ef1c ra l\u00e0 \u0111\u1ebfch \u1ed5n, m\u00ecnh c\u00f2n ch\u01b0a check null c\u01a1 m\u00e0 =)) c\u00e1i c\u01a1 b\u1ea3n nh\u1ea5t c\u00f2n su\u1ed1t ng\u00e0y qu\u00ean \u0111\u00e2y function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = \u20131; if (count($A)) { for ($index = 0; $index &lt; count($A); $index++) { $tempRight = $sumRight \u2013 $A&#x5B;$index]; if ($sumLeft === $tempRight) { $equi = $index; return $equi; } $sumLeft += $A&#x5B;$index]; $sumRight = $tempRight; } return $equi; } return \u20131; } Ok done! N\u00e0o, b\u00e2y gi\u1edd test th\u00f4i! echo demo(&#x5B;4, 35, 80, 123, 12345, 44, 8, 5, 24, 3]); Chu\u1ea9n \u0111\u00e9t :)) Test th\u1eed v\u1edbi d\u1eef li\u1ec7u\u00a0kh\u00e1c xem sao echo demo(&#x5B;-1, 3, -4, 5, 1, -6, 2, 1]); Done! Hy v\u1ecdng anh em gi\u1ea3i to\u00e1n vui v\u1ebb :)) c\u00f3 solution n\u00e0o ngon h\u01a1n nh\u1edb comment -_- \u0111\u1eebng c\u00f3 \u00e9m h\u00e0ng<\/p>\n","protected":false},"author":1,"featured_media":110,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-66","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9? - Mark&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dangnh.cf\/vi\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9? - Mark&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"Ok, ch\u00e0o t\u1ea5t c\u1ea3 anh em Ch\u1ea3 l\u00e0 cu\u1ed1i tu\u1ea7n, \u1edf nh\u00e0 r\u1ea3nh rang, tr\u1eddi th\u00ec se se l\u1ea1nh, m\u0169i h\u01a1i t\u1eafc, ch\u1ec9 mu\u1ed1n co ro qu\u1ea5n ch\u0103n \u00f4m laptop cho \u1ea5m. Lang thang thi c\u00e1i cu\u1ed9c thi l\u1eadp tr\u00ecnh c\u1ee7a b\u1ecdn Top Career g\u00ec \u0111\u00f3 :v v\u00f4 t\u00ecnh v\u1ea5p ph\u1ea3i 1 b\u00e0i test demo, m\u00e0 m\u00ecnh th\u1ea5y kh\u00e1 hay, n\u00ean mu\u1ed1n chia s\u1ebb l\u00ean \u0111\u00e2y cho c\u1ea3 nh\u00e0 \u0110\u1ec1 b\u00e0i: A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 \u2264 P &lt; N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e. A[0] + A[1] + ... + A[P\u22121] = A[P+1] + ... + A[N\u22122] + A[N\u22121]. Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N\u22121. For example, consider the following array A consisting of N = 8 elements: A[0] = -1 A[1] = 3 A[2] = -4 A[3] = 5 A[4] = 1 A[5] = -6 A[6] = 2 A[7] = 1 P = 1 is an equilibrium index of this array, because: A[0] = \u22121 = A[2] + A[3] + A[4] + A[5] + A[6] + A[7] P = 3 is an equilibrium index of this array, because: A[0] + A[1] + A[2] = \u22122 = A[4] + A[5] + A[6] + A[7] P = 7 is also an equilibrium index, because: A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] = 0 and there are no elements with indices greater than 7. P = 8 is not an equilibrium index, because it does not fulfill the condition 0 \u2264 P &lt; N. Write a function: function solution($A); that, given a zero-indexed array A consisting of N integers, returns any of its equilibrium indices. The function should return \u22121 if no equilibrium index exists. For example, given array A shown above, the function may return 1, 3 or 7, as explained above. Assume that: N is an integer within the range [0..100,000]; each element of array A is an integer within the range [\u22122,147,483,648..2,147,483,647]. Complexity: expected worst-case time complexity is O(N); expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments). Elements of input arrays can be modified. D\u1ecbch \u0111\u1ea1i kh\u00e1i l\u00e0: Ta c\u00f3 1 indexed array A g\u1ed3m N ph\u1ea7n t\u1eed l\u00e0 c\u00e1c s\u1ed1 t\u1ef1 nhi\u00ean b\u1ea5t k\u1ef3. T\u00ecm ch\u1ec9 s\u1ed1 c\u00e2n b\u1eb1ng P sao cho P l\u00e0 - Key c\u1ee7a array A - Th\u1ecfa m\u00e3n \u0111i\u1ec1u ki\u1ec7n: A[0] + A[1] + ... + A[P\u22121] = A[P+1] + ... + A[N\u22122] + A[N\u22121]. - P = 0 ho\u1eb7c P= N-1 \u0111\u1ec1u c\u00f3 th\u1ec3 l\u00e0 gi\u00e1 tr\u1ecb \u0111\u00fang - C\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u ho\u1eb7c 1 gi\u00e1 tr\u1ecb P - N\u1ebfu kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb n\u00e0o, function c\u1ea7n return -1 C\u00e1c \u0111i\u1ec1u ki\u1ec7n v\u1ec1 complexity, assumption m\u1eddi xem ph\u1ea7n ti\u1ebfng Anh nh\u00e9, l\u01b0\u1eddi d\u1ecbch :D R\u1ed3i, \u0111\u1ec1 b\u00e0i l\u00e0 nh\u01b0 v\u1eady, y\u00eau c\u1ea7u vi\u1ebft 1 function d\u01b0\u1edbi ng\u00f4n ng\u1eef n\u00e0o c\u0169ng \u0111\u01b0\u1ee3c, th\u1eddi gian l\u00e0m b\u00e0i l\u00e0\u00a030 ph\u00fat. GI\u1ea2I (\u0110\u00e2y l\u00e0 c\u00e1ch gi\u1ea3i c\u1ee7a m\u00ecnh, ai c\u00f3 c\u00e1ch n\u00e0o hay h\u01a1n th\u00ec comment nh\u00e9 ) H\u01b0\u1edbng gi\u1ea3i c\u1ee7a m\u00ecnh l\u00e0 s\u1ebd chia m\u1ea3ng 1 chi\u1ec1u n\u00e0y th\u00e0nh 2 ph\u1ea7n, T\u1ed5ng\u00a0Tr\u00e1i\u00a0v\u00e0 T\u1ed5ng\u00a0Ph\u1ea3i. Sau \u0111\u00f3 ch\u1ea1y d\u1ea7n t\u1eeb tr\u00e1i qua ph\u1ea3i c\u1ee7a m\u1ea3ng v\u00e0 so s\u00e1nh 2 t\u1ed5ng n\u00e0y v\u1edbi nhau. EZPZ ph\u1ea3i kh\u00f4ng? :)) M\u00ecnh code PHP nh\u00e9, \u0111\u1ea7u ti\u00ean g\u00e1n gi\u00e1 tr\u1ecb default ph\u00e1t\u00a0(th\u00f3i quen th\u00f4i, PHP kh\u00f4ng c\u1ea7n initialize bi\u1ebfn) function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = -1; } \/\/$A l\u00e0 arrray nh\u1eadp v\u00e0o \/\/$equi l\u00e0 s\u1ed1 P c\u1ea7n t\u00ecm R\u1ed3i, b\u00e2y gi\u1edd l\u1eb7p qua c\u00e1i array A xem sao nh\u1ec9? function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = \u20131; for ($index = 0; $index &lt; count($A); $index++) { \/\/So s\u00e1nh $sumLeft v\u1edbi $sumRight trong n\u00e0y \/\/M\u00ecnh d\u00f9ng for thay v\u00ec foreach do l\u00fd do performance } return $equi; } B\u1eaft \u0111\u1ea7u so s\u00e1nh, v\u00e0 ph\u1ea3i tr\u1eeb d\u1ea7n\u00a0$sumRight\u00a0 t\u0103ng d\u1ea7n\u00a0$sumLeft\u00a0v\u1edbi gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed7i element function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = \u20131; for ($index = 0; $index &lt; count($A); $index++) { $tempRight = $sumRight \u2013 $A&#x5B;$index]; if ($sumLeft === $tempRight) { $equi = $index; return $equi; } else { $sumLeft += $A&#x5B;$index]; $sumRight = $tempRight; } } return $equi; } Tr\u00f4ng c\u00f3 v\u1ebb \u1ed5n \u1ed5n r\u1ed3i \u0111\u1ea5y nh\u1ec9 :)) Nh\u01b0ng th\u1ef1c ra l\u00e0 \u0111\u1ebfch \u1ed5n, m\u00ecnh c\u00f2n ch\u01b0a check null c\u01a1 m\u00e0 =)) c\u00e1i c\u01a1 b\u1ea3n nh\u1ea5t c\u00f2n su\u1ed1t ng\u00e0y qu\u00ean \u0111\u00e2y function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = \u20131; if (count($A)) { for ($index = 0; $index &lt; count($A); $index++) { $tempRight = $sumRight \u2013 $A&#x5B;$index]; if ($sumLeft === $tempRight) { $equi = $index; return $equi; } $sumLeft += $A&#x5B;$index]; $sumRight = $tempRight; } return $equi; } return \u20131; } Ok done! N\u00e0o, b\u00e2y gi\u1edd test th\u00f4i! echo demo(&#x5B;4, 35, 80, 123, 12345, 44, 8, 5, 24, 3]); Chu\u1ea9n \u0111\u00e9t :)) Test th\u1eed v\u1edbi d\u1eef li\u1ec7u\u00a0kh\u00e1c xem sao echo demo(&#x5B;-1, 3, -4, 5, 1, -6, 2, 1]); Done! Hy v\u1ecdng anh em gi\u1ea3i to\u00e1n vui v\u1ebb :)) c\u00f3 solution n\u00e0o ngon h\u01a1n nh\u1edb comment -_- \u0111\u1eebng c\u00f3 \u00e9m h\u00e0ng\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dangnh.cf\/vi\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/\" \/>\n<meta property=\"og:site_name\" content=\"Mark&#039;s Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/dangtute\" \/>\n<meta property=\"article:published_time\" content=\"2017-05-19T03:45:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-02T05:01:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"513\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 ph\u00fat\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#\\\/schema\\\/person\\\/8f3b9db3b250186af217fbeec88eda9c\"},\"headline\":\"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9?\",\"datePublished\":\"2017-05-19T03:45:45+00:00\",\"dateModified\":\"2018-01-02T05:01:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/\"},\"wordCount\":580,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/dangnh.cf\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1\",\"articleSection\":[\"PHP\"],\"inLanguage\":\"vi\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/\",\"url\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/\",\"name\":\"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9? - Mark's Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/dangnh.cf\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1\",\"datePublished\":\"2017-05-19T03:45:45+00:00\",\"dateModified\":\"2018-01-02T05:01:53+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#\\\/schema\\\/person\\\/8f3b9db3b250186af217fbeec88eda9c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/#breadcrumb\"},\"inLanguage\":\"vi\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"vi\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/dangnh.cf\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/dangnh.cf\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1\",\"width\":800,\"height\":513,\"caption\":\"93b10235-a169-4375-b8f5-f5a95450d258\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2017\\\/05\\\/19\\\/lam-toan-giai-tri-mot-ti-nhi\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/dangnh.cf\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#website\",\"url\":\"https:\\\/\\\/dangnh.cf\\\/\",\"name\":\"Mark's Blog\",\"description\":\"A blog about Programming and Technical Stuffs\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/dangnh.cf\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"vi\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#\\\/schema\\\/person\\\/8f3b9db3b250186af217fbeec88eda9c\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"vi\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g\",\"caption\":\"admin\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9? - Mark's Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dangnh.cf\/vi\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/","og_locale":"vi_VN","og_type":"article","og_title":"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9? - Mark's Blog","og_description":"Ok, ch\u00e0o t\u1ea5t c\u1ea3 anh em Ch\u1ea3 l\u00e0 cu\u1ed1i tu\u1ea7n, \u1edf nh\u00e0 r\u1ea3nh rang, tr\u1eddi th\u00ec se se l\u1ea1nh, m\u0169i h\u01a1i t\u1eafc, ch\u1ec9 mu\u1ed1n co ro qu\u1ea5n ch\u0103n \u00f4m laptop cho \u1ea5m. Lang thang thi c\u00e1i cu\u1ed9c thi l\u1eadp tr\u00ecnh c\u1ee7a b\u1ecdn Top Career g\u00ec \u0111\u00f3 :v v\u00f4 t\u00ecnh v\u1ea5p ph\u1ea3i 1 b\u00e0i test demo, m\u00e0 m\u00ecnh th\u1ea5y kh\u00e1 hay, n\u00ean mu\u1ed1n chia s\u1ebb l\u00ean \u0111\u00e2y cho c\u1ea3 nh\u00e0 \u0110\u1ec1 b\u00e0i: A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 \u2264 P &lt; N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e. A[0] + A[1] + ... + A[P\u22121] = A[P+1] + ... + A[N\u22122] + A[N\u22121]. Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N\u22121. For example, consider the following array A consisting of N = 8 elements: A[0] = -1 A[1] = 3 A[2] = -4 A[3] = 5 A[4] = 1 A[5] = -6 A[6] = 2 A[7] = 1 P = 1 is an equilibrium index of this array, because: A[0] = \u22121 = A[2] + A[3] + A[4] + A[5] + A[6] + A[7] P = 3 is an equilibrium index of this array, because: A[0] + A[1] + A[2] = \u22122 = A[4] + A[5] + A[6] + A[7] P = 7 is also an equilibrium index, because: A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] = 0 and there are no elements with indices greater than 7. P = 8 is not an equilibrium index, because it does not fulfill the condition 0 \u2264 P &lt; N. Write a function: function solution($A); that, given a zero-indexed array A consisting of N integers, returns any of its equilibrium indices. The function should return \u22121 if no equilibrium index exists. For example, given array A shown above, the function may return 1, 3 or 7, as explained above. Assume that: N is an integer within the range [0..100,000]; each element of array A is an integer within the range [\u22122,147,483,648..2,147,483,647]. Complexity: expected worst-case time complexity is O(N); expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments). Elements of input arrays can be modified. D\u1ecbch \u0111\u1ea1i kh\u00e1i l\u00e0: Ta c\u00f3 1 indexed array A g\u1ed3m N ph\u1ea7n t\u1eed l\u00e0 c\u00e1c s\u1ed1 t\u1ef1 nhi\u00ean b\u1ea5t k\u1ef3. T\u00ecm ch\u1ec9 s\u1ed1 c\u00e2n b\u1eb1ng P sao cho P l\u00e0 - Key c\u1ee7a array A - Th\u1ecfa m\u00e3n \u0111i\u1ec1u ki\u1ec7n: A[0] + A[1] + ... + A[P\u22121] = A[P+1] + ... + A[N\u22122] + A[N\u22121]. - P = 0 ho\u1eb7c P= N-1 \u0111\u1ec1u c\u00f3 th\u1ec3 l\u00e0 gi\u00e1 tr\u1ecb \u0111\u00fang - C\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u ho\u1eb7c 1 gi\u00e1 tr\u1ecb P - N\u1ebfu kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb n\u00e0o, function c\u1ea7n return -1 C\u00e1c \u0111i\u1ec1u ki\u1ec7n v\u1ec1 complexity, assumption m\u1eddi xem ph\u1ea7n ti\u1ebfng Anh nh\u00e9, l\u01b0\u1eddi d\u1ecbch :D R\u1ed3i, \u0111\u1ec1 b\u00e0i l\u00e0 nh\u01b0 v\u1eady, y\u00eau c\u1ea7u vi\u1ebft 1 function d\u01b0\u1edbi ng\u00f4n ng\u1eef n\u00e0o c\u0169ng \u0111\u01b0\u1ee3c, th\u1eddi gian l\u00e0m b\u00e0i l\u00e0\u00a030 ph\u00fat. GI\u1ea2I (\u0110\u00e2y l\u00e0 c\u00e1ch gi\u1ea3i c\u1ee7a m\u00ecnh, ai c\u00f3 c\u00e1ch n\u00e0o hay h\u01a1n th\u00ec comment nh\u00e9 ) H\u01b0\u1edbng gi\u1ea3i c\u1ee7a m\u00ecnh l\u00e0 s\u1ebd chia m\u1ea3ng 1 chi\u1ec1u n\u00e0y th\u00e0nh 2 ph\u1ea7n, T\u1ed5ng\u00a0Tr\u00e1i\u00a0v\u00e0 T\u1ed5ng\u00a0Ph\u1ea3i. Sau \u0111\u00f3 ch\u1ea1y d\u1ea7n t\u1eeb tr\u00e1i qua ph\u1ea3i c\u1ee7a m\u1ea3ng v\u00e0 so s\u00e1nh 2 t\u1ed5ng n\u00e0y v\u1edbi nhau. EZPZ ph\u1ea3i kh\u00f4ng? :)) M\u00ecnh code PHP nh\u00e9, \u0111\u1ea7u ti\u00ean g\u00e1n gi\u00e1 tr\u1ecb default ph\u00e1t\u00a0(th\u00f3i quen th\u00f4i, PHP kh\u00f4ng c\u1ea7n initialize bi\u1ebfn) function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = -1; } \/\/$A l\u00e0 arrray nh\u1eadp v\u00e0o \/\/$equi l\u00e0 s\u1ed1 P c\u1ea7n t\u00ecm R\u1ed3i, b\u00e2y gi\u1edd l\u1eb7p qua c\u00e1i array A xem sao nh\u1ec9? function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = \u20131; for ($index = 0; $index &lt; count($A); $index++) { \/\/So s\u00e1nh $sumLeft v\u1edbi $sumRight trong n\u00e0y \/\/M\u00ecnh d\u00f9ng for thay v\u00ec foreach do l\u00fd do performance } return $equi; } B\u1eaft \u0111\u1ea7u so s\u00e1nh, v\u00e0 ph\u1ea3i tr\u1eeb d\u1ea7n\u00a0$sumRight\u00a0 t\u0103ng d\u1ea7n\u00a0$sumLeft\u00a0v\u1edbi gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed7i element function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = \u20131; for ($index = 0; $index &lt; count($A); $index++) { $tempRight = $sumRight \u2013 $A&#x5B;$index]; if ($sumLeft === $tempRight) { $equi = $index; return $equi; } else { $sumLeft += $A&#x5B;$index]; $sumRight = $tempRight; } } return $equi; } Tr\u00f4ng c\u00f3 v\u1ebb \u1ed5n \u1ed5n r\u1ed3i \u0111\u1ea5y nh\u1ec9 :)) Nh\u01b0ng th\u1ef1c ra l\u00e0 \u0111\u1ebfch \u1ed5n, m\u00ecnh c\u00f2n ch\u01b0a check null c\u01a1 m\u00e0 =)) c\u00e1i c\u01a1 b\u1ea3n nh\u1ea5t c\u00f2n su\u1ed1t ng\u00e0y qu\u00ean \u0111\u00e2y function ($A) { $sumLeft = 0; $sumRight = array_sum($A); $equi = \u20131; if (count($A)) { for ($index = 0; $index &lt; count($A); $index++) { $tempRight = $sumRight \u2013 $A&#x5B;$index]; if ($sumLeft === $tempRight) { $equi = $index; return $equi; } $sumLeft += $A&#x5B;$index]; $sumRight = $tempRight; } return $equi; } return \u20131; } Ok done! N\u00e0o, b\u00e2y gi\u1edd test th\u00f4i! echo demo(&#x5B;4, 35, 80, 123, 12345, 44, 8, 5, 24, 3]); Chu\u1ea9n \u0111\u00e9t :)) Test th\u1eed v\u1edbi d\u1eef li\u1ec7u\u00a0kh\u00e1c xem sao echo demo(&#x5B;-1, 3, -4, 5, 1, -6, 2, 1]); Done! Hy v\u1ecdng anh em gi\u1ea3i to\u00e1n vui v\u1ebb :)) c\u00f3 solution n\u00e0o ngon h\u01a1n nh\u1edb comment -_- \u0111\u1eebng c\u00f3 \u00e9m h\u00e0ng","og_url":"https:\/\/dangnh.cf\/vi\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/","og_site_name":"Mark's Blog","article_publisher":"https:\/\/www.facebook.com\/dangtute","article_published_time":"2017-05-19T03:45:45+00:00","article_modified_time":"2018-01-02T05:01:53+00:00","og_image":[{"width":800,"height":513,"url":"https:\/\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"admin","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"5 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/#article","isPartOf":{"@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/"},"author":{"name":"admin","@id":"https:\/\/dangnh.cf\/#\/schema\/person\/8f3b9db3b250186af217fbeec88eda9c"},"headline":"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9?","datePublished":"2017-05-19T03:45:45+00:00","dateModified":"2018-01-02T05:01:53+00:00","mainEntityOfPage":{"@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/"},"wordCount":580,"commentCount":0,"image":{"@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1","articleSection":["PHP"],"inLanguage":"vi","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/","url":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/","name":"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9? - Mark's Blog","isPartOf":{"@id":"https:\/\/dangnh.cf\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/#primaryimage"},"image":{"@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1","datePublished":"2017-05-19T03:45:45+00:00","dateModified":"2018-01-02T05:01:53+00:00","author":{"@id":"https:\/\/dangnh.cf\/#\/schema\/person\/8f3b9db3b250186af217fbeec88eda9c"},"breadcrumb":{"@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/#primaryimage","url":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1","contentUrl":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1","width":800,"height":513,"caption":"93b10235-a169-4375-b8f5-f5a95450d258"},{"@type":"BreadcrumbList","@id":"https:\/\/dangnh.cf\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dangnh.cf\/"},{"@type":"ListItem","position":2,"name":"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9?"}]},{"@type":"WebSite","@id":"https:\/\/dangnh.cf\/#website","url":"https:\/\/dangnh.cf\/","name":"Mark's Blog","description":"A blog about Programming and Technical Stuffs","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dangnh.cf\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Person","@id":"https:\/\/dangnh.cf\/#\/schema\/person\/8f3b9db3b250186af217fbeec88eda9c","name":"admin","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/secure.gravatar.com\/avatar\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g","caption":"admin"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9w3NP-14","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":441,"url":"https:\/\/dangnh.cf\/vi\/2025\/06\/06\/rag-la-gi-va-tai-sao-may-ong-ai-cu-nhac-hoai\/","url_meta":{"origin":66,"position":0},"title":"RAG l\u00e0 g\u00ec? V\u00e0 t\u1ea1i sao m\u1ea5y \u00f4ng AI c\u1ee9 nh\u1eafc ho\u00e0i?","author":"admin","date":"Th\u00e1ng 6 6, 2025","format":false,"excerpt":"RAG \u2013 vi\u1ebft t\u1eaft c\u1ee7a \u201cRetrieval-Augmented Generation\u201d \u2013 nghe th\u00ec c\u00f3 v\u1ebb ng\u1ea7u, nh\u01b0ng th\u1ef1c ra hi\u1ec3u \u0111\u01a1n gi\u1ea3n th\u00ec n\u00f3 l\u00e0 m\u1ed9t c\u00e1ch gi\u00fap m\u1ea5y con AI\u2026 \u0111\u1ee1 ngu h\u01a1n khi tr\u1ea3 l\u1eddi c\u00e2u h\u1ecfi. N\u1ebfu b\u1ea1n \u0111\u00e3 s\u1eed d\u1ee5ng AI cho c\u00f4ng vi\u1ec7c chuy\u00ean m\u00f4n, ch\u1eafc ch\u1eafn c\u00f3\u2026","rel":"","context":"Trong &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/dangnh.cf\/vi\/category\/ai\/"},"img":{"alt_text":"RAG trong AI","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":211,"url":"https:\/\/dangnh.cf\/vi\/2018\/06\/01\/trait-mixin-in-php\/","url_meta":{"origin":66,"position":1},"title":"Trait &#8211; Mixin in PHP?","author":"admin","date":"Th\u00e1ng 6 1, 2018","format":false,"excerpt":"Hi guys :) Nh\u01b0 c\u00e1c b\u1ea1n c\u00f3 l\u1ebd \u0111\u00e3 bi\u1ebft, PHP l\u00e0 1 ng\u00f4n ng\u1eef single inheritance, t\u1ee9c l\u00e0 n\u00f3 s\u1ebd c\u00f3 1 s\u1ed1 nh\u01b0\u1ee3c \u0111i\u1ec3m nh\u01b0: M\u1ea5t th\u1eddi gian & c\u00f4ng s\u1ee9c khi t\u00ecm hi\u1ec3u\/ch\u1ea1y h\u1ec7 th\u1ed1ng. V\u00ed d\u1ee5: 1 class c\u00f3 10 levels c\u00e1c class cha, th\u00ec v\u1ec1\u2026","rel":"","context":"Trong &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/dangnh.cf\/vi\/category\/web-development\/php\/"},"img":{"alt_text":"Trait in PHP","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":367,"url":"https:\/\/dangnh.cf\/vi\/2020\/01\/20\/service-container-di-sanh-dieu-voi-laravel\/","url_meta":{"origin":66,"position":2},"title":"Service Container &#038; DI &#8220;s\u00e0nh \u0111i\u1ec7u&#8221; v\u1edbi Laravel","author":"admin","date":"Th\u00e1ng 1 20, 2020","format":false,"excerpt":"Hi, long time no see :D Laravel l\u00e0 m\u1ed9t framework n\u1ed5i ti\u1ebfng nh\u1ea5t trong c\u1ed9ng \u0111\u1ed3ng PHP, 1 ph\u1ea7n l\u00e0 v\u00ec c\u1ea5u tr\u00fac tuy\u1ec7t v\u1eddi c\u1ee7a n\u00f3. Khi n\u00f3i \u0111\u1ebfn architectural concepts c\u1ee7a Laravel, kh\u00f4ng th\u1ec3 kh\u00f4ng nh\u1eafc t\u1edbi Service Container. Khi b\u1ea1n \u0111\u1ee5ng \u0111\u1ebfn 1 b\u00e0i to\u00e1n l\u1edbn h\u01a1n,\u2026","rel":"","context":"Trong &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/dangnh.cf\/vi\/category\/web-development\/php\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2020\/01\/1_SstfI6yiEWj1mrnFrLTUdA-e1579505803935.jpeg?fit=900%2C600&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2020\/01\/1_SstfI6yiEWj1mrnFrLTUdA-e1579505803935.jpeg?fit=900%2C600&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2020\/01\/1_SstfI6yiEWj1mrnFrLTUdA-e1579505803935.jpeg?fit=900%2C600&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2020\/01\/1_SstfI6yiEWj1mrnFrLTUdA-e1579505803935.jpeg?fit=900%2C600&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":473,"url":"https:\/\/dangnh.cf\/vi\/2025\/11\/05\/ban-dung-cho-developer\/","url_meta":{"origin":66,"position":3},"title":"Standing desk &#8211; V\u1eadt trang tr\u00ed \u0111\u1eaft ti\u1ec1n hay m\u1eb9o hack productivity?","author":"admin","date":"Th\u00e1ng m\u01b0\u1eddi m\u1ed9t 5, 2025","format":false,"excerpt":"Mua c\u00e1i b\u00e0n \u0111\u1ee9ng - standing desk, t\u00f4i t\u01b0\u1edfng m\u00ecnh s\u1ebd th\u00e0nh si\u00eau nh\u00e2n. Ng\u01b0\u1eddi ta qu\u1ea3ng c\u00e1o b\u1ea3o \u0111\u1ee9ng l\u00e0m vi\u1ec7c s\u1ebd t\u1eadp trung h\u01a1n, kh\u1ecfe l\u01b0ng h\u01a1n, code s\u01b0\u1edbng h\u01a1n. C\u00f2n th\u1ef1c t\u1ebf th\u00ec... N\u00f3 th\u00e0nh c\u00e1i c\u1edb ho\u00e0n h\u1ea3o \u0111\u1ec3... kh\u00f4ng ng\u1ed3i y\u00ean. L\u00fac code \u0111\u01b0\u1ee3c, t\u00f4i\u2026","rel":"","context":"Trong \"productivity hack\"","block_context":{"text":"productivity hack","link":"https:\/\/dangnh.cf\/vi\/tag\/productivity-hack\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/11\/image-1.png?fit=800%2C1200&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/11\/image-1.png?fit=800%2C1200&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/11\/image-1.png?fit=800%2C1200&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/11\/image-1.png?fit=800%2C1200&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":124,"url":"https:\/\/dangnh.cf\/vi\/2017\/05\/25\/stdclass-la-gi-lam-the-nao-de-co-properties-dong-trong-php\/","url_meta":{"origin":66,"position":4},"title":"stdClass l\u00e0 g\u00ec? L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 c\u00f3 Dynamic Properties trong PHP?","author":"admin","date":"Th\u00e1ng 5 25, 2017","format":false,"excerpt":"Ch\u00e0o c\u00e1c b\u1ea1n, m\u00ecnh l\u00e0 \u0110\u0103ng, v\u00e0 m\u00ecnh \u0111\u00e3 tr\u1edf l\u1ea1i r\u1ed3i \u0111\u00e2yy\u00a0 N\u1ebfu b\u1ea1n l\u00e0 1 ng\u01b0\u1eddi r\u1ea5t hay t\u00f2 m\u00f2 ngh\u1ecbch ng\u1ee3m, gi\u1ed1ng t\u00f4i, th\u00ec ch\u1eafc h\u1eb3n b\u1ea1n \u0111\u00e3 t\u1eebng lang thang trong core c\u1ee7a m\u1ea5y th\u1eb1ng PHP framework nh\u01b0 Laravel hay Yii, v\u00e0 ch\u1eafc cmn c\u00fa l\u00e0\u2026","rel":"","context":"Trong &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/dangnh.cf\/vi\/category\/web-development\/php\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/stdclass-trong-php.png?fit=365%2C268&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":409,"url":"https:\/\/dangnh.cf\/vi\/2025\/05\/19\/huong-dan-setup-ai-blog-to-podcast-agent\/","url_meta":{"origin":66,"position":5},"title":"H\u01b0\u1edbng D\u1eabn Setup AI Blog to Podcast Agent","author":"admin","date":"Th\u00e1ng 5 19, 2025","format":false,"excerpt":"D\u01b0\u1edbi \u0111\u00e2y l\u00e0 b\u00e0i vi\u1ebft gi\u1edbi thi\u1ec7u nhanh v\u1ec1 repo Awesome LLM Apps v\u00e0 h\u01b0\u1edbng d\u1eabn ch\u1ea1y th\u1eed \u201cAI Blog to Podcast Agent\u201d tr\u00ean m\u00e1y Mac c\u1ee7a b\u1ea1n. M\u00ecnh s\u1ebd l\u1ea7n l\u01b0\u1ee3t \u0111i qua: Gi\u1edbi thi\u1ec7u chung v\u1ec1 repo T\u1ea1i sao n\u00ean kh\u00e1m ph\u00e1 \u0110i\u1ec3m nh\u1ea5n \u201cAI Blog to Podcast\u2026","rel":"","context":"Trong &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/dangnh.cf\/vi\/category\/ai\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/05\/ai-agent.png?fit=1024%2C1024&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/05\/ai-agent.png?fit=1024%2C1024&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/05\/ai-agent.png?fit=1024%2C1024&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/05\/ai-agent.png?fit=1024%2C1024&ssl=1&resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":5,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":267,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts\/66\/revisions\/267"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/media\/110"}],"wp:attachment":[{"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}