<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
      <title>mark@usegitflow</title>
      <link>https://usegitflow.com</link>
      <description>Mark&#x27;s homepage on the Internet.</description>
      <generator>Zola</generator>
      <language>en</language>
      <atom:link href="https://usegitflow.com/rss.xml" rel="self" type="application/rss+xml"/>
      <lastBuildDate>Sun, 05 Jul 2026 00:00:00 +0000</lastBuildDate>
      <item>
          <title>Write the rule, not just the fix, so Claude can follow it</title>
          <pubDate>Sun, 05 Jul 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/write-the-rule-not-just-the-fix/</link>
          <guid>https://usegitflow.com/posts/write-the-rule-not-just-the-fix/</guid>
          <description xml:base="https://usegitflow.com/posts/write-the-rule-not-just-the-fix/">&lt;p&gt;I recently asked Claude to look back over how I work and tell me what, if
anything, was worth keeping. It returned a tidy list of habits. Most of them were
tangled up with specific projects I cannot write about here, but one stood out
because it had nothing to do with any particular job. It is the only one I would
defend as genuinely portable, and it is boring in the best way: I write down what
I learn, and then I maintain it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;capture-the-lesson&quot;&gt;Capture the lesson&lt;&#x2F;h2&gt;
&lt;p&gt;Every engineer solves the same class of problem more than once. The only question
that matters is whether the second time is cheaper than the first. Most of us fix
a bug, feel the small relief, and move on, only to meet its cousin six months
later and solve it from scratch.&lt;&#x2F;p&gt;
&lt;p&gt;What I try to do instead is spend the extra two minutes to record not the fix but
the lesson. A good note captures three things:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;the shape of the mistake, not just this one instance&lt;&#x2F;li&gt;
&lt;li&gt;the date it cost me something, so I know when it might be going stale&lt;&#x2F;li&gt;
&lt;li&gt;the rule that would have prevented it&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;A fix solves one case. A rule closes a category. Over a few years the notes stop
being a list of solved problems and become a compressed version of my own
judgement, one I can reread, hand to a colleague or point an agent at.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;from-notes-to-instructions&quot;&gt;From notes to instructions&lt;&#x2F;h2&gt;
&lt;p&gt;This habit used to be mostly for me. Lately it has quietly changed shape. When
you work with coding agents, a well written rule is no longer just a private
reminder. It becomes an instruction you can delegate against. “Never do X without
first checking Y” stops being a note to self and turns into a guardrail the
machine will actually respect. The clearer the rule, the more autonomy you can
safely hand over. I did not expect my scruffy pile of lessons to become the
interface for delegation, but that is more or less what happened.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-trap&quot;&gt;The trap&lt;&#x2F;h2&gt;
&lt;p&gt;There is a catch, and it took me a while to see it. A system built entirely from
“this burned me, never again” is optimised against your past, and two things
follow. Rules quietly go stale, so the real work is not writing them but retiring
the ones that no longer hold. And a growing collection of “never again” slowly
makes you conservative. Guardrails are very good at preventing disasters and no
good at all at finding the next opportunity. So I now try to spend as much effort
pruning old rules as adding new ones, and to remember that not every lesson
deserves to become a law.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-actually-compounds&quot;&gt;What actually compounds&lt;&#x2F;h2&gt;
&lt;p&gt;The thing I would carry into any project is not the notes themselves. It is the
discipline behind them. Treat what you learn as an asset worth maintaining, write
it in a form someone else could use, and stay as willing to delete a rule as to
write one. The notes are only where that discipline leaves a mark.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>How I use Superpowers for engineering work</title>
          <pubDate>Thu, 14 May 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/superpowers/</link>
          <guid>https://usegitflow.com/posts/superpowers/</guid>
          <description xml:base="https://usegitflow.com/posts/superpowers/">&lt;p&gt;I have spent a lot of hours with coding agents, and for a while the experience
was split down the middle. Half the time I got something useful in minutes. The
other half, the agent set off confidently in the wrong direction, and I spent
longer untangling its work than if I had written the thing myself. Superpowers,
an open source plugin by Jesse Vincent (obra), is the first tool that reliably
fixed the second half for me.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-it-actually-is&quot;&gt;What it actually is&lt;&#x2F;h2&gt;
&lt;p&gt;The idea is refreshingly plain. Superpowers is a library of skills, which are
ordinary Markdown files that teach the agent how to do something and then insist
that it does. There is no clever trick underneath. A skill fires at the right
moment and walks the agent through a workflow that a careful engineer would
recognise.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-workflow-it-enforces&quot;&gt;The workflow it enforces&lt;&#x2F;h2&gt;
&lt;p&gt;Strung together, the skills follow the discipline I wish I always kept myself.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Brainstorm first.&lt;&#x2F;strong&gt; It refuses to write code until it understands what I am
really trying to build, then returns the spec in pieces short enough to read.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Plan.&lt;&#x2F;strong&gt; It turns that spec into steps concrete enough for a junior with no
context to follow.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Test first.&lt;&#x2F;strong&gt; Real red then green: write the failing test, write the least
code that passes, commit. YAGNI and DRY throughout.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Delegate to subagents.&lt;&#x2F;strong&gt; Independent tasks go to fresh agents in their own
git worktrees, with a review between stages so a long run does not drift.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Review before merge.&lt;&#x2F;strong&gt; A final pass checks the work against the spec before
anything lands.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;the-honest-trade&quot;&gt;The honest trade&lt;&#x2F;h2&gt;
&lt;p&gt;It is slower to the first line of code. You give up the small thrill of an
instant draft in return for far fewer wrong turns, which is a trade I would make
anyway and one I keep failing to make on my own. In practice it feels less like
prompting and more like pairing with someone who has better habits than me.&lt;&#x2F;p&gt;
&lt;p&gt;The part I keep thinking about is that the skills are just Markdown. You can read
them, fork them, and the system can even mine your past sessions to write new
ones. It is rare to find a tool that gets better the more you teach it.&lt;&#x2F;p&gt;
&lt;p&gt;Worth a look if agents are part of your day: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;obra&#x2F;superpowers&quot;&gt;obra&#x2F;superpowers&lt;&#x2F;a&gt;,
and Jesse’s own &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;blog.fsck.com&#x2F;2025&#x2F;10&#x2F;09&#x2F;superpowers&#x2F;&quot;&gt;post&lt;&#x2F;a&gt; on the
thinking behind it.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>战争与和平</title>
          <pubDate>Tue, 24 Feb 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/war-and-peace/</link>
          <guid>https://usegitflow.com/posts/war-and-peace/</guid>
          <description xml:base="https://usegitflow.com/posts/war-and-peace/">&lt;p&gt;Book link: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;zh.wikipedia.org&#x2F;wiki&#x2F;%E6%88%98%E4%BA%89%E4%B8%8E%E5%92%8C%E5%B9%B3&quot;&gt;战争与和平&lt;&#x2F;a&gt;, &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;War_and_Peace&quot;&gt;War and Peace&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;托尔斯泰写了五百多个人物、一整个时代的战争与和平，最后想说的却是一件很小的事：一个人到底能不能主宰自己的一生。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;li-shi-li-mei-you-zhu-jiao&quot;&gt;历史里没有主角&lt;&#x2F;h3&gt;
&lt;p&gt;拿破仑以为是自己在指挥千军万马，托尔斯泰却说，他不过是被历史推着走的一个人，和最末排的士兵没有本质区别。真正推动历史的，不是某个伟人的意志，而是无数普通人各自微小选择的总和。每个人都以为自己在自由地行动，合在一起却汇成了谁也没有设计过的洪流。&lt;&#x2F;p&gt;
&lt;p&gt;这是全书最锋利的地方：它把英雄从神坛上请了下来，告诉你所谓的时代大势，其实是由许许多多像你我一样看不清全局的人共同写成的。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;an-de-lie-de-tian-kong&quot;&gt;安德烈的天空&lt;&#x2F;h3&gt;
&lt;p&gt;安德烈公爵一心想建功立业，把拿破仑当成偶像。直到他在奥斯特里茨战场上负伤倒地，抬头看见那片高远宁静的天空，才忽然觉得从前追逐的荣耀都轻得可笑。头顶的云还是那样慢慢地飘，仿佛在提醒他，人所看重的许多东西，放到足够远的地方去看，都算不得什么。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;pi-ai-er-de-xun-zhao&quot;&gt;皮埃尔的寻找&lt;&#x2F;h3&gt;
&lt;p&gt;皮埃尔几乎试遍了所有寻找意义的路：继承巨额财产、投身共济会、旁观战争、又在被俘中跌到谷底。最后教会他的，不是哪一套宏大的道理，而是同为战俘的农民卡拉塔耶夫，一个安于当下、把日子本身过成答案的人。托尔斯泰借他说出一件朴素的事：活着的意义，也许不在远方的理想里，而在能不能诚实地过好眼前这一天。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;yi-dian-xiang-fa&quot;&gt;一点想法&lt;&#x2F;h3&gt;
&lt;p&gt;读这本书最打动我的，不是那些战争场面，而是托尔斯泰对普通生活的耐心。他愿意花上百页去写一场舞会、一次打猎、一家人围坐的晚饭，好像在说：真正的历史不在战报里，而在这些看似无关紧要的日常中。合上书之后我常想，我们总盼着做点了不起的大事，却容易忘了，把平凡的一天认真过完，本身已经很不容易。&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“We can know only that we know nothing. And that is the highest degree of human wisdom.”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;“The strongest of all warriors are these two — Time and Patience.”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;“If everyone fought for their own convictions there would be no war.”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;“Seize the moments of happiness, love and be loved! That is the only reality in the world, all else is folly. It is the one thing we are interested in here.”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
</description>
      </item>
      <item>
          <title>What I learned from The Art of SEO</title>
          <pubDate>Thu, 18 Sep 2025 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/art-of-seo/</link>
          <guid>https://usegitflow.com/posts/art-of-seo/</guid>
          <description xml:base="https://usegitflow.com/posts/art-of-seo/">&lt;p&gt;The Art of SEO is a doorstop of a book, close to a thousand pages, and I opened
it expecting a bag of keyword tricks. What I found was closer to plain
engineering advice. These are the ideas that stayed with me, along with a few
thoughts on where search is heading.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;seo-is-architecture-not-decoration&quot;&gt;SEO is architecture, not decoration&lt;&#x2F;h2&gt;
&lt;p&gt;The central point of the book is that search optimisation is not something you
sprinkle on at the end. It is architecture. If a crawler cannot reach a page,
render it, or make sense of it, nothing else matters. Clean URLs, a clear
sitemap, a sensible hierarchy and honest internal links are the same things that
make a site easy for a person to use. The closest thing to a trick is to build a
fast, well organised site that answers a real question, which is what you would
want to build anyway.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-ideas-that-stayed-with-me&quot;&gt;The ideas that stayed with me&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Intent beats keywords.&lt;&#x2F;strong&gt; Rank for the job behind the query, not the words in it.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Title tags do the most work.&lt;&#x2F;strong&gt; They are the strongest signal on a page and
the biggest influence on whether anyone clicks. Meta descriptions do not rank,
but they still win or lose the click.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Canonicalise to fight duplication.&lt;&#x2F;strong&gt; Give every idea a single home. Thin,
overlapping pages only dilute each other.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links are earned, not bought.&lt;&#x2F;strong&gt; Relevance matters far more than volume.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;It compounds.&lt;&#x2F;strong&gt; Search optimisation is a long game that rewards patience over
cleverness.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;where-this-is-heading-geo&quot;&gt;Where this is heading: GEO&lt;&#x2F;h2&gt;
&lt;p&gt;My edition could not cover the shift now under way: GEO, or generative engine
optimisation. As answer engines such as Google’s AI Overviews, ChatGPT and
Perplexity begin to absorb the click, the goal moves from ranking a link to being
the source the model quotes. Position one matters less when the answer is written
above the results.&lt;&#x2F;p&gt;
&lt;p&gt;What reassures me is that the fundamentals carry over. A language model, like a
crawler, rewards content that is clear, well organised and genuinely
authoritative. Being talked about starts to matter as much as being linked to.
GEO looks less like a new craft than the old principles aimed at a new kind of
reader.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;worth-reading&quot;&gt;Worth reading?&lt;&#x2F;h2&gt;
&lt;p&gt;Yes, if you own anything on the web. Just pair it with something current on GEO,
because the ground under this one is still moving.&lt;&#x2F;p&gt;
&lt;p&gt;The Art of SEO, by Eric Enge, Stephan Spencer and Jessie C. Stricchiola.
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.goodreads.com&#x2F;book&#x2F;show&#x2F;6801452-the-art-of-seo&quot;&gt;Goodreads&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Dostoevsky’s Notes from Underground</title>
          <pubDate>Sat, 14 Dec 2024 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/notes-from-underground/</link>
          <guid>https://usegitflow.com/posts/notes-from-underground/</guid>
          <description xml:base="https://usegitflow.com/posts/notes-from-underground/">&lt;p&gt;I recently finished reading &lt;em&gt;Notes from Underground&lt;&#x2F;em&gt; by Fyodor Dostoevsky, and it’s been sitting heavily on my mind.
First published in 1864, the book is often called one of the earliest existentialist novels, and after reading it, I can
see why. It’s raw, challenging, and deeply philosophical.&lt;&#x2F;p&gt;
&lt;p&gt;The story is told by the “Underground Man,” an unnamed narrator who has isolated himself from society. He’s a retired
civil servant living in St. Petersburg, and he spends his days trapped in his own thoughts. His voice is bitter and
scathing, full of contradictions, but also painfully honest. What struck me most about him is his self-awareness: he
knows exactly how flawed he is, but he seems unable or unwilling to change. It’s frustrating to read at times, but also
incredibly relatable. How often do we recognise our own bad habits but still struggle to break free from them?&lt;&#x2F;p&gt;
&lt;p&gt;One of the central themes of the book is free will. The Underground Man pushes back against the idea that humans are
purely rational and always act in their best interest. Instead, he argues that people sometimes make irrational choices
simply to prove they can, just to assert their freedom. It’s a powerful idea that feels surprisingly relevant even today.
In a world that values optimisation and efficiency, this stubborn insistence on irrationality feels strangely human.&lt;&#x2F;p&gt;
&lt;p&gt;Another theme that stood out to me was loneliness. The Underground Man is deeply alienated, and yet he craves
connection. His interactions with other people, especially Liza, are painful to watch. He wants to be understood, but he
sabotages every chance he gets. The scenes with Liza are especially moving: she offers him compassion and a chance at
redemption, but he lashes out at her, pushing her away. It’s heartbreaking, but also a reminder of how fear and
insecurity can prevent us from accepting kindness when we need it most.&lt;&#x2F;p&gt;
&lt;p&gt;What I find fascinating about this book is how timeless it feels. Even though it was written more than 150 years ago,
the struggles of the Underground Man still resonate today. His bitterness, his self-doubt, his need to prove something
to himself and others. It’s all so familiar. Dostoevsky doesn’t give us easy answers, but he forces us to confront the
uncomfortable truths about human nature.&lt;&#x2F;p&gt;
&lt;p&gt;Reading &lt;em&gt;Notes from Underground&lt;&#x2F;em&gt; isn’t easy. It’s the kind of book that challenges you, makes you uncomfortable, and
leaves you thinking long after you’ve closed it. But that’s also what makes it so powerful. It’s a book that asks hard
questions about who we are, why we act the way we do, and what it really means to be free.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re looking for a book that digs deep into the human psyche and doesn’t shy away from complexity, I highly
recommend &lt;em&gt;Notes from Underground&lt;&#x2F;em&gt;. It’s not a light read, but it’s one that will stay with you.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Siddhartha by Hermann Hesse, A Short Reflection</title>
          <pubDate>Tue, 29 Oct 2024 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/siddhartha/</link>
          <guid>https://usegitflow.com/posts/siddhartha/</guid>
          <description xml:base="https://usegitflow.com/posts/siddhartha/">&lt;p&gt;The story is about Siddhartha, a man who spends his life searching for meaning and enlightenment. He leaves his family,
tries being a monk, lives in luxury, and finally settles by a river, where he finds peace and wisdom.&lt;&#x2F;p&gt;
&lt;p&gt;What struck me the most is how the book shows that true understanding comes from experience, not from teachings.
Siddhartha learns this the hard way, going through so many phases that at times feel frustrating to watch, but isn’t that
just life? It reminded me that every mistake and detour we make has value.&lt;&#x2F;p&gt;
&lt;p&gt;The river in the story is my favourite part. It’s a beautiful metaphor for how life flows and connects everything.
Reading this made me reflect on how often I try to control things, instead of just letting life unfold.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Siddhartha&lt;&#x2F;em&gt; isn’t a fast or action-packed book, but it’s reflective and calming. If you’re feeling overwhelmed or
stuck, it’s a great reminder to take a step back and see the bigger picture.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Making Chill Lofi Music with GarageBand</title>
          <pubDate>Sun, 03 Sep 2023 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/making-chill-lofi-music-with-garageband/</link>
          <guid>https://usegitflow.com/posts/making-chill-lofi-music-with-garageband/</guid>
          <description xml:base="https://usegitflow.com/posts/making-chill-lofi-music-with-garageband/">&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;usegitflow.com&#x2F;posts&#x2F;making-chill-lofi-music-with-garageband&#x2F;#why-i-like-lofi&quot;&gt;Why I Like Lofi&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;usegitflow.com&#x2F;posts&#x2F;making-chill-lofi-music-with-garageband&#x2F;#playing-around-in-garageband&quot;&gt;Playing Around in GarageBand&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;usegitflow.com&#x2F;posts&#x2F;making-chill-lofi-music-with-garageband&#x2F;#hiccups-along-the-way&quot;&gt;Hiccups Along the Way&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;usegitflow.com&#x2F;posts&#x2F;making-chill-lofi-music-with-garageband&#x2F;#putting-my-music-out-there&quot;&gt;Putting My Music Out There&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Music has always been my happy place, and lofi is my go-to for chilling out.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-i-like-lofi&quot;&gt;Why I Like Lofi&lt;&#x2F;h2&gt;
&lt;p&gt;What’s not to love about lofi? It’s got these little noises, the sound of an old record, the tiny crackles, that just make you feel cozy. It’s also easy to get into: you don’t need a pile of fancy gear or to be a music genius.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;playing-around-in-garageband&quot;&gt;Playing Around in GarageBand&lt;&#x2F;h2&gt;
&lt;p&gt;I started messing around with GarageBand on my MacBook, and it was a blast. If you’ve used any app before, GarageBand feels easy to find your way around, and there are so many sounds to pick from.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;media&#x2F;piano.jpg&quot; alt=&quot;piano.jpg&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Making music is awesome!&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I didn’t expect it, but making my own beats was like a mini-vacation for my brain. It’s nothing like my day job, yet it’s creative in its own way. And the best part is that a mistake sometimes makes the music sound even better.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;hiccups-along-the-way&quot;&gt;Hiccups Along the Way&lt;&#x2F;h2&gt;
&lt;p&gt;OK, I hit a couple of bumps in the road. At first, I wanted to throw in every cool sound I found, but lofi is more about keeping things simple. I also had to turn off my “let’s solve this problem” mindset. Lofi isn’t about following all the rules; it’s about the feel.&lt;&#x2F;p&gt;
&lt;p&gt;You don’t have to make things complicated. What really matters is how the music makes you, and hopefully others, feel. GarageBand makes it easy to turn that feeling into a tune.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;putting-my-music-out-there&quot;&gt;Putting My Music Out There&lt;&#x2F;h2&gt;
&lt;p&gt;Finally, I got brave enough to share my beats online. I was a mix of excited and nervous, and to my surprise, people from all sorts of places and backgrounds got into it.&lt;&#x2F;p&gt;
&lt;p&gt;Getting into lofi has been an eye-opener. It lets me tap into a side of myself that my techie day-to-day doesn’t often show. It isn’t perfect or polished, but that’s what makes it feel real, a small reminder that even in a world full of gadgets and screens there’s still a place for simple, honest feelings.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re curious, you can find my tracks on &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;music.apple.com&#x2F;us&#x2F;artist&#x2F;chaoyi-feng&#x2F;1703750524&quot;&gt;Apple Music&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>How I Passed the JLPT N1 Test</title>
          <pubDate>Sun, 20 Aug 2023 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/how-i-passed-the-jlpt-n1-test/</link>
          <guid>https://usegitflow.com/posts/how-i-passed-the-jlpt-n1-test/</guid>
          <description xml:base="https://usegitflow.com/posts/how-i-passed-the-jlpt-n1-test/">&lt;p&gt;I have always had a soft spot for Japanese culture, its dramas and comics above all, 名探偵コナン (Detective Conan) most of all. Taking the JLPT N1 was never really about the certificate. It was a personal milestone, and what follows is simply how one working amateur got there, offered as one route among many rather than a map anyone need follow.&lt;&#x2F;p&gt;
&lt;p&gt;N1 is the highest of the JLPT’s five levels. It builds on the ground I first covered for N3 in 2020, though the gap between the two is wider than the numbering lets on. The examiners draw their vocabulary, reading and listening from the material a native adult meets every day, which means the test rewards long exposure far more than a late scramble. The paper is marked out of 180 across three sections, 言語知識 (vocabulary and grammar), 読解 (reading) and 聴解 (listening), and a pass asks you to clear a minimum in each rather than merely the total. That last point is worth respecting. A strong reading score will not rescue a weak ear.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-books-i-leaned-on&quot;&gt;The books I leaned on&lt;&#x2F;h2&gt;
&lt;p&gt;The set I worked from was 日本語総まとめ N1 (Nihongo Sōmatome N1), the same series that had carried me through N3, so it already felt like a familiar hand. Its appeal is the format: a structured six week plan with a small amount to do each day, illustrations and all, which turns a daunting syllabus into something you can chip at a page at a time. It suited my self study, though I would not pretend it is the only sensible choice; plenty of people reach N1 by quite different roads, and some of them faster. What mattered was less the book than the habit around it. I treated it as a drill rather than a text to be read cover to cover. Vocabulary and grammar went into daily review, reading was about building speed so the clock would not beat me, and listening meant playing a passage on repeat until it stopped sounding like noise.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;fitting-it-around-a-busy-life&quot;&gt;Fitting it around a busy life&lt;&#x2F;h2&gt;
&lt;p&gt;I gave myself about six months, which is not long, and I was honest with myself that studying every day was never going to happen. In practice it was a few evenings in the week and longer stretches at the weekend, slotted around work and family rather than the other way round. Three things outside the books quietly did much of the work:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Anki&lt;&#x2F;strong&gt; carried the daily load for vocabulary and grammar, a few minutes at a time rather than one long sitting. Spaced repetition is hardly a secret, yet I know of nothing with a better return for a test like this.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Dramas and 名探偵コナン&lt;&#x2F;strong&gt;, the shows that drew me to Japanese in the first place, doubled as listening practice. It rarely felt like work, which is rather the point.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;YouTube and podcasts&lt;&#x2F;strong&gt; filled the commute and the odd spare moment, keeping my ear used to natural speed on the days the books stayed shut.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If there is one thing worth passing on, it is that consistency beat intensity every time. Small daily contact with the language, even on tired evenings, did more than any ambitious weekend I planned and then only half kept.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;on-the-day&quot;&gt;On the day&lt;&#x2F;h2&gt;
&lt;p&gt;I went in trying to enjoy the thing rather than survive it, which helped more than I had expected. The questions felt less like hurdles and more like pieces settling into place. If I watched anything closely it was the clock, particularly in the reading section, where it is easy to fall for one passage and pay for it later.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;afterwards&quot;&gt;Afterwards&lt;&#x2F;h2&gt;
&lt;p&gt;Passing turned out to matter less than the certificate might suggest. The quiet satisfaction lay in keeping a small and demanding hobby alive alongside a full life, and in finding that learning a language is still one of the more rewarding ways to spend an odd half hour. I pass all of this on tentatively, aware that what worked for me may not be your path at all. If you are weighing up N1, or any other private challenge, the most honest thing I can offer is that the journey tends to be worth more than the line at the end of it.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Think Again: the art of rethinking in both career and life</title>
          <pubDate>Tue, 09 Aug 2022 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/think-again/</link>
          <guid>https://usegitflow.com/posts/think-again/</guid>
          <description xml:base="https://usegitflow.com/posts/think-again/">&lt;p&gt;&lt;em&gt;Think Again&lt;&#x2F;em&gt; is one of those books that examine how we think, with abundant examples, and it will keep reminding me to practise rethinking in both my career and my life. I expect rethinking could eventually become part of my thinking strategies.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;individual-rethinking-updating-our-own-views&quot;&gt;Individual Rethinking: Updating Our Own Views&lt;&#x2F;h2&gt;
&lt;p&gt;It starts by talking about individual rethinking. The author listed four modes of thinking:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Preacher: We’re convinced we’re right&lt;&#x2F;li&gt;
&lt;li&gt;Prosecutor: We’re trying to prove someone else wrong&lt;&#x2F;li&gt;
&lt;li&gt;Politician: We’re trying to win the approval of our audience&lt;&#x2F;li&gt;
&lt;li&gt;Scientist: You favor humility over pride and curiosity over conviction. You look for reasons why you might be wrong, not just reasons why you must be right.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;It looks obvious that the scientist thinking mode is the most “mature” way of thinking, but I can easily come up with cases that I’ve behaved as the other modes. It’s hard to maintain an open mind and research why we might be wrong instead of thinking about why we must be right. The author listed several stories of how rethinking has helped boost start-up revenues, or how intelligence became a curse in BlackBerry’s failure to compete with Apple.&lt;&#x2F;p&gt;
&lt;p&gt;“If knowledge is power, knowing what we don’t know is wisdom.” I’m confident that I would stay in the rethinking cycle of Humility -&amp;gt; Doubt -&amp;gt; Curiosity -&amp;gt; Discovery -&amp;gt; Humility when learning new things, but it’s so easy to get into the overconfidence cycle when talking about some topics or tech stacks that (I believe) I’m fairly familiar with and know much more than average: Pride -&amp;gt; Conviction -&amp;gt; Confirmation &amp;amp; Desirability Biases -&amp;gt; Validation -&amp;gt; Pride. Especially on the validation part, when I got lucky in several discussions or even debates, it’s easy to tend to become conceited or even condescending. The curse of knowledge is we could close our minds to what we don’t know, and stand on the “summit of Mount Stupid”.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;media&#x2F;think-again&#x2F;1.png&quot; alt=&quot;image&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The ideal position is to be both high in confidence and humility, or in the “Confident Humility Zone”, which I believe I’m still seeking. To possess faith in my strengths while being aware of my weaknesses, I need to get an accurate picture of my knowledge and skills in the scientist mode. Although the author mentioned he somehow believes “we’re sometimes better off underestimating ourselves”, which I also agree with.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;media&#x2F;think-again&#x2F;2.png&quot; alt=&quot;image&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;interpersonal-rethinking-opening-other-people-s-minds&quot;&gt;Interpersonal Rethinking: Opening Other People’s Minds&lt;&#x2F;h2&gt;
&lt;p&gt;I’m not that passionate about winning debates and influencing other people, but it’s possible that when I think things are personal I lose passion&#x2F;temper&#x2F;whatever and end up with at least one person in the debate becoming unhappy and nothing working out. One way to improve is by listening and finding common ground.&lt;&#x2F;p&gt;
&lt;p&gt;The book describes a &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=-d4Uj9ViP9o&quot;&gt;debate between Harish and Debra&lt;&#x2F;a&gt;, where the audience’s mind shifted several times as the debaters convinced people to rethink. The key points from Harish are: drawing attention to common ground and avoiding defend-attack spirals. Also, don’t step on people’s toes by throwing more reasons as preaching or prosecuting, as that would shut people’s minds as audiences shield against persuasion, and maybe even backfire. Instead, pose more questions, and open audiences’ minds that they might be wrong.&lt;&#x2F;p&gt;
&lt;p&gt;One thing to notice is that less is more: when we put several reasons on the table, the weakest one becomes the easiest loophole for people to dismiss the entire case. “A weak argument generally dilutes a strong one”. This also applies when we’re writing a list of reasons for performance reviews.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;media&#x2F;think-again&#x2F;3.png&quot; alt=&quot;image&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;collective-rethinking-creating-communities-of-lifelong-learners&quot;&gt;Collective Rethinking: Creating Communities of Lifelong Learners&lt;&#x2F;h2&gt;
&lt;p&gt;It’s a basic human tendency to seek binary bias by simplifying a complex continuum into two categories, like good or bad, gun control or gun freedom, abortion or anti-abortion, Democrats or Republicans, Zero Covid or Living with Covid, or “those who divide the world into two kinds of people, and those who don’t”. It’s important to &lt;strong&gt;resist the impulse to simplify things&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;media&#x2F;think-again&#x2F;4.png&quot; alt=&quot;image&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The author also talked about the so-called life plans, by not setting boundaries by making plans. We should be mindful of the “tunnel vision” of plans that prevent us from seeing better possibilities.&lt;&#x2F;p&gt;
&lt;p&gt;Collective rethinking is also about changing organisational cultures, for example, a team that is agile in changing its mind collectively based on rethinking, although I wouldn’t want this agility to go too far either. One interesting point is “avoid best practice”, as best practice assumes the team has arrived at an optimal solution. I understand this type of belief will prevent effective rethinking, but since I’m a fan of “best practice” myself sometimes and believe it has more benefits, I would prefer stating this as “update best practice frequently”.&lt;&#x2F;p&gt;
&lt;p&gt;It’s also very normal for the plan to not work out. We should keep an open mind and spend time rethinking the plan on the way. To question your plan instead of executing it at any cost is the essence of rethinking, and this is something I’m also not very aware of. We always hear about determination but rarely about the direction that would lead to undesirable results.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>A new page in 2022</title>
          <pubDate>Sat, 06 Aug 2022 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/2022-new-page/</link>
          <guid>https://usegitflow.com/posts/2022-new-page/</guid>
          <description xml:base="https://usegitflow.com/posts/2022-new-page/">&lt;p&gt;It has been quite a while since the last time I updated my blog, although I kept updating items in my &lt;a href=&quot;&#x2F;media&#x2F;&quot;&gt;Books &amp;amp; Movies log page&lt;&#x2F;a&gt;. Many life changes have happened during this period of over a year.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;I got married to my lovely wife, and we’ve officially made our home in the beautiful city of Singapore!&lt;&#x2F;li&gt;
&lt;li&gt;I landed a new job at Facebook, now known as Meta, and have been working there for almost a year now. Admittedly, I’ve gained a bit of weight, courtesy of the irresistible desserts at the cafeteria.&lt;&#x2F;li&gt;
&lt;li&gt;Instead of spending all my spare time coding or on my laptop, I’ve been indulging in my hobbies and investing time in learning Japanese. I took my JLPT N2 exam this July. Learning a new language is challenging, especially when you don’t get to practice speaking it often.&lt;&#x2F;li&gt;
&lt;li&gt;While COVID is receding in some parts of the world, I still find myself unable to return home.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Despite the challenges, life has been treating me fairly well, and I’m grateful for it. Looking ahead, I have some specific plans for the rest of 2022.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;I plan to read more books in paperback. There’s something about the tactile experience of turning pages that a Kindle or iPad just can’t replicate, right?&lt;&#x2F;li&gt;
&lt;li&gt;I aim to write &lt;code&gt;n(n&amp;gt;0)&lt;&#x2F;code&gt; random posts about a variety of topics. I believe this will not only help me share my thoughts and experiences but also improve my writing skills.&lt;&#x2F;li&gt;
&lt;li&gt;I intend to do more coding. After all, I don’t want my new laptop to stay idle for too long.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;In conclusion, the past year has been a journey of change and growth, and I’m excited about what the rest of 2022 holds.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>What I learned from How to Avoid a Climate Disaster</title>
          <pubDate>Sun, 02 May 2021 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/climate-change/</link>
          <guid>https://usegitflow.com/posts/climate-change/</guid>
          <description xml:base="https://usegitflow.com/posts/climate-change/">&lt;h2 id=&quot;the-importance-of-getting-to-zero&quot;&gt;The importance of “getting to zero”&lt;&#x2F;h2&gt;
&lt;p&gt;We’ve heard the phrase “zero greenhouse gas emission” many times in the news or magazines because greenhouse gases absorb heat, trap it in the atmosphere, and cause global warming and rising temperatures. We already know that if we don’t reduce emissions, the temperature will still rise by between 4 and 8 degrees Celsius this century. But apart from the direct effect of days becoming hotter and sea levels going up (which is already horrible), there are some effects that I didn’t think about before reading this book.&lt;&#x2F;p&gt;
&lt;p&gt;The first trouble from a hotter climate is more extreme natural disasters like hurricanes and floods that destroy infrastructure and cause devastation. Hotter weather means droughts in rivers and soil and more frequent and destructive wildfires in California and Australia in 2020. Rising sea levels, caused by melting polar ice and seawater expanding as it warms, mean that some cities are shrinking because of higher coastlines. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.nccs.gov.sg&#x2F;faqs&#x2F;impact-of-climate-change-and-adaptation-measures&#x2F;&quot;&gt;Singapore is taking some steps&lt;&#x2F;a&gt; to prepare itself for future issues caused by climate change.&lt;&#x2F;p&gt;
&lt;p&gt;As the weather gets hotter, animals and plants will be affected. Some will suffer while others thrive, which hits essential businesses like farming hard. With seawater getting warmer, even by only 2 degrees, some seafood would be wiped out.&lt;&#x2F;p&gt;
&lt;p&gt;And these effects do not work individually but on top of one another. According to Bill, climate change could be just as deadly as Covid-19 by mid-century and five times as fatal by 2100. Economic damage caused by climate change would be equally enormous.&lt;&#x2F;p&gt;
&lt;p&gt;To answer the question “why should we (as a country) deal with this issue?” the most persuasive answer is that countries that build great zero-carbon industries will be leading the global economy in the coming decades. Big energy breakthroughs would be significant and welcomed by the world.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;significant-topics-to-consider-about-climate-change&quot;&gt;Significant topics to consider about Climate Change&lt;&#x2F;h2&gt;
&lt;p&gt;According to the data in the book, greenhouse gas is emitted by these five categories as a proportion of:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Making things (cement, steel, plastic): 31%&lt;&#x2F;li&gt;
&lt;li&gt;Electricity: 27%&lt;&#x2F;li&gt;
&lt;li&gt;Growing plants and animals: 19%&lt;&#x2F;li&gt;
&lt;li&gt;Traffic (planes, trucks, ships): 16%&lt;&#x2F;li&gt;
&lt;li&gt;Keeping warm and cool (heating, cooling, refrigeration): 7%&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Although electricity only accounts for just a quarter here, I think clean energy is the most important topic and can help with the other categories, like how electric cars help reduce carbon emissions. In the book, Bill talked about how to help with “zero greenhouse gas emission” for each category in different chapters.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Electricity&lt;&#x2F;strong&gt; One interesting new term I learned is “power density”, about how much power we can get from a square metre of land. It turns out we can generate 500-10000 Watts per square metre from fossil fuels, and for Nuclear, the number is 500-1000, while for Solar, it is 5-20, and for Wind, we can only generate 1-2 Watts per square metre. The author uses the word &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.gatesnotes.com&#x2F;Energy&#x2F;Introducing-the-Green-Premiums&quot;&gt;“Green Premium”&lt;&#x2F;a&gt; to describe the extra cost we would need for switching to a zero-carbon option, and we need to find a new energy source that we can widely deploy with low or no Green Premium.&lt;&#x2F;p&gt;
&lt;p&gt;Today, natural gas and coal make up two-thirds of our electricity source because fossil fuels are cheap. Fun fact: oil is more affordable than a soft drink. Bill discussed several other options that are possible to replace fossil fuels. Apart from the problem of needing too much land, the sun and the wind are intermittent sources affected by weather. Storing excess electricity in batteries is super expensive, and it is hard to reduce the cost. If we want to use renewables for electricity sources, much faster innovations and more breakthroughs are needed for deploying renewables and improving transmission. According to &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.nytimes.com&#x2F;2021&#x2F;02&#x2F;15&#x2F;books&#x2F;review&#x2F;bill-gates-how-to-avoid-a-climate-disaster.html&quot;&gt;this NYTimes review&lt;&#x2F;a&gt;, the progress on batteries, solar and wind energy is more optimistic than Bill thinks.&lt;&#x2F;p&gt;
&lt;p&gt;Other options include nuclear power (fission and fusion), the only carbon-free and reliable energy source. France is already getting 70 percent of electricity from nuclear, while the US around 20 percent. The significant drawback is that it’s costly to build, and human error caused several nuclear accidents or disasters in history. In the book, Bill compared Nuclear power with Coal and Oil and said deaths caused per unit of Nuclear electricity are far less, and safety concerns shouldn’t block people from using it. Of course, the world needs to improve on Nuclear safety.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Materials&lt;&#x2F;strong&gt; Cement, concrete and steel are being used worldwide at an ever faster rate, and they generate far more greenhouse gases than plastics, even though plastics have lately had the worst reputation for climate change. We manufacture enormous amounts of materials, resulting in copious amounts of greenhouse gases, nearly a third of the 51 billion tonnes per year. We need to get those emissions down to zero, but it’s not an option to stop making things. Instead, Bill discussed several ways to drive the premiums down when adopting the zero-emissions approach.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Farming&lt;&#x2F;strong&gt; As people get richer, they eat more calories, particularly more meat and dairy. The more meat we consume, the more plants we need to grow, as it takes six calories of feed for every calorie of beef. When we need to produce more food, we need to reduce the emissions from producing it, while farmlands are already being affected by climate change. Artificial plant-based meat is a popular alternative for real meat, and the author highly recommends this approach (as an investor in plant-based meat companies).&lt;&#x2F;p&gt;
&lt;p&gt;Planting trees has been viewed as a popular forest-related solution for climate change, as trees capture carbon dioxide from the atmosphere. However, it’s not as simple as I considered before. A tree absorbs carbon dioxide with rather low efficiency, and if the tree dies, it will release all the carbon dioxide it stored back into the atmosphere. If we convert a farm into a forest, that may lead to trees being cut down somewhere else, and the benefits are offset. The most effective tree strategy for climate change is to &lt;strong&gt;stop cutting down&lt;&#x2F;strong&gt; trees we already have.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Traffic&lt;&#x2F;strong&gt; 8.2 billion tonnes of carbon are being produced from transportation today. During Covid-19, travel and trade have been limited, but even this reduction is not enough for the zero-emission target by 2050. And stopping people from moving is also not a valid option. Passenger vehicles are the source of half of transportation-related emissions. Electric vehicles are already trendy, and the Green Premium of EV is coming down. But the main concern is that if the electricity is not coming from a clean source, we’re not reducing the emissions, as it’s equal to moving gasoline around.&lt;&#x2F;p&gt;
&lt;p&gt;In the last three chapters, the author suggested the specific steps we can take, from government policies and world leaders to companies and investors to every one of us.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;covid-19-and-climate-change&quot;&gt;Covid-19 and Climate Change&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.geekwire.com&#x2F;2020&#x2F;bill-gates-warned-us-covid-19-like-pandemic-watch-ted-talk-2015&#x2F;&quot;&gt;Bill Gates warned us of a COVID-19-like pandemic — watch his TED Talk from 2015&lt;&#x2F;a&gt;. Now he has written this book to warn people about climate change. Still, he is optimistic and pragmatic, and thinks the world can avoid a disaster, as countries are making real progress. The world has become more committed since Covid to solving a global problem. In the next decade, Bill thinks that the world should focus on the technologies, policies, and market structures that will put us on the path to eliminating greenhouse gases by 2050.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.theguardian.com&#x2F;books&#x2F;2021&#x2F;feb&#x2F;17&#x2F;how-to-avoid-a-climate-disaster-by-bill-gates-review-why-science-isnt-enough&quot;&gt;Book review by the Guardian: How to Avoid a Climate Disaster by Bill Gates review – why science isn’t enough&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Applying CSS grid</title>
          <pubDate>Sun, 11 Apr 2021 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/grid-css/</link>
          <guid>https://usegitflow.com/posts/grid-css/</guid>
          <description xml:base="https://usegitflow.com/posts/grid-css/">&lt;p&gt;I’ve been trying to use Flexbox and Grid layout recently whenever I need to write some CSS for layout. It has been a widely used practice to use Flexbox to centre elements vertically and horizontally, or to fill elements into a container like a navigation bar. However, Flexbox itself is not sufficient for a page layout.&lt;&#x2F;p&gt;
&lt;p&gt;Grid layout, by contrast, is a generalized layout system. With something that looks a bit similar to table layout, or Bootstrap Grid layout, it can do much more. A Grid layout allows components to be put independently or even overlapping. We can nest grids in grids, or attach flexbox to a grid. In short, it’s the layout system that can do most of the complex layout jobs we’ve come across so far.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;steps-to-use-the-grid-layout&quot;&gt;Steps to use the Grid layout&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;Create a Grid container by defining the size of several rows and columns. You can also let the Grid extend automatically.&lt;&#x2F;li&gt;
&lt;li&gt;Place the Grid lines&lt;&#x2F;li&gt;
&lt;li&gt;Attach elements to the Grid&lt;&#x2F;li&gt;
&lt;li&gt;Define the Grid flow (optional)&lt;&#x2F;li&gt;
&lt;li&gt;Align and justify items&lt;&#x2F;li&gt;
&lt;li&gt;Layer elements (optional, if overlapping is needed)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;useful-resources&quot;&gt;Useful Resources&lt;&#x2F;h2&gt;
&lt;p&gt;I’d like to list the resources I used along the way, for serious learners who want to learn Grid CSS thoroughly.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;css-tricks.com&#x2F;snippets&#x2F;css&#x2F;complete-guide-grid&#x2F;&quot;&gt;A Complete Guide to Grid&lt;&#x2F;a&gt;, together with &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;css-tricks.com&#x2F;snippets&#x2F;css&#x2F;a-guide-to-flexbox&#x2F;&quot;&gt;Flexbox&lt;&#x2F;a&gt; is the place I’ll go to for learning and reference.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;CSS_Grid_Layout&quot;&gt;MDN Docs for CSS Grid Layout&lt;&#x2F;a&gt; is where we can look up useful properties.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;learning.oreilly.com&#x2F;library&#x2F;view&#x2F;css-in-depth&#x2F;9781617293450&#x2F;&quot;&gt;CSS in Depth, Part 2&lt;&#x2F;a&gt; covers layout strategies.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>My Japanese learning path from Zero to JLPT N3</title>
          <pubDate>Wed, 27 Jan 2021 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/japanese-n3/</link>
          <guid>https://usegitflow.com/posts/japanese-n3/</guid>
          <description xml:base="https://usegitflow.com/posts/japanese-n3/">&lt;p&gt;I’m writing to share my Japanese learning path last year, from Zero to JLPT N3. It’s achievable and practical.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;media&#x2F;japanese-n3&#x2F;friends.jpeg&quot; alt=&quot;My friends during the journey&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;my-experience&quot;&gt;My experience&lt;&#x2F;h3&gt;
&lt;p&gt;2020 was, no doubt, a strange and challenging year for almost everyone, including me. From March we were cut off from the world, with almost no good news to be had: working from home, away from the office, colleagues and friends, and getting used to faces behind masks.&lt;&#x2F;p&gt;
&lt;p&gt;Bored with the daily routine of working from home, I found I had far more spare time on my hands, and because of my long-standing curiosity about Japan and Japanese, in May I decided to try learning the language and see how far I could go. The target I set myself was passing the December 2020 JLPT N3 exam (the July sitting had been cancelled).&lt;&#x2F;p&gt;
&lt;p&gt;My motivation to learn Japanese is relatively straightforward:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;It’s an influential language in the world, especially in Asia and Singapore.&lt;&#x2F;li&gt;
&lt;li&gt;Learning a new language is always pretty cool, and it can equip me with a new angle on the world.&lt;&#x2F;li&gt;
&lt;li&gt;It’s close to Chinese. The two languages are similar in lexical terms, and I can save some effort reading Kanji (but not their readings).&lt;&#x2F;li&gt;
&lt;li&gt;Japanese culture is influential to almost everyone around me. I watched several Japanese dramas and movies, including Legal High, which I saw several times.&lt;&#x2F;li&gt;
&lt;li&gt;If I have time, effort, and interest, why not?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;After seven months of learning, I took the JLPT N3 in December 2020 at the Japanese Cultural Society of Singapore. Seven months of part-time study is not enough to master the language, and I ran into difficulties during the test. Luckily the result turned out well.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;media&#x2F;japanese-n3&#x2F;n3-result.jpeg&quot; alt=&quot;my JLPT N3 test result&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;learning-path&quot;&gt;Learning path&lt;&#x2F;h3&gt;
&lt;p&gt;I want to introduce my &lt;strong&gt;reference books, textbooks, exam books&lt;&#x2F;strong&gt;, and how I used them. I hope it can help somebody to start their journey of learning Japanese.&lt;&#x2F;p&gt;
&lt;p&gt;For reference books, I only bought two books, and these are more than enough for me.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.google.com&#x2F;url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=2ahUKEwiXkuDP6rvuAhUl7XMBHRr-BvMQFjACegQIAhAC&amp;amp;url=http%3A%2F%2Fwww.randomhousebooks.com%2Fbooks%2F40690%2F&amp;amp;usg=AOvVaw1NTcJrUicI0qCnXo-psjae&quot;&gt;Random House Japanese-English Dictionary&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.google.com&#x2F;url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=2ahUKEwj2puni6rvuAhX0juYKHbyvDPQQFjABegQIAxAC&amp;amp;url=https%3A%2F%2Fwww.tofugu.com%2Freviews%2Fdictionary-of-basic-japanese-grammar%2F&amp;amp;usg=AOvVaw3zo13CK21k8mJxPR7e8LS6&quot;&gt;A Dictionary of Japanese Grammar&lt;&#x2F;a&gt;, buy the Basic and Intermediate if you’re aiming for N3. It may seem a bit pricey, but worth every penny.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The only textbooks I used were the complete set of 『みんなの日本語初級』 including Textbook and several workbooks, as &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;omgjapan.com&#x2F;search?q=minna+no+nihongo&quot;&gt;this link&lt;&#x2F;a&gt; shows. As I’m studying part-time, I spent around 1-2 hours learning these textbooks every day.&lt;&#x2F;p&gt;
&lt;p&gt;My steps of using 『みんなの日本語初級』 are:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Read the words following recordings.&lt;&#x2F;li&gt;
&lt;li&gt;Memorise the words through &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;ankiweb.net&#x2F;&quot;&gt;anki&lt;&#x2F;a&gt; iOS and Mac app. It is an excellent app for memorising Japanese words. I strongly recommend using it. We can easily find the vocabulary set of みんなの日本語 in shared decks.&lt;&#x2F;li&gt;
&lt;li&gt;Listen to the main text and &lt;strong&gt;shadow&lt;&#x2F;strong&gt; it. By shadow, I mean doing dictation as much as possible. I used my iPad Pro Notability app to write the texts down after repeating them several times. Of course, there would be words I don’t understand and Kanji I can’t remember. It’s totally fine.&lt;&#x2F;li&gt;
&lt;li&gt;Compare with the main text and correct my dictation.&lt;&#x2F;li&gt;
&lt;li&gt;Reread the text following the audio for pronunciation.&lt;&#x2F;li&gt;
&lt;li&gt;Read the grammar part. There are plenty of great YouTube videos explaining grammar in みんなの日本語. I attached my link in the next section.&lt;&#x2F;li&gt;
&lt;li&gt;Look up the grammar I don’t understand in ‘A dictionary of Basic Japanese Grammar’, or search it online.&lt;&#x2F;li&gt;
&lt;li&gt;Finish all the exercises and workbooks. And then I’ll give myself some rewards after the hard work. No more practice is required as the workbooks contain reviewing sections already.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;I think after finishing the 『みんなの日本語初級』 textbook, you can pass the JLPT N4 easily without anything else. However, I needed to fill in the gap, as I had signed up for the N3 exam.&lt;&#x2F;p&gt;
&lt;p&gt;By the time I finished the 『みんなの日本語初級』 textbook it was already October, two months before my JLPT N3 exam. In those two months I focused on only one set of books, the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;omgjapan.com&#x2F;collections&#x2F;nihongo-so-matome&quot;&gt;Nihongo So-Matome JLPT N3 Complete Set&lt;&#x2F;a&gt;. One section a day across the five books matched the timeline well, and they helped me a great deal to bridge the gap between 『みんなの日本語初級』 and JLPT N3. Vocabulary, Grammar and Listening are the most critical parts, in my opinion, as test preparation requires specific techniques and experience. I certainly did not memorise everything, but completing the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;omgjapan.com&#x2F;collections&#x2F;nihongo-so-matome&quot;&gt;Nihongo So-Matome JLPT N3 Complete Set&lt;&#x2F;a&gt; was enough to get me through the N3. Things turned out well.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;some-useful-online-resources&quot;&gt;Some useful online resources&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.tofugu.com&#x2F;learn-japanese&#x2F;&quot;&gt;Learn Japanese: A Ridiculously Detailed Guide - Tofugu&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; title=&quot; 出口日語 【改訂版】大家的日本語文法解說&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=U8wniu_c_zc&quot;&gt;出口日語 【改訂版】大家的日本語文法解說&lt;&#x2F;a&gt; for grammar explanation&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.udemy.com&#x2F;course&#x2F;japanese-n3-course&#x2F;&quot;&gt;Online Japanese N3 Course(All 10 lessons)&lt;&#x2F;a&gt; I think the series by Attain Corp. on Udemy are all well-made. You can buy all courses if you prefer learning through videos. It would take no less effort for sure. I think it can be a suitable supplemental material for 『みんなの日本語初級』.&lt;&#x2F;li&gt;
&lt;li&gt;Siri. I changed my Siri language settings to Japanese and talked to it sometimes. It’s pretty helpful to practice my Japanese communication, especially during the lockdown period.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;I hope this post can assist some readers as a reference to reach the N3 level. I’m continuing my self-learning journey this year, and I hope I can share some N3 -&amp;gt; N2 experience some time.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>菊与刀</title>
          <pubDate>Sun, 20 Dec 2020 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/kiku-to-katana/</link>
          <guid>https://usegitflow.com/posts/kiku-to-katana/</guid>
          <description xml:base="https://usegitflow.com/posts/kiku-to-katana/">&lt;p&gt;Book link: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;zh.wikipedia.org&#x2F;wiki&#x2F;%E8%8F%8A%E4%B8%8E%E5%88%80&quot;&gt;菊与刀&lt;&#x2F;a&gt;,
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;The_Chrysanthemum_and_the_Sword&quot;&gt;The Chrysanthemum and the Sword&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;《菊与刀》（The Chrysanthemum and the Sword），美国人类学家鲁思·本尼迪克特於第二次世界大战接近尾声时受美国政府委托，为解决盟军是否应该占领日本以及美国应该如何管理日本的问题，根据文化类型理论、运用文化人类学方法对即将战败的日本进行研究所得出的综合报告，主要内容是分析了日本国民的性格。1946年该报告被作者整理成书出版，遂成本书。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;ju-yu-dao-de-chuan-qi-wu-guan-feng-ya-yu-sha-fa&quot;&gt;《菊与刀》的传奇：无关风雅与杀伐&lt;&#x2F;h3&gt;
&lt;p&gt;这些文化模式体现在日本人表面上相互矛盾的行为方式上。比如，日本人一方面彬彬有礼，另一方面尊大不逊；一方面墨守成规，另一方面开拓进取；一方面在菊花艺术上追求尽善尽美，另一方面崇拜武力，视武士为至高的荣誉……&lt;&#x2F;p&gt;
&lt;p&gt;日本社会先后经历了两次外来文明，即隋唐时代的中华文明与近代的欧洲文明的全方位影响，这种源于外部的影响导致了强烈的自我意识的生成。&lt;&#x2F;p&gt;
&lt;p&gt;如果我们要达成阅读的目标，我们必须首先进入对象的语境中去揣摩、理解，而非横向的、从外部进行简单的语义替换。&lt;&#x2F;p&gt;
&lt;p&gt;毋庸讳言，一个民族只有保持清醒的自我认识、自我反思的能力，才能永葆青春；反之，它将失去滋润生命的源头活水，浑浑噩噩地迷失在社会历史的变迁与诸文明的竞争当中。中华文明进入近代后，命运多舛、数度劫灰，最终能否生生不息，端赖自己是否有清醒的自我认识。对此，中国读者诚不可不察也。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-yi-zhang-ren-wu-ri-ben&quot;&gt;第一章 任务：日本&lt;&#x2F;h3&gt;
&lt;p&gt;无论是在原始部落还是文明前沿的国家，人类的行为都习自日常生活。不管一个人的行为或意见如何古怪，他的感受和想法是和他的经历有关的。&lt;&#x2F;p&gt;
&lt;p&gt;如果一个人接受了一个生活价值系统，却长期在某一方面依照另一个相反的价值系统思考行事，他就不可能不造成混乱和低效。他会试图尽量统一两者或者给自己编出一些共同的理由和动机。某种程度上的统一是必不可少的，不然这个系统就支离破碎了。&lt;&#x2F;p&gt;
&lt;p&gt;那些空想者似乎只能把善意原则建立在全世界的人都是出自同一个模子的这个假设上。实际上，以这样的绝对一致来作为尊重他国的条件就如同要求自己的妻儿同自己一样般神经质。&lt;&#x2F;p&gt;
&lt;p&gt;在美国，共和党和民主党都认为政府是个不得不有的祸害，它限制了个人的自由。除了战争时期，公务员远不及私有企业的职员有地位。这种看法和日本人相去甚远，甚至和不少欧洲国家也完全不同。&lt;&#x2F;p&gt;
&lt;p&gt;西方意义上的善与恶在这里发生了翻天覆地的变化。这个系统是独一无二的。它既不是佛教也不是儒学。这就是日本的特点，既是彼之所长也是彼之所短。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-er-zhang-zhan-zheng-zhong-de-ri-ben-ren&quot;&gt;第二章 战争中的日本人&lt;&#x2F;h3&gt;
&lt;p&gt;即便战争失败也没能让日本对自己的“大东亚”理想进行道德批判。即便是没怎么受军国主义毒害的日本战俘也几乎从不质问日本对亚洲大陆和西南太平洋的野心。日本将会在很长一段时间里保持某些与生俱来的态度，其中最重要的一个就是对等级制度的忠诚和信念。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-san-zhang-ge-de-qi-suo&quot;&gt;第三章 各得其所&lt;&#x2F;h3&gt;
&lt;p&gt;赫尔在他的备忘录里引用了对美国人而言同样基本的四条原则：主权不可侵犯和领土完整；不干涉他国内政；依赖国际合作与和解；平等的原则。&lt;&#x2F;p&gt;
&lt;p&gt;这并不是没有意义的姿态，它意味着鞠躬者承认对方有权决定他的事务，哪怕他本人更倾向于自己做主。那些受礼者也同样承认随着自己的地位相应而来的某些责任。以性别、辈分及长子继承权为基础的等级制度是家庭生活的重要组成部分。&lt;&#x2F;p&gt;
&lt;p&gt;一个宗族甚至有自己祖传的家法，如果宗族不同意当权者的意见，可以依此拒绝把宗族犯人交给国家。在帝制时代，官府以国家名义漫不经心地治理这些半自主的庞大宗族，朝廷一般委任外乡人作为统领官员并定期调任。&lt;&#x2F;p&gt;
&lt;p&gt;除此之外，日本还是一个封建国家，个人的效忠对象不是庞大的亲属集团，而是封建领主。领主是长居本地的最高领袖，和中国短期任命的外地官员完全不同。&lt;&#x2F;p&gt;
&lt;p&gt;日本是他们的长兄，他们是日本的弟弟。这个事实一定要让占领区的居民彻底明白。对他们太过体贴，他们就可能产生利用日本仁慈的倾向，进而危害到日本的统治。”换句话说，长兄替弟弟们决定什么对他们好，而且在执行过程中不应该表现出过多的体贴。&lt;&#x2F;p&gt;
&lt;p&gt;在此之前无论官方还是私人，日本都没有宏伟的永久性建筑，天皇以中国都城为模板新建了一座都城奈良，还参照中国模式建了多所宏伟奢华的佛寺和僧院。天皇根据使臣来自中国的报道引进了头衔、官阶和律法。一个主权国如此成功有计划地引进他国文明，在世界各国的历史上都可谓前无古人后无来者。&lt;&#x2F;p&gt;
&lt;p&gt;一道鸿沟隔开了武士和其他三个阶层：农民、工匠和商人。后三种是“庶民”，武士不是。武士们凭着特权佩刀，刀代表着他们的阶层，而不仅仅是装饰。他们有权对平民用刀。&lt;&#x2F;p&gt;
&lt;p&gt;就像商人们在等级规定的限制下，依然发展出一种追求舒适高雅的城市生活方式；武士们尽管随时可以拔刀相向，也发展出了风雅的技艺。&lt;&#x2F;p&gt;
&lt;p&gt;它对领俸禄的侍从阶层和生产阶层的限制如斯巴达式的苛刻，但是每个依赖者和上级之间的关系相对而言却比较可靠。每个人都知道自己的义务、权利和地位，如果这些权利、地位受到了侵犯，最穷困的人也会抗议。&lt;&#x2F;p&gt;
&lt;p&gt;农民们的抱怨也许事出有因，政府满足他们的要求也许是可取的，但是农民领袖们依然违反了严格的等级有别的法律。不管判决是否对他们有利，他们都违反了对主人忠诚这一核心法律，这一点不能被忽视。他们因此将被判处死刑。他们行为动机的正确性与此毫无关系。即使是那些受罚的农民也接受这种必然结果。&lt;&#x2F;p&gt;
&lt;p&gt;这就是法律和秩序。他们也许会在事后为死者修建祠堂，把他们当作烈士供奉，但是农民们接受死刑，因为这是他们赖以生活的等级制度的重要组成部分。&lt;&#x2F;p&gt;
&lt;p&gt;毕竟，封建统治在七十五年前才合法结束，深入人心的国民习性则很难在有生之年消失。下一章就会讲到，尽管国家的目标急剧变更，近代日本的政治家们依然处心积虑地保存现有制度的大部分。&lt;&#x2F;p&gt;
&lt;p&gt;每个人只要信赖并遵循这个制度就能获得安全。勇气和正义体现在对制度的遵守上，而不是对它的修改或反对上。在标明的范围内，这个世界制度明确，因此在日本人眼里也就是可靠的。它的规定不是戒条那样抽象的道德标准，而是细致地说明在这样那样的场合该怎么做，面对武士该如何，面对庶民又该如何，面对长兄该如何，面对幼弟又该如何。&lt;&#x2F;p&gt;
&lt;p&gt;我们要认识到日本的各个阶级都得到了特定的保障，这一点非常重要。即使是流民也有垄断各自行当的保障，他们的自治团体也得到了政府认可。每个阶级都受到诸多限制，但是都有序而安全。&lt;&#x2F;p&gt;
&lt;p&gt;不得不令人惊奇并指出的是，当欧日的封建制度同时面临灭绝的威胁时，比起欧洲大陆来说，日本在更大程度上允许了等级之间的流动。日本社会没有任何迹象表明贵族和中产阶级之间发生过阶级斗争就是对这一点最好的证明。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-si-zhang-ming-zhi-wei-xin&quot;&gt;第四章 明治维新&lt;&#x2F;h3&gt;
&lt;p&gt;把日本带入近代的战斗口号是“尊皇攘夷”，即“还政天皇，驱除蛮夷”。这句口号试图杜绝外部世界对日本的影响，使日本回到十世纪那种还没有天皇和将军双重统治的黄金时代。&lt;&#x2F;p&gt;
&lt;p&gt;然而真正的问题不是这些人出身于哪个阶级，而是他们到底为什么能够如此精明、干练和务实?十九世纪后半期日本刚刚脱离中世纪，国力就像现在的暹罗那样薄弱。而就在这样的情况下，它孕育出的领导人却能够计划并完成各国历史上最具政治家风范、最为成功的改革大业，实属不易。&lt;&#x2F;p&gt;
&lt;p&gt;在所有的亚洲国家中，不管采用什么样的政权，统治权威往往自上而下。他们的政权总是在中间地带遭遇自下而上的地方自主势力抗衡。各国的差别在于民主化的程度，政府承担责任的范围，当地领导的责任对象是全体选民，还是以牺牲一定的公众利益为代价来保证地方上少数权势阶层的利益。&lt;&#x2F;p&gt;
&lt;p&gt;因此日本政府和美国政府在各个方面都有很大的不同。在美国，选举产生的人员担负最高行政和立法责任，通过指挥地方警察和刑事法庭实现对地方的管理。但是与荷兰或比利时等西欧国家相比，日本的政府设置也并没有什么差别。&lt;&#x2F;p&gt;
&lt;p&gt;与西方文化相比，日本人更加顺从“上级”，因而他们的“上级”也拥有更多的行动自由。但是“上级”本身也必须安守本分。日本人的座右铭就是：“各就其位。”&lt;&#x2F;p&gt;
&lt;p&gt;日本在其他各个方面都任由个人自由选择信仰，只有一种特别的信仰被纳为国家管辖领域，其崇拜对象被视为国家统一和民族优越性的标志。这就是国家神道教。&lt;&#x2F;p&gt;
&lt;p&gt;因此，日本人是不断地通过参照等级制度来组织他们的社会秩序的。在家庭和私人关系中，年龄、辈分、性别和阶级决定人与人之间适当的行为。在政府、宗教、军队和工业中，各领域被周密地分成不同等级，无论是较高等级的人还是较低等级的人，一旦越权都将受罚。只要人人“各得其所”，日本人就毫无异议地继续生活，他们就觉得安全。当然，如果以他们的个人幸福是否得到了最好的保护作为标准，那么他们其实并不非常“安全”。他们所谓的“安全”是因为承认了等级制度的合法。这是日本人对等级的信仰，就像美国人对平等和企业自主经营的信仰一样。&lt;&#x2F;p&gt;
&lt;p&gt;日本人不能以要求自己的标准来强求其他民族。他们的错误就在于他们认为自己可以做到。他们没有认识到，把他们打造成“各得其所”的日本道德体系是其他地方所无法接受的。其他国家从来没有过这种系统，这是真正的日本产物。日本作家们视这种道德体系为理所当然，对此也没有过多的阐述。所以，我们必须首先理解这种道德体系，才能去了解日本人。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-wu-zhang-shou-en-yu-li-shi-yu-she-hui&quot;&gt;第五章 受恩于历史与社会&lt;&#x2F;h3&gt;
&lt;p&gt;品德高尚的人不会像美国人那样说什么自己“谁也不亏欠”，也不会忽略历史。日本有着一张巨大的人情互惠网络，覆盖了祖先和同辈，一个人只有认清了自己在其中的位置，才算持身公正。&lt;&#x2F;p&gt;
&lt;p&gt;这个“恩”意味着对亏欠的对象要有所回报，所以也就意味着“爱”，但是其中的最主要含义还是“亏欠”。而我们总认为“爱”是自愿给予，不求回报的。&lt;&#x2F;p&gt;
&lt;p&gt;当然没有人是在对自己的孩子施恩，尽心照顾孩子只是回报自己幼时父母的照顾之恩。把自己的孩子同样或者更好地养大，就是部分地回报了自己的父母之恩，对子女的义务就这样只是从属于父母之恩。&lt;&#x2F;p&gt;
&lt;p&gt;这种建立在恩情基础上的道德体系要运作顺利，必须取决于每个人是否把自己当作优良的债务人，在还债的同时不心怀怨恨。我们已经谈到过日本的等级系统组织得如何完善，随之产生的习惯也得到了日本人的忠实遵守。多亏了这些习惯，日本人对道德债务的履行程度之高是西方人所无法想象的。如果施恩的上级是出自好意，报恩自然就更加理所当然了。&lt;&#x2F;p&gt;
&lt;p&gt;在日本，街上发生交通意外时人群的无所作为不是因为缺乏主动，而是因为大家都知道任何非官方的干涉会让人背负恩情。明治之前的一条著名法律就是：“如果发生争吵和纷争，旁人非不得已不可干涉”，要是有人在这种情况下未经授权而帮助了他人，大家会怀疑他是想从中非法牟利。&lt;&#x2F;p&gt;
&lt;p&gt;日本人通常说这种“难事”是顾客通过购物而赐给商店的难得大恩。这是一句恭维，也适用于收到礼物和无数其他场合。&lt;&#x2F;p&gt;
&lt;p&gt;从日本人的角度看，这种欠债的态度在另一种谢谢的说法里表达得更为强烈，“我被羞辱了”，这个词组书写时包括了侮辱的“辱”字和意味着丢脸的“羞”字，它同时表达了“我受到了侮辱”和“我很感激”的意思。&lt;&#x2F;p&gt;
&lt;p&gt;无论感情有多复杂，只要“恩人”是自己就可以接受；或者因为这个人在“我”的等级结构里有一定位置，或者因为他所做的是我认为自己也会做的，比如说归还被风吹跑的帽子，又或者这个人是“我”的崇拜者。一旦这些既定的身份前提不能成立，恩就成了化了脓的疮。即使再小的亏欠也让人反感，这是一种德行。&lt;&#x2F;p&gt;
&lt;p&gt;假如一个人选择让别人背负自己的深恩，哪怕施恩对象是自己的亲生子女，以后想要改变也得冒不小的风险。他应该明白自己会为此吃苦头。另外，不管自己的付出有多大，也不能挟恩自重；用旧日恩情来合理化现在的行为是错误的。&lt;&#x2F;p&gt;
&lt;p&gt;爱、善心、慷慨，这些我们无条件给予，也同样珍重的东西，在日本就是带了附加条件的。每一次接受这些东西都让人成为负债人。就如日本俗语所说：“要受恩得天生的（极端）大度。”&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-liu-zhang-bao-en-yu-mo-yi&quot;&gt;第六章 报恩于万一&lt;&#x2F;h3&gt;
&lt;p&gt;对日本人来说，恩这种重要的也是时刻存在的负债状态和主动而又紧张的还债行为完全是两码事，后者得通过另外一套概念来表达。一个人负债（恩）不是德行；还债（报恩）则是美德。一个人主动报恩就是美德的体现。&lt;&#x2F;p&gt;
&lt;p&gt;一种回报在数量和时间上都是无限的，另一种则是等量回报，并在特定的日子里付出。那种无限的回报被称为“义务”，有话这样说，“难以报（此）恩于万一”。&lt;&#x2F;p&gt;
&lt;p&gt;中国规定了一个更高级别的德行，也是忠孝的前提，那就是“仁”。“仁”几乎包括了所有西方人认为良好的人际关系。父母必须“仁”。如果一个统治者不仁，他的臣民起义反叛就是正义的。“仁”是忠的先决条件。皇帝和官员的在位长短就取决于他们是否施行仁政。中国的道德体系把这一试金石应用到所有的人际关系中。&lt;&#x2F;p&gt;
&lt;p&gt;“行仁义”所含的“法律之外”的意思还有另一层意义，它也被用来特指“绿林道义”。&lt;&#x2F;p&gt;
&lt;p&gt;日本人就这样重新诠释并贬低了中国体系中关键的美德，却没有补充其他可以作为义务的先决条件，于是孝道在日本成了一个人必须完成的责任，哪怕这意味着容忍父母的恶行和不公。只有在和对天皇的义务发生冲突时，孝才可废。如果仅仅是因为父母不值得子女孝敬，或者父母摧毁了子女的幸福，孝还是不可违背。&lt;&#x2F;p&gt;
&lt;p&gt;他说孝常常和其他的美德冲突。如果那个儿子够聪明，他也许可以找到一个法子缓和矛盾而不失自尊。但是他要是责怪了自己的母亲，哪怕只是心里想想，也要无地自容了。&lt;&#x2F;p&gt;
&lt;p&gt;但是就如日本习语所说：“讨人厌的媳妇不断地生招人疼的孙子”，孝就体现在这里。小媳妇表面上无限顺从，但是一代又一代，这些温和可爱的女子长成挑剔苛刻的婆婆，就如同自己的婆婆一样。作为年轻的妻子，她们不能表现出凶悍，但也不会就此永远温顺。她们后半生会加倍地把自己历年积累的怨恨加诸自己的媳妇。&lt;&#x2F;p&gt;
&lt;p&gt;日本不像中国那样有史以来记载了三十六个朝代。作为一个国家，日本尽管经历了种种变迁，却从未真正彻底地破除自己的社会结构，其模式是一成不变的。&lt;&#x2F;p&gt;
&lt;p&gt;实习教师如果把一个人的最高使命解释成为爱国就会被评为不及格，唯一的正确解释是回报天皇。&lt;&#x2F;p&gt;
&lt;p&gt;在天皇的声音从广播里传出之前，怀恨的反对者们封锁了皇宫，试图阻止天皇发布公告。但是公告一旦发出，大家都接受了。无论是满洲或是爪哇的指挥官，还是日本的东条，都没人提出异议。&lt;&#x2F;p&gt;
&lt;p&gt;但是日本不是西方，不会使用西方国家的终极力量：革命，也并不和占领的敌人暗中作对搞破坏。日本使用的是自己的力量：在军队的战斗力被消灭之前，就要求自己付出无条件投降的巨大代价，以效忠天皇为号令。在日本人的眼里，这种巨大代价还是换来了他们至为珍视的东西：他们有权说，这是天皇下的命令，即使命令是投降。即使战败了，效忠天皇依然是最高法律。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-qi-zhang-zui-nan-cheng-dan-de-hui-bao&quot;&gt;第七章 最难承担的回报&lt;&#x2F;h3&gt;
&lt;p&gt;“道义”的起源却和中国的儒家思想或东方的佛教都毫无瓜葛，它指代的是一个日本特有的道德范畴，只有考虑到了这一点才能理解日本人的行为。日本人一旦谈到动力、名声，或男男女女在祖国日本碰到的为难之处，就一定会时刻把“道义”挂在嘴边。&lt;&#x2F;p&gt;
&lt;p&gt;道义又分为不同的两大类：一类我姑且称为“对社会的道义”——实际上就是“回报道义”——是指一个人有责任报答同伴的恩情；另一种我姑且称为“对名声的道义”，是指个人有责任保持自己的名声不受玷污，类似德国的“名誉”之说。&lt;&#x2F;p&gt;
&lt;p&gt;正如一个日本人所说：“一个长大成人的儿子为母亲做任何事都是出于爱，因此不能算是道义；只要行动发自内心，就不能算是为了道义。”履行对亲家的责任则必须事无巨细、小心缜密，不然就有可能被人指责“这个人不懂道义”。这是不惜任何代价都要避免的。&lt;&#x2F;p&gt;
&lt;p&gt;在这些古代传说中，道义发自内心，毫无怨恨，那是现代日本人心目中的黄金时代。这些故事告诉他们，那个时候的道义没有“不情愿”的含义。如果道义和“忠”起了冲突，人们可以堂堂正正地坚持道义。&lt;&#x2F;p&gt;
&lt;p&gt;“道义”现在常见于日常用语，但是表达的都是怨恨，强调的是说话的人迫于舆论的压力、不得不违背自己的意愿去履行道义。&lt;&#x2F;p&gt;
&lt;p&gt;但是回礼重于礼物是日本的大忌。“投我以木瓜，报之以琼琚”根本不是美德。事实上，对礼物的最大批评就是送礼人“用鲷鱼（一种大鱼）回报小鱼”。同样的道理也适用于回报道义。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-ba-zhang-xi-qing-wu-ming&quot;&gt;第八章 洗清污名&lt;&#x2F;h3&gt;
&lt;p&gt;在日本这就是同一种美德。正直的人对于受人恩惠或者遭人侮辱感受都同样强烈。无论是哪一者，给予相应回报都是美德。不像我们，还要把两者区分开来，一者称之为侵犯；另一者为非侵犯。对日本人来说，只有“道义界”之外才存在侵犯；只要一个人保持道义，为自己洗清污名，那个人就不用担侵犯的罪名。&lt;&#x2F;p&gt;
&lt;p&gt;和日本不同，这不属于中国人理想中的高贵品质。无故使用暴力是错误的，中国的道德体系并不赞同用暴力报复自己受到的侮辱，认为这样气量狭小是极其可笑的。面对毁谤，他们也不会下定决心全力行善来证明这种诋毁是没有根据的。&lt;&#x2F;p&gt;
&lt;p&gt;所有这些道义的用法都体现了个人和工作的极端认同感，任何对个人行动或者能力的批评都自动变成对个人本身的批评。&lt;&#x2F;p&gt;
&lt;p&gt;没有人会认为自己的自尊取决于是否一贯正确，一旦承认错误就得辞职或退休。但是在日本，这种自我维护意识深入人心。所以不能当面如实指出一个人犯了专业上的错误，这既是明智之举，也是通行的礼节。&lt;&#x2F;p&gt;
&lt;p&gt;日本人有很多方法消除两人之间因竞争而引发的直接对抗，其中最引人注目的方法之一就是无所不在的中介制度。只要事情办不成有可能让人感到羞辱，中间人就必不可少。这就造成无数场合都需要中间人：从谈婚论嫁，求职应聘，离职到其他无数日常安排。&lt;&#x2F;p&gt;
&lt;p&gt;日本人有各种各样应对的礼节，以免某些情况会造成对人的羞辱，进而引起“对名声的道义”问题。直接竞争只是这些需要尽可能避免的情形之一。&lt;&#x2F;p&gt;
&lt;p&gt;西方讨论日本人的忠诚时大多不切实际，因为他们没有意识到道义并不仅仅是忠诚；作为一种德行，它在特定条件下会要求背叛。恰如其所言，“挨打的人会变反叛”，受辱则同理。&lt;&#x2F;p&gt;
&lt;p&gt;但是不管日本人从传统上多么推崇复仇，只要考察一下近代日本的生活实录、小说和活动就能发现，复仇故事在今天的日本并不比西方国家多，说不定还更少一些。与其说这意味着日本人对名誉的执著减弱了，还不如说他们对侮辱和诋毁的反应更多地从攻击型变为防守型。&lt;&#x2F;p&gt;
&lt;p&gt;在过去的两代人里，每当日本人觉得“世界失去平衡”，或者“等号两边的项”不等，或者需要“晨浴”来擦去污秽时，他们越来越倾向于毁灭自己，而不是他人。&lt;&#x2F;p&gt;
&lt;p&gt;日本人典型的情绪不稳定是从极端的专注一下子变成极端的厌倦，这种日本传统方式的精神崩溃让不少日本知识分子备受折磨。&lt;&#x2F;p&gt;
&lt;p&gt;但这的确是同一个民族。他们的反应是典型的。从极度的努力到消磨时光，对他们来说这是再自然不过的情绪转换。此刻日本人关心的主要是如何在战败的情况下维护自己的名誉，他们觉得表示友好就能实现这一目标。推论下来，很多人觉得最安全的做法就是依赖美国。再进一步，就有了努力会招来怀疑的想法，还不如消磨时光。消沉态度就这样传开来。&lt;&#x2F;p&gt;
&lt;p&gt;名誉是日本人永久的追求。这是赢得别人尊敬的必要条件。为了实现这一目标所采取的手段则可以视时机而定。一旦情况有变，日本人就会改变姿态，重新选择道路。他们和西方人不同，并不把变化立场当作道德问题来看。&lt;&#x2F;p&gt;
&lt;p&gt;在诸多维护名誉的手段中，他们只看到了复仇和好斗这一醒目的传统方式，而没有考虑到日本人另辟蹊径的习惯。他们误把日本的攻击性道德体系等同于欧洲的模式。根据欧洲模式，任何个人或民族要开战，必须先坚信永恒的正义站在自己这一边，并从憎恨和义愤里汲取力量。&lt;&#x2F;p&gt;
&lt;p&gt;日本人则用另一种方式产生攻击力。他们迫切需要得到全世界的尊重。&lt;&#x2F;p&gt;
&lt;p&gt;这种随机应变的现实主义是日式“对名声的道义”的光明面。道义就像月亮一样，有光明的一面，也有阴暗的一面。其阴暗面驱使日本人把美国的限制移民法案和海军裁军条约看作是对日本民族的莫大侮辱，进而把日本推向了灾难性的战争计划。其光明面又使日本能够在1945年带着友好的意愿接受投降的后果。日本依然是在按本色行事。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-jiu-zhang-ren-qing-jie&quot;&gt;第九章 人情界&lt;&#x2F;h3&gt;
&lt;p&gt;尽管日本是世界上的佛教大国之一，它的道德准则却和释迦及佛经的教诲形成鲜明对比。日本人并不谴责自我满足，他们不是清教徒。他们认为肉体的快感是件好事，值得培养。日本人追求并重视享受，但是享受要有度，不能影响生活里的正事。&lt;&#x2F;p&gt;
&lt;p&gt;日本人对此就有不同看法。选择配偶时年轻人要服从父母的安排盲婚盲嫁。和妻子相处必须相敬如宾。在互相迁就的家庭生活里，孩子们也看不到父母之间有丝毫情欲的表现。正如一个当代的日本人在一本杂志里所说：“在这个国家里，婚姻的真正目的是生儿育女，传宗接代。任何其他目的都只会曲解这一真谛。”&lt;&#x2F;p&gt;
&lt;p&gt;对于自体性欲这种乐趣他们并不觉得有罪恶感，在他们看来，这种乐趣在体面的生活中没有什么地位，这样就足以控制它了。&lt;&#x2F;p&gt;
&lt;p&gt;饮酒是种令人愉悦的消遣，醉酒者的家人和公众都不会觉得他讨厌。他一般不会有什么暴力倾向，至少没有人觉得他会把孩子暴揍一顿。但痛哭一场是常见的，放浪形骸则更普遍。在城市里的酒席上，男人们还喜欢坐在彼此的大腿上。&lt;&#x2F;p&gt;
&lt;p&gt;精神和肉体并不是普遍存在的两股对抗力量，日本人从这一信条导出了逻辑性的结论：世界并不是善与恶的战场。乔治·桑塞姆爵士这样写道：“贯穿整个日本史，日本人似乎都没有发展出辨别罪恶的能力，也许他们是不想去解决恶这个问题。”[6]事实上日本人一直把这一点当作人生观来驳斥。&lt;&#x2F;p&gt;
&lt;p&gt;对日本观众来说，看到银幕上的人为了报恩倾尽所有就已经满足了。因此这些电影在日本就是军国主义者的宣传工具。赞助者们知道此类电影不会激起日本观众的反战情绪。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-shi-zhang-de-zhi-liang-nan&quot;&gt;第十章 德之两难&lt;&#x2F;h3&gt;
&lt;p&gt;他们通常用自己的性格塑造出一个“完全形态”[1]。人生在世，这样才有秩序。&lt;&#x2F;p&gt;
&lt;p&gt;我们的主人公之所以是好人正是因为他们“选择了自己善良的那一半”，与为恶的敌人作斗争。正如我们所说，“美德必胜”。幸福的结局理所当然，善良的人应该得到奖励。日本人百听不厌的却是这类“反面事例”：主人公既迫于社会，又迫于名声，不能两全，最终只能选择一死了之。&lt;&#x2F;p&gt;
&lt;p&gt;日本人在评判自己或者熟人的生活时用的是同样的标准。在意愿和责任发生矛盾时，一个人如果关注了自己的意愿，他就被看作是弱者。日本人在各种场合都使用这种判断方法，但是和西方道德最背道而驰的是男人对妻子的态度。&lt;&#x2F;p&gt;
&lt;p&gt;在“孝界”，父母是中心，妻子只处于边缘地位，因此他的责任非常明确。如果母亲要他休妻，一个有着强烈道德感的人必须服从孝，接受母亲的决定。如果他爱着妻子，或者妻子为他生有孩子，那么他的服从就显得他更为“坚强”。&lt;&#x2F;p&gt;
&lt;p&gt;不了解日本的义务系统是没法理解敕谕里的“戒”的。整道敕谕都是官方为了弱化道义并拔高忠而做出的努力。全文中没有出现过一次日本人通常意义上的“道义”一词。作为替代，它强调大节为忠，“守信于私”乃是小节。&lt;&#x2F;p&gt;
&lt;p&gt;按照日本人的用法，“诚”的一个基本含义是对遵循日本伦理规范和日本精神的热忱。不管“诚”在特定语境里有什么特殊意义，都可以当作是在赞扬大家都认同的某些“日本精神”，或者是称赞那些广为接受的道德规范。&lt;&#x2F;p&gt;
&lt;p&gt;同理，“诚”把日本道德规范中的任何条款都提升到更高的高度。它不再是单独的一种品德，而是狂热分子对信条的热忱。&lt;&#x2F;p&gt;
&lt;p&gt;这些在美国的日本人觉得自己像被移植过的盆景一样，再也无法装点日本园林，因为无法再适应原来的要求。他们的经历最深刻地体现了日本道德的进退两难之境。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-shi-yi-zhang-zi-wo-xun-lian&quot;&gt;第十一章 自我训练&lt;&#x2F;h3&gt;
&lt;p&gt;美国人眼中为别人做出的巨大“牺牲”，在另外一些文化看来不过是有来有往的交换。它们要不就是一种投资，日后可以收回，要不就是对以前收益的回报。&lt;&#x2F;p&gt;
&lt;p&gt;在日本，为他人服务的制约力当然是互相往来，往来的可以是同类事物，也可以是不同等级但形成互补的责任。因此，自我牺牲在日本的道德地位与在美国相比有很大不同。日本人一直特别反对基督教传教士关于牺牲的布道。他们的论点是一个好人不应该把为他人服务当作是委屈自己。“&lt;&#x2F;p&gt;
&lt;p&gt;日本人表达这一信条最为极端的方式，至少在西方人听来如此，就是他们如何盛赞“像已死之人一样生活”的人。西方的字面翻译应该是“活尸”，而在任何西方语言中，“活尸”都是表达恐怖的意思。我们用这种方式来形容一个人的自我已死，徒留躯体在世。他不再遵循生命的法则。日本人用“像已死之人一样生活”来形容一个人处于“通”的境界。这句话被用于日常勉励。&lt;&#x2F;p&gt;
&lt;p&gt;用西方人的话说，日本人训练“无我”和“像已死之人一样生活”就是消灭了自己的良心。他们所称的“观察的自我”，“干扰的自我”，其实是对自己行为进行评判的审查者。这里有个例子生动地说明了东西方心理学之间的差异：当我们说到没有良心的美国人时，我们指这个人不再为干了坏事而产生本应产生的罪恶感；但是当日本人使用同类用语时，他的意思是说那个人不再紧张畏缩。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-shi-er-zhang-er-tong-de-xue-xi&quot;&gt;第十二章 儿童的学习&lt;&#x2F;h3&gt;
&lt;p&gt;日本的人生轨迹与美国的恰好相反。它是个大大的浅底U字，婴儿和老人享有最大程度的自由和纵容。婴儿期一过，限制就渐渐多了起来，自主能力在结婚前后降至最低线。&lt;&#x2F;p&gt;
&lt;p&gt;然而，事实证明，尽管美国和日本对人生轨迹的安排绝然不同，但是事实上两者都同样保证了各自的个体在青壮年时期都精力充沛地参与了自己的文化。&lt;&#x2F;p&gt;
&lt;p&gt;自我牺牲是日本人经常反对的基督教义之一；他们拒绝承认自己是在做出自我牺牲。即使是在极端的例子里，日本人也宁愿说是为了尽忠、尽孝或尽道义而“自愿”赴死，在他们看来，这不属于自我牺牲的范畴。据他们说，这样的自愿赴死是完成了自己的心愿。不然就是“犬之死”，意指死得没有价值，而不是像英语里那样，意指潦倒地死在街头。&lt;&#x2F;p&gt;
&lt;p&gt;谨慎的教导经常使他们在战斗中显得怯懦，但是他们勇猛起来又近于鲁莽。他们在等级分明的情况下表现出极度的顺从，但是又不轻易服从上级的管教。尽管他们礼貌周到，却也会心存傲慢。他们能够接受军队里的超严纪律，同时却又桀骜不驯。他们可以对保守主义充满激情，却又被新道路所吸引，相继引进中国习俗和西方知识就是佐证。&lt;&#x2F;p&gt;
&lt;p&gt;但是日本人对自己的要求太高。为了避免被排斥和责难，他们必须放弃刚刚学会品味的个人享受。在人生的重大事务中，他们必须牢牢克制住这些冲动。背离这一模式的人自己都会看不起自己。那些真正“自重”的人并不是在“善”与“恶”之间寻找前进的方向，而是在“期望之中的人”和“出乎意料的人”之间选择道路，并为了集体的“期望”葬送了个人的要求。这些是“知耻”、慎行的好人。正是这些人给家庭、村子和国家带来荣誉&lt;&#x2F;p&gt;
&lt;p&gt;今天日本人提出西方意义上的“放下刀”，但是在日本的意义上，他们有毅力保持内心之刀不染铁锈，尽管锈蚀的威胁一直存在。作为德行的另一种表述方式，刀是一种象征，在一个更加自由和平的世界里可以继续保留。&lt;&#x2F;p&gt;
&lt;h3 id=&quot;di-shi-san-zhang-zhan-bai-hou-de-ri-ben-ren&quot;&gt;第十三章 战败后的日本人&lt;&#x2F;h3&gt;
&lt;p&gt;日本的真正力量在于它能够承认一种行动路线“失败了”，然后全力投入到其他路线中去。日本可以凭借这种力量重新把自己建设成爱好和平的国家。日本人的道德体系允许多项选择。他们试图在战争中找到自己的“恰当地位”，但是他们失败了。现在他们可以抛弃那条路线，因为他们一直以来受到的训练就使他们习惯了改变方向。&lt;&#x2F;p&gt;
&lt;p&gt;日本人把行动路线没有达到目标看成是自己犯了一个“错误”。路线一旦失败就被放弃，因为日本人不习惯坚持失败的路线。他们有种说法，“咬自己的肚脐没有用”。二十世纪三十年代，日本人普遍认为能借军事主义赢得世界的钦佩——一种靠强大的军事实力争取来的钦佩——于是他们心甘情愿地为这一计划做出牺牲。&lt;&#x2F;p&gt;
&lt;p&gt;日本的社论反复强调“日本必须得到世界各国的尊重”，日本人民的任务就是在新的基础上赢得这种尊重。&lt;&#x2F;p&gt;
&lt;p&gt;因此，对俄胜利和在菲律宾对美的胜利例证了日本人行为中的两个对立面：受到侮辱时是一面；无关侮辱时又是另一面。&lt;&#x2F;p&gt;
&lt;p&gt;民族主义的秘密团体在日本由来已久，他们为日本“洗清污名”。日本的男人接受的教育是为了报仇必须竭尽所能，否则“世界就会失去平衡”，所以他们极有可能加入这样的地下团体。像黑龙会、玄洋社之类的秘密团体所宣扬的暴力，以“对名声的道义”为名，这是日本道德所允许的。日本政府长期以来一直强调义务，忽略“对名声的道义”，而为了根除暴力，这种努力在往后若干年里还需继续下去。&lt;&#x2F;p&gt;
&lt;p&gt;日本如果不把军事化纳入预算，只要他们愿意，用不了多少年就可以奠定繁荣的基础，并成为东方贸易不可或缺的一分子。日本可以凭借和平时期的获利奠定经济基础，提高国民的生活水平。这样一个和平的日本将在世界各国中占有光荣的一席，如果美国继续动用自己的影响力支持日本的这项计划，将是对日本的很大帮助。&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
</description>
      </item>
      <item>
          <title>5 Things To Do For Career Development As a Software Engineer</title>
          <pubDate>Sun, 24 May 2020 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/five-things-to-do-as-software-engineer/</link>
          <guid>https://usegitflow.com/posts/five-things-to-do-as-software-engineer/</guid>
          <description xml:base="https://usegitflow.com/posts/five-things-to-do-as-software-engineer/">&lt;p&gt;Software engineers and developers are fortunate when they land an ideal job and settle into a company they enjoy, drawing a comfortable pay packet for interesting work. However, it’s also quite common that during our spare time, we may ask ourselves a question: what should we do to help our career development? Sooner or later, this question appears in every software engineering professional’s mind.&lt;&#x2F;p&gt;
&lt;p&gt;Today, let’s talk about what we should do when we do not intend to look for a job and change our current career life immediately. Most of the ideas come from the book &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pragprog.com&#x2F;book&#x2F;algh&#x2F;land-the-tech-job-you-love&quot;&gt;Land the Tech Job You Love&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;1-teaching-your-knowledge-to-other-people&quot;&gt;1. Teaching your knowledge to other people&lt;&#x2F;h3&gt;
&lt;p&gt;Teaching and sharing are always excellent ways to improve your learning and make your knowledge base more solid. When trying to teach a concept to others, you need to gain your audience’s interest in what you’re talking about. It would be best if you had a clear understanding of where the concept is in the big picture, and you have to figure out how to let a newbie get their hands dirty without getting too confused and losing interest.&lt;&#x2F;p&gt;
&lt;p&gt;An audience may come up with questions that you never thought of. You should be prepared to answer them with as much scope as you’re familiar with, or have a friendly discussion and learn something new yourself.&lt;&#x2F;p&gt;
&lt;p&gt;Sharing your knowledge with the community could also help you expand your social network and amplify your influence, which can show its worth in the future.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;2-starting-a-blog&quot;&gt;2. Starting a blog&lt;&#x2F;h3&gt;
&lt;p&gt;It sounds cool, and it is cool, to have a place people can find when they look for you on the Internet. Since a resume can only be one page long, filled with your education and job experience, what you can show to potential future employers is quite limited. But imagine that when people are easily linked to your blog (after you’ve done some SEO) and can go through your thinking by reading the recent 3-5 posts, they can gain much more insight about you.&lt;&#x2F;p&gt;
&lt;p&gt;Of course, here we’re talking about a tech-related blog that deals with what value you can offer an employer. We can blog about anything that we might tell a techie buddy about at lunch or over beers after work. There are plenty of discussions online about how to build an excellent tech blog. Another book &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pragprog.com&#x2F;book&#x2F;actb2&#x2F;technical-blogging-second-edition&quot;&gt;Technical Blogging, Second Edition&lt;&#x2F;a&gt; can be a step-by-step guide to plan, create, maintain, and promote a successful blog as a developer.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;3-learning-new-things-and-writing-them-down&quot;&gt;3. Learning new things, and writing them down&lt;&#x2F;h3&gt;
&lt;p&gt;Any software engineer or technical professional is in an industry that is continuously innovating and frequently adding new features and capabilities to the world around us. If you’re not learning something new, you’re falling behind the competition, or at least feeling that you have.&lt;&#x2F;p&gt;
&lt;p&gt;However, there are numerous things to learn in the IT industry whose resources can be very easily accessed. It’s just a matter of whether you have the willingness to learn or not (sounds like another cliche). But here I’d like to mention that another step is quite essential: share what you’ve learned. By writing down or doing some tech sharing, what you’ve learned can become what you know. The new knowledge I mention here can be:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;A new programming language&lt;&#x2F;li&gt;
&lt;li&gt;A new framework in the language you’re familiar with&lt;&#x2F;li&gt;
&lt;li&gt;A new OS&lt;&#x2F;li&gt;
&lt;li&gt;New hardware made for programming&lt;&#x2F;li&gt;
&lt;li&gt;Other companies’ best practice&lt;&#x2F;li&gt;
&lt;li&gt;Even another industry radically different from what we know, but which shares similarities with our industry and can teach us some lessons&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Whatever you’ve absorbed can be transformed into new knowledge that may be beneficial to yourself and innovative to other colleagues. Continually investing in learning and sharing what you’ve learned pays much bigger dividends.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;4-updating-your-resume-every-three-months&quot;&gt;4. Updating your resume every three months&lt;&#x2F;h3&gt;
&lt;p&gt;Add ‘update my resume’ into your calendar and set the interval as every three months. Almost whenever we open the resume after some time, we can find things to add in or to improve on. It could be a job promotion (congrats!), or it could be a new job responsibility or a new project that your team is now working on. It can also be something not done in your office, but an open-source project you are actively contributing to. Whatever adds value to your company and yourself should be added to your resume.&lt;&#x2F;p&gt;
&lt;p&gt;If you cannot find anything worth adding to your resume for six months or so, treat it as a warning. Your career progress has probably stalled, and your skills may be going rusty. It is a good moment to consider looking for more challenges, maybe by switching jobs, or by proactively seeking new challenges and taking on more responsibilities. As the book &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pragprog.com&#x2F;book&#x2F;algh&#x2F;land-the-tech-job-you-love&quot;&gt;Land the Tech Job You Love&lt;&#x2F;a&gt; says, “Lather, rinse, repeat.”&lt;&#x2F;p&gt;
&lt;h3 id=&quot;5-growing-your-network-and-jumping-out-of-your-comfort-zone&quot;&gt;5. Growing your network and jumping out of your comfort zone&lt;&#x2F;h3&gt;
&lt;p&gt;It is all too familiar: software engineers spend at least 70% of their time in an IDE and would rather not spend effort talking to people. Some developers are not keen to communicate and feel more comfortable letting the code talk. That said, maintaining a reliable professional network can matter as much as any other area of self-improvement (like sections 1-4 above). You might have the best skills, but they’re not much good if your ideal employers can’t easily find that out.&lt;&#x2F;p&gt;
&lt;p&gt;Here are some handy tips we can take up gradually, starting next Monday when we walk into the office.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Have lunch with people outside your team, and get to know them&lt;&#x2F;li&gt;
&lt;li&gt;Join the office’s interest group, and break the invisible wall between engineers and non-engineers&lt;&#x2F;li&gt;
&lt;li&gt;Join a local tech community in your area of expertise, like &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.meetup.com&#x2F;GraphQL-SG&#x2F;&quot;&gt;GraphQL Singapore&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Join user groups in areas you’re not familiar with but would like to learn about&lt;&#x2F;li&gt;
&lt;li&gt;Keep track of your connections’ updates, and stay updated about their vital information&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;5-questions-for-self-checking&quot;&gt;5 questions for self-checking&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;As technical professionals, we are blessed to have the skills to be well paid for jobs that we love. Not just like, but love. Please don’t settle for anything less.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Here are five questions that a software engineer or IT professional can ask themselves regularly.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Is my resume up-to-date?&lt;&#x2F;li&gt;
&lt;li&gt;Am I competitive in the current job market?&lt;&#x2F;li&gt;
&lt;li&gt;Am I able to be found online with an insightful presence?&lt;&#x2F;li&gt;
&lt;li&gt;Do I have at least five people to approach when I’m seeking help to find my next job?&lt;&#x2F;li&gt;
&lt;li&gt;Do I have at least three references who can speak for my work experience and ability?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h5 id=&quot;recommended-books-for-software-engineer-career-development&quot;&gt;Recommended books for software engineer career development&lt;&#x2F;h5&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pragprog.com&#x2F;book&#x2F;algh&#x2F;land-the-tech-job-you-love&quot;&gt;Land the Tech Job You Love&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pragprog.com&#x2F;book&#x2F;actb2&#x2F;technical-blogging-second-edition&quot;&gt;Technical Blogging, Second Edition&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pragprog.com&#x2F;book&#x2F;tpp20&#x2F;the-pragmatic-programmer-20th-anniversary-edition&quot;&gt;The Pragmatic Programmer, 20th Anniversary Edition&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</description>
      </item>
      <item>
          <title>Some pragmatic notes for programmers (part 2)</title>
          <pubDate>Sun, 15 Dec 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/some-pragmatic-notes-part-2/</link>
          <guid>https://usegitflow.com/posts/some-pragmatic-notes-part-2/</guid>
          <description xml:base="https://usegitflow.com/posts/some-pragmatic-notes-part-2/">&lt;p&gt;Extracted some interesting points from the book &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.amazon.com&#x2F;gp&#x2F;product&#x2F;0135957052&quot;&gt;“The Pragmatic Programmer: your journey to mastery, 20th Anniversary Edition, 2nd Edition”&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;7-while-you-are-coding&quot;&gt;7. While You Are Coding&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;Perhaps there’s an element of imposter syndrome, too; we may think that this project is beyond us. We can’t see our way through to the end; we’ll get so far and then be forced to admit that we’re lost.&lt;&#x2F;li&gt;
&lt;li&gt;If that’s not working, try externalizing the issue. Make doodles about the code you’re writing, or explain it to a coworker (preferably one who isn’t a programmer), or to your rubber duck. Expose different parts of your brain to the issue, and see if any of them have a better handle on the thing that’s troubling you. We’ve lost track of the number of conversations we’ve had where one of us was explaining a problem to the other and suddenly went “Oh! Of course!” and broke off to fix it.&lt;&#x2F;li&gt;
&lt;li&gt;We should avoid programming by coincidence—relying on luck and accidental successes—in favor of programming deliberately.&lt;&#x2F;li&gt;
&lt;li&gt;For code you write that others will call, the basic principles of good modularization and of hiding implementation behind small, well-documented interfaces can all help. A well-specified contract (see Topic 23, ​Design by Contract​) can help eliminate misunderstandings.&lt;&#x2F;li&gt;
&lt;li&gt;Don’t code in the dark. Build an application you don’t fully grasp, or use a technology you don’t understand, and you’ll likely be bitten by coincidences. If you’re not sure why it works, you won’t know why it fails.&lt;&#x2F;li&gt;
&lt;li&gt;Rely only on reliable things. Don’t depend on assumptions. If you can’t tell if something is reliable, assume the worst.&lt;&#x2F;li&gt;
&lt;li&gt;Don’t be a slave to history. Don’t let existing code dictate future code. All code can be replaced if it is no longer appropriate. Even within one program, don’t let what you’ve already done constrain what you do next—be ready to refactor (see Topic 40, ​Refactoring​). This decision may impact the project schedule. The assumption is that the impact will be less than the cost of not making the change.&lt;&#x2F;li&gt;
&lt;li&gt;You refactor when you’ve learned something; when you understand something better than you did last year, yesterday, or even just ten minutes ago.&lt;&#x2F;li&gt;
&lt;li&gt;In order to guarantee that the external behavior hasn’t changed, you need good, automated unit testing that validates the behavior of the code.&lt;&#x2F;li&gt;
&lt;li&gt;Don’t try to refactor and add functionality at the same time.&lt;&#x2F;li&gt;
&lt;li&gt;Make sure you have good tests before you begin refactoring. Run the tests as often as possible. That way you will know quickly if your changes have broken anything.&lt;&#x2F;li&gt;
&lt;li&gt;Testing Is Not About Finding Bugs.&lt;&#x2F;li&gt;
&lt;li&gt;We strongly believe that the only way to build software is incrementally. Build small pieces of end-to-end functionality, learning about the problem as you go.&lt;&#x2F;li&gt;
&lt;li&gt;A culture of testing means all the tests pass all the time. Ignore a spew of tests that “always fail” makes it easier to ignore all the tests, and the vicious spiral begins.&lt;&#x2F;li&gt;
&lt;li&gt;Make no mistake, testing is part of programming. It’s not something left to other departments or staff. Testing, design, coding—it’s all programming.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;8-before-the-project&quot;&gt;8. Before the Project&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;No One Knows Exactly What They Want.&lt;&#x2F;li&gt;
&lt;li&gt;whenever you create something, you need to pause and think “what is my motivation to create this?”.&lt;&#x2F;li&gt;
&lt;li&gt;Requirements rarely lie on the surface. Normally, they’re buried deep beneath layers of assumptions, misconceptions, and politics. Even worse, often they don’t really exist at all.&lt;&#x2F;li&gt;
&lt;li&gt;Programmers Help People Understand What They Want.&lt;&#x2F;li&gt;
&lt;li&gt;This is both an intellectual process and a creative one: you’re thinking on your feet and you’re contributing to a solution that is likely to be better than one that either you or the client would have produced alone.&lt;&#x2F;li&gt;
&lt;li&gt;Requirements are not architecture. Requirements are not design, nor are they the user interface. Requirements are need.&lt;&#x2F;li&gt;
&lt;li&gt;Create and maintain a project glossary—one place that defines all the specific terms and vocabulary used in a project.&lt;&#x2F;li&gt;
&lt;li&gt;Organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations.&lt;&#x2F;li&gt;
&lt;li&gt;Having a second developer’s full brain available during the task brings a lot more mental power to bear.&lt;&#x2F;li&gt;
&lt;li&gt;Build the code, not your ego. It’s not about who’s brightest; we all have our moments, good and bad.&lt;&#x2F;li&gt;
&lt;li&gt;Criticise the code, not the person. “Let’s look at this block” sounds much better than “you’re wrong.”&lt;&#x2F;li&gt;
&lt;li&gt;Listen and try to understand others’ viewpoints. Different isn’t wrong.&lt;&#x2F;li&gt;
&lt;li&gt;Conduct frequent retrospectives to try and improve for next time.&lt;&#x2F;li&gt;
&lt;li&gt;Don’t Go into the Code Alone&lt;&#x2F;li&gt;
&lt;li&gt;Individuals and interactions over processes and tools. Working software over comprehensive documentation. Customer collaboration over contract negotiation.Responding to change over following a plan.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;9-pragmatic-projects&quot;&gt;9. Pragmatic Projects&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;Programmers are a bit like cats: intelligent, strong willed, opinionated, independent, and often worshiped by the net.&lt;&#x2F;li&gt;
&lt;li&gt;Stay awake and aware for increased scope, decreased time scales, additional features, new environments—anything that wasn’t in the original understanding. Keep metrics on new requirements.&lt;&#x2F;li&gt;
&lt;li&gt;Great project teams have a distinct personality. People look forward to meetings with them, because they know that they’ll see a well-prepared performance that makes everyone feel good.&lt;&#x2F;li&gt;
&lt;li&gt;Maintain awareness to stay DRY.&lt;&#x2F;li&gt;
&lt;li&gt;Does it work well for you? Or was it adopted just because it was being used by the latest internet-fueled success story?&lt;&#x2F;li&gt;
&lt;li&gt;Do What Works, Not What’s Fashionable&lt;&#x2F;li&gt;
&lt;li&gt;the idea of the Pragmatic Starter Kit was born, covering these three critical and interrelated topics: Version Control, Regression Testing, Full Automation.&lt;&#x2F;li&gt;
&lt;li&gt;You deliver when the users need it, when it makes business sense to do so.&lt;&#x2F;li&gt;
&lt;li&gt;Pragmatic Programmers are different. We are driven to find our bugs now, so we don’t have to endure the shame of others finding our bugs later.&lt;&#x2F;li&gt;
&lt;li&gt;Test Early, Test Often, Test Automatically&lt;&#x2F;li&gt;
&lt;li&gt;In fact, a good project may well have more test code than production code. The time it takes to produce this test code is worth the effort. It ends up being much cheaper in the long run, and you actually stand a chance of producing a product with close to zero defects.&lt;&#x2F;li&gt;
&lt;li&gt;A bug-free system that answers the wrong question isn’t very useful.&lt;&#x2F;li&gt;
&lt;li&gt;But it’s these expectations of business value that really count—not just the software project itself. The software is only a means to these ends.&lt;&#x2F;li&gt;
&lt;li&gt;Even though your title might be some variation of “Software Developer” or “Software Engineer,” in truth it should be “Problem Solver.” That’s what we do, and that’s the essence of a Pragmatic Programmer.&lt;&#x2F;li&gt;
&lt;li&gt;The Golden Rule (“Do unto others as you would have them do unto you’’) and a foundation of mutual respect among the developers is critical to make this tip work.&lt;&#x2F;li&gt;
&lt;li&gt;It’s Your Life. Share it. Celebrate it. Build it. AND HAVE FUN!&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</description>
      </item>
      <item>
          <title>Some pragmatic notes for programmers (part 1)</title>
          <pubDate>Sun, 08 Dec 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/some-pragmatic-notes/</link>
          <guid>https://usegitflow.com/posts/some-pragmatic-notes/</guid>
          <description xml:base="https://usegitflow.com/posts/some-pragmatic-notes/">&lt;p&gt;Keep a record of some highlights from the book &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.amazon.com&#x2F;gp&#x2F;product&#x2F;0135957052&quot;&gt;“The Pragmatic Programmer: your journey to mastery, 20th Anniversary Edition, 2nd Edition”&lt;&#x2F;a&gt; which might be useful to me, or to your Software Engineer career path.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;what-makes-a-pragmatic-programmer&quot;&gt;What makes a pragmatic programmer?&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;Over the long term, your time investment will be repaid as you and your team become more efficient, write code that’s easier to maintain, and spend less time in meetings.&lt;&#x2F;li&gt;
&lt;li&gt;You rarely take things as given without first getting the facts. When colleagues say “because that’s the way it’s done,” or a vendor promises the solution to all your problems, you smell a challenge.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;We who cut mere stones must always be envisioning cathedrals.&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Every day, work to refine the skills you have and to add new tools to your repertoire.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;1-a-pragmatic-philosophy-software-entropy&quot;&gt;1. A Pragmatic Philosophy &amp;amp;&amp;amp; Software Entropy&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;When you find yourself saying, “I don’t know,” be sure to follow it up with “—but I’ll find out.” It’s a great way to admit what you don’t know, but then take responsibility like a pro.&lt;&#x2F;li&gt;
&lt;li&gt;Before you approach anyone to tell them why something can’t be done, is late, or is broken, stop and listen to yourself. Talk to the rubber duck on your monitor, or the cat.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Don’t leave “broken windows’’ (bad designs, wrong decisions, or poor code) unrepaired. Fix each one as soon as it is discovered. If there is insufficient time to fix it properly, then board it up.&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;It’s time to bring out the stones. Work out what you can reasonably ask for. Develop it well. Once you’ve got it, show people, and let them marvel. Then say “of course, it would be better if we added…’’ Pretend it’s not important. Sit back and wait for them to start asking you to add the functionality you originally wanted. People find it easier to join an ongoing success. Show them a glimpse of the future and you’ll get them to rally around.&lt;&#x2F;li&gt;
&lt;li&gt;If you give your users something to play with early, their feedback will often lead you to a better eventual solution.&lt;&#x2F;li&gt;
&lt;li&gt;Talking to other people will help build your personal network, and you may surprise yourself by finding solutions to other, unrelated problems along the way. And that old portfolio just keeps getting bigger.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;The more different things you know, the more valuable you are.&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Know what you want to say. Know your audience. Choose your moment. Choose a style. Make it look good. Involve your audience. Be a listener. Get back to people. Keep code and documentation together.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;if you don’t listen to them, they won’t listen to you.&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Treat English (or whatever your native tongue may be) as just another programming language. Write natural language as you would write code: honor the DRY principle, ETC, automation, and so on.&lt;&#x2F;li&gt;
&lt;li&gt;A good idea is an orphan without effective communication.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;2-a-pragmatic-approach&quot;&gt;2. A Pragmatic Approach&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;In the modern world, it’s critical to test ideas and get feedback before you commit to them whole-heartedly.&lt;&#x2F;li&gt;
&lt;li&gt;We feel that the only way to develop software reliably, and to make our developments easier to understand and maintain, is to follow what we call the DRY principle: &lt;strong&gt;Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Don’t rely on the properties of things you can’t control.&lt;&#x2F;li&gt;
&lt;li&gt;Requirements, users, and hardware change faster than we can get the software developed.&lt;&#x2F;li&gt;
&lt;li&gt;The distinction is important enough to warrant repeating. Prototyping generates disposable code. Tracer code is lean but complete, and forms part of the skeleton of the final system. Think of prototyping as the reconnaissance and intelligence gathering that takes place before a single tracer bullet is fired.&lt;&#x2F;li&gt;
&lt;li&gt;Our suggestion is fairly simple: don’t spend more effort than you save. Writing a domain language adds some cost to your project, and you’ll need to be convinced that there are offsetting savings (potentially in the long term).&lt;&#x2F;li&gt;
&lt;li&gt;Use paper, not a file or a wiki: there’s something special about the act of writing compared to typing. Give it a month, and see if you’re getting any benefits.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;3-pragmatic-paranoia&quot;&gt;3. Pragmatic Paranoia&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;But Pragmatic Programmers take this a step further. They don’t trust themselves, either. Knowing that no one writes perfect code, including themselves, Pragmatic Programmers build in defenses against their own mistakes.&lt;&#x2F;li&gt;
&lt;li&gt;The finish what you start tip tells us that, ideally, the routine that allocates a resource should also free it.&lt;&#x2F;li&gt;
&lt;li&gt;Much of the time, tomorrow looks a lot like today. But don’t count on it.&lt;&#x2F;li&gt;
&lt;li&gt;Let’s look at four strategies that help.&lt;&#x2F;li&gt;
&lt;li&gt;Finite State Machines&lt;&#x2F;li&gt;
&lt;li&gt;The Observer Pattern&lt;&#x2F;li&gt;
&lt;li&gt;Publish&#x2F;Subscribe&lt;&#x2F;li&gt;
&lt;li&gt;Reactive Programming and Streams&lt;&#x2F;li&gt;
&lt;li&gt;Let us suggest three techniques that mean you should never need to use inheritance again:&lt;&#x2F;li&gt;
&lt;li&gt;Interfaces and protocols&lt;&#x2F;li&gt;
&lt;li&gt;Delegation&lt;&#x2F;li&gt;
&lt;li&gt;Mixins and traits&lt;&#x2F;li&gt;
&lt;li&gt;We still want configuration data kept external to the application, but rather than in a flat file or database, we’d like to see it stored behind a service API. This has a number of benefits:&lt;&#x2F;li&gt;
&lt;li&gt;Multiple applications can share configuration information, with authentication and access control limiting what each can see&lt;&#x2F;li&gt;
&lt;li&gt;Configuration changes can be made globally&lt;&#x2F;li&gt;
&lt;li&gt;The configuration data can be maintained via a specialized UI&lt;&#x2F;li&gt;
&lt;li&gt;The configuration data becomes dynamic&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</description>
      </item>
      <item>
          <title>Some LeetCode Contest in Rust</title>
          <pubDate>Sat, 26 Oct 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/leetcode-contest-rust/</link>
          <guid>https://usegitflow.com/posts/leetcode-contest-rust/</guid>
          <description xml:base="https://usegitflow.com/posts/leetcode-contest-rust/">&lt;p&gt;As I’m learning Rust recently, LeetCode has become a good place to write small programs and to get familiar with Rust grammar and syntax. In the recent two contests, I tried using Rust to solve some problems; however, it took much longer than I expected to deal with the strict compiler. Pretty fun though, and I think it did help me get my hands dirty.&lt;&#x2F;p&gt;
&lt;p&gt;However, personally I won’t suggest using Rust in LeetCode contests or in real interviews as Python&#x2F;Ruby would be a much better choice. Rust could be useful in some other aspects which I’ll check later. (safety, speed, and concurrency? + WebAssembly)&lt;&#x2F;p&gt;
&lt;h3 id=&quot;1234-replace-the-substring-for-balanced-string&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-159&#x2F;problems&#x2F;replace-the-substring-for-balanced-string&#x2F;&quot;&gt;1234. Replace the Substring for Balanced String&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Keyword: &lt;strong&gt;Sliding window&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Use a counter to keep track of the appearances &lt;strong&gt;outside&lt;&#x2F;strong&gt; of the sliding window, and try to make the window as small as possible.&lt;&#x2F;p&gt;
&lt;p&gt;Rust solution:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;use&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; std&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;cmp;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;use&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; std&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;collections&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; balanced_string&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(s&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-storage&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; counter&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; HashMap&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; c&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;#39;Q&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;#39;W&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;#39;E&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; &amp;#39;R&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            counter&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;insert&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;*&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;c,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; c&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; s&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;chars&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; new_count&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; = match&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; counter&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;c) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;                Some&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;val)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; val&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;                None&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            counter&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;insert&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(c, new_count);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; s&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-storage&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; result&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; length;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; expected&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 4&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; j,&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0_&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0_&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        while&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; length {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; char_j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; s&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;chars&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;nth&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            counter&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;insert&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(char_j, counter&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;char_j)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;            &#x2F;&#x2F; sliding window&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            while&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; length&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; counter[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;#39;Q&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; expected&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; counter[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;#39;W&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; expected&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; counter[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;#39;E&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; expected&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; counter[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;&amp;#39;R&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; expected&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                    result&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; cmp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;min&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(result, j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;                    let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; char_i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; s&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;chars&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;nth&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                    counter&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;insert&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(char_i, counter&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;char_i)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                    i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;        result&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; tests&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    use&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language&quot;&gt; super&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; test&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; s&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;QWER&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Solution&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;balanced_string&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(s),&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; s&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;QQWE&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Solution&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;balanced_string&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(s),&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Some places in the code may be not necessary:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Update a counter’s value for a character, I’m using: &lt;code&gt;let char_j = s.chars().nth(j as usize).unwrap();&lt;&#x2F;code&gt; &lt;code&gt;counter.insert(char_j, counter.get(&amp;amp;char_j).unwrap() - 1);&lt;&#x2F;code&gt; which is actually the same as &lt;code&gt;counter[c] += 1&lt;&#x2F;code&gt; in Python. Seems too long in Rust.&lt;&#x2F;li&gt;
&lt;li&gt;For the place &lt;code&gt;while i &amp;lt; length &amp;amp;&amp;amp; counter[&amp;amp;&#x27;Q&#x27;] &amp;lt;= expected &amp;amp;&amp;amp; counter[&amp;amp;&#x27;W&#x27;] &amp;lt;= expected&lt;&#x2F;code&gt; &lt;code&gt;&amp;amp;&amp;amp; counter[&amp;amp;&#x27;E&#x27;] &amp;lt;= expected &amp;amp;&amp;amp; counter[&amp;amp;&#x27;R&#x27;] &amp;lt;= expected&lt;&#x2F;code&gt;, it would be &lt;code&gt;all([counter[x] &amp;lt;= expected for x in &#x27;QWER&#x27;])&lt;&#x2F;code&gt; in Python.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;1235-maximum-profit-in-job-scheduling&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-159&#x2F;problems&#x2F;maximum-profit-in-job-scheduling&#x2F;&quot;&gt;1235. Maximum Profit in Job Scheduling&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Keyword: &lt;strong&gt;DP&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Use [(ending_time, max_profit)] to keep track of possible best profit for each end time. For a new job, use &lt;strong&gt;binary search&lt;&#x2F;strong&gt; to find the possible previous ending time for the last job, and calculate whether the profit would be better than the current best (last element in the DP record); if so, append it to the end of the DP record vector.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt;{}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; job_scheduling&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(start_time&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;&amp;gt;, end_time&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;&amp;gt;, profit&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-storage&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; jobs&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; start_time&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;..&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;length {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            jobs&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;push&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;((start_time[i], end_time[i], profit[i]))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;        jobs&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;sort_by_key&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;|&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;t1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;|&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; t1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-storage&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;)];&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;  &#x2F;&#x2F; (ending, max_profit)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; (s, e, p)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; jobs {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; last_job_index&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; = match&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;binary_search_by_key&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;s,&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; |&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;t&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;|&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;                Ok&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(i)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;                Err&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(i)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; record[last_job_index]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; p&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;last&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;push&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;((e, record[last_job_index]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; p))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;        record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;last&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; tests&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    use&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language&quot;&gt; super&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; test1 () {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; starts&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;6&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; ends&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;6&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;9&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; profit&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;70&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;60&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Solution&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;job_scheduling&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(starts, ends, profit),&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 150&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;1223-dice-roll-simulation&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-158&#x2F;problems&#x2F;dice-roll-simulation&#x2F;&quot;&gt;1223. Dice Roll Simulation&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Keyword: &lt;strong&gt;Cache&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;To make it not TLE we use a cache to reduce time cost. However, in Rust, it happened to be the very first HashMap I used and cost me some time to deal with the compiler. I finally made it pass with the code below. The &lt;code&gt;&amp;lt;&#x27;a&amp;gt;&lt;&#x2F;code&gt; is an explicit lifetime which could be implicit.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;use&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; std&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;collections&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;&#x2F;&#x2F; struct Solution {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;type&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Cache&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; die_simulator&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;, roll_max&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-storage&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; cache&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Cache&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; HashMap&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; helper&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            k&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            number&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            roll_max&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            cache&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-storage&quot;&gt;: &amp;amp;mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Cache&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        )&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; key_string&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; format!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;{} {} {}&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;, k, number, n);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-keyword&quot;&gt;            let ref&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; key&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; key_string&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            match&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; cache&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;get&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;key) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;                Some&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;number)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&amp;gt; return&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; number,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                _&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-storage&quot;&gt;            let mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; temp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i64&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            for&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;..&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;6&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                if&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; number&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                    temp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; helper&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;, i, n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;, roll_max, cache)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i64&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; else if&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; roll_max[i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;] {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                    temp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; helper&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(k&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;, i, n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;, roll_max, cache)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i64&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; result&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; (temp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; %&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;10_&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;i64&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;pow&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;9&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 7&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            cache&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;insert&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(key_string, result);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;            result&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;        helper&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;, n,&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;roll_max,&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-storage&quot;&gt; &amp;amp;mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; cache)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;1240-tiling-a-rectangle-with-the-fewest-squares&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-160&#x2F;problems&#x2F;tiling-a-rectangle-with-the-fewest-squares&#x2F;&quot;&gt;1240. Tiling a Rectangle with the Fewest Squares&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Keyword: &lt;strong&gt;DP&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;It’s an interesting DP problem, as it only cares about &lt;code&gt;1&amp;lt;=n,m&amp;lt;=13&lt;&#x2F;code&gt; cases. For larger ranges, it would become very complicated; please check this &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;int-e.eu&#x2F;~bf3&#x2F;squares&#x2F;&quot;&gt;link&lt;&#x2F;a&gt; for more info.&lt;&#x2F;p&gt;
&lt;p&gt;Solution in Rust:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;use&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; std&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;cmp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;min;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; tiling_rectangle&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;, m&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-storage&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;; n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;]; m&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;        record[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;][&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;        &#x2F;&#x2F;special case&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; (n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 11&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; m&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 13&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; (n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 13&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; m&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 11&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 6&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;..&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;m&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            for&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;..&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; as&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                if&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                    record[i][j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                    continue&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                if&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; j {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                    record[i][j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                    continue&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type z-storage&quot;&gt;                let mut&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; temp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 13&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;*&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;13&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                for&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;..=&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;min&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(i, j) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                    temp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; min&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;(temp,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;                               min&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; record[i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;k][j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; record[k][j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;k],&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; record[i][j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;k]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; record[i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;k][k])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    );&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;                record[i][j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt; temp;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        *&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-other&quot;&gt;record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;last&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;last&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; tests&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    use&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language&quot;&gt; super&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; test&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Solution&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;tiling_rectangle&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Solution&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;tiling_rectangle&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 8&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;Solution&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;::&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt;tiling_rectangle&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;11&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 13&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 6&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</description>
      </item>
      <item>
          <title>Leetcode Contest 154, 155 - Graph</title>
          <pubDate>Mon, 16 Sep 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/leetcode-154/</link>
          <guid>https://usegitflow.com/posts/leetcode-154/</guid>
          <description xml:base="https://usegitflow.com/posts/leetcode-154/">&lt;h3 id=&quot;sort-items-by-groups-respecting-dependencies&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-155&#x2F;problems&#x2F;sort-items-by-groups-respecting-dependencies&#x2F;&quot;&gt;Sort Items by Groups Respecting Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it’s equal to -1 if the i-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Return a sorted list of the items such that:&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;The items that belong to the same group are next to each other in the sorted list.&lt;&#x2F;li&gt;
&lt;li&gt;There are some relations between these items where beforeItems[i] is a list containing all the items that should come before the i-th item in the sorted array (to the left of the i-th item).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Return any solution if there is more than one solution and return an empty list if there is no solution.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: &lt;strong&gt;Graph, Topological sort, DAG&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Topological sorting for a Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering. Topological Sorting for a graph is not possible if the graph is not a DAG. A directed graph doesn’t have topological sorting if and only if it contains a cycle.&lt;&#x2F;p&gt;
&lt;p&gt;In this problem, we need to do a cycle check and topological sorting between groups, and inside each group we need another check and topological sorting.&lt;&#x2F;p&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Get the &lt;code&gt;in_degree&lt;&#x2F;code&gt; map for groups and for items&lt;&#x2F;li&gt;
&lt;li&gt;Sort groups. By sorting here, we get all nodes whose in degree is 0 (which means no dependency), add them to a &lt;code&gt;stack&lt;&#x2F;code&gt; and update the in_degree map, and do the process again until there are no nodes. Then pop nodes from &lt;code&gt;stack&lt;&#x2F;code&gt; and get the topological sort result.&lt;&#x2F;li&gt;
&lt;li&gt;Sort inside each group&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Reference:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.geeksforgeeks.org&#x2F;topological-sorting&#x2F;&quot;&gt;Topological sorting&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;critical-connections-in-a-network&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;problems&#x2F;critical-connections-in-a-network&#x2F;&quot;&gt;Critical Connections in a Network&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;There are n servers numbered from 0 to n-1 connected by undirected server-to-server connections forming a network where connections[i] = [a, b] represents a connection between servers a and b. Any server can reach any other server directly or indirectly through the network.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;A critical connection is a connection that, if removed, will make some server unable to reach some other server.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Return all critical connections in the network in any order.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: &lt;strong&gt;Graph, DFS&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Basically it’s a DFS over all the nodes; the difficult part is to check whether an edge is a ‘critical connection’ or not. To define this edge &lt;code&gt;[a,b]&lt;&#x2F;code&gt;, it’s critical if and only if there is no other way for a to reach b except this edge (not in a cycle).&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.geeksforgeeks.org&#x2F;bridge-in-a-graph&#x2F;&quot;&gt;Another post to explain ‘Bridges in a graph’&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Tarjan%27s_strongly_connected_components_algorithm&quot;&gt;Tarjan’s Algorithm to find Strongly Connected Components, which is the hint of this question&lt;&#x2F;a&gt; but it’s for directed graph&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Solution:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;from&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-variable&quot;&gt; __future__&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; import&lt;&#x2F;span&gt;&lt;span&gt; print_function&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt; collections&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; import&lt;&#x2F;span&gt;&lt;span&gt; defaultdict&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; criticalConnections&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(self, n, connections):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type n: int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type connections: List[List[int]]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :rtype: List[List[int]]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support&quot;&gt;        map&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; defaultdict(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;list&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; [n1, n2]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; connections:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support&quot;&gt;            map&lt;&#x2F;span&gt;&lt;span&gt;[n1].append(n2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support&quot;&gt;            map&lt;&#x2F;span&gt;&lt;span&gt;[n2].append(n1)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        visited&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; defaultdict(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; False&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;        # node with lowest index that this node can reach&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        lowestNode&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; defaultdict(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; float&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;-inf&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;        # time that dfs went through this node, or depth in DFS&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        discoverTime&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; defaultdict(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; float&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;-inf&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        parentMap&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; defaultdict(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        results&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; []&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; dfs&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(node, time):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; visited[node]:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; return&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            visited[node]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; True&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            lowestNode[node]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; time&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            discoverTime[node]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; time&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            for&lt;&#x2F;span&gt;&lt;span&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; map&lt;&#x2F;span&gt;&lt;span&gt;[node]:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;                # dfs over all adjacent nodes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                if not&lt;&#x2F;span&gt;&lt;span&gt; visited[t]:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    parentMap[t]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; node&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    dfs(t, time&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    lowestNode[node]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; min&lt;&#x2F;span&gt;&lt;span&gt;(lowestNode[t], lowestNode[node])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                    if&lt;&#x2F;span&gt;&lt;span&gt; lowestNode[t]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; discoverTime[node]:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        results.append([node, t])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                    if&lt;&#x2F;span&gt;&lt;span&gt; t&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span&gt; parentMap[node]:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        lowestNode[node]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; min&lt;&#x2F;span&gt;&lt;span&gt;(lowestNode[node], discoverTime[t])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        dfs(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; results&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;n&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;connections&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;], [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;], [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;], [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;]]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-support&quot;&gt;print&lt;&#x2F;span&gt;&lt;span&gt;(Solution().criticalConnections(n, connections))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</description>
      </item>
      <item>
          <title>Leetcode Contest 153</title>
          <pubDate>Sun, 08 Sep 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/leetcode-153/</link>
          <guid>https://usegitflow.com/posts/leetcode-153/</guid>
          <description xml:base="https://usegitflow.com/posts/leetcode-153/">&lt;h4 id=&quot;make-array-strictly-increasing&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;problems&#x2F;make-array-strictly-increasing&quot;&gt;Make Array Strictly Increasing&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;In one operation, you can choose two indices 0 &amp;lt;= i &amp;lt; arr1.length and 0 &amp;lt;= j &amp;lt; arr2.length and do the assignment arr1[i] = arr2[j].&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;If there is no way to make arr1 strictly increasing, return -1.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: &lt;strong&gt;DP&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;New method used here: &lt;code&gt;bisect.bisect_right&lt;&#x2F;code&gt; to find an index for a value in a sorted array&lt;&#x2F;p&gt;
&lt;p&gt;Solution:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;import&lt;&#x2F;span&gt;&lt;span&gt; bisect&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; makeArrayIncreasing&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(self, arr1, arr2):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type arr1: List[int]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type arr2: List[int]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :rtype: int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(arr1)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; return&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        arr2.sort()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;  # (value, number of operations to get this value)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        record[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; number&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; arr1:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;            # record is what we get for each possible value before this position&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;            # for each number i at this position, we try two paths:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;            # if it&amp;#39;s larger then record[i] =&amp;gt; (record[i], number of operations)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;            # else then try to find other keys in record to make it work&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            temp&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            for&lt;&#x2F;span&gt;&lt;span&gt; key&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; record.keys():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                if&lt;&#x2F;span&gt;&lt;span&gt; key&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; number:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    temp[number]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; min&lt;&#x2F;span&gt;&lt;span&gt;(temp.get(number,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 999999&lt;&#x2F;span&gt;&lt;span&gt;), record[key])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                leastOptionPos&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; bisect.bisect_right(arr2, key)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;                # first iteration, it will find minimal value in arr2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;                # to be another option to replace in first position&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                if&lt;&#x2F;span&gt;&lt;span&gt; leastOptionPos&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(arr2):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    replaceNumber&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; arr2[leastOptionPos]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    temp[replaceNumber]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; min&lt;&#x2F;span&gt;&lt;span&gt;(temp.get(replaceNumber,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 999999&lt;&#x2F;span&gt;&lt;span&gt;), record[key]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;  # replace&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; temp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; record:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; min&lt;&#x2F;span&gt;&lt;span&gt;(record.values())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;maximum-subarray-sum-with-one-deletion&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;problems&#x2F;maximum-subarray-sum-with-one-deletion&#x2F;&quot;&gt;Maximum Subarray Sum with One Deletion&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum possible.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Note that the subarray needs to be non-empty after deleting one element.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: &lt;strong&gt;DP&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Idea: find &lt;code&gt;maxSubarrayEndHere&lt;&#x2F;code&gt; and &lt;code&gt;maxSubarrayStartHere&lt;&#x2F;code&gt; for each position, then we find max value &lt;code&gt;result&lt;&#x2F;code&gt; for each position’s &lt;code&gt;maxSubarrayEndHere[i-1] + maxSubarrayStartHere[i+1]&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>How to use Insomnia for GraphQL requests</title>
          <pubDate>Sun, 11 Aug 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/insomnia-graphql-requests/</link>
          <guid>https://usegitflow.com/posts/insomnia-graphql-requests/</guid>
          <description xml:base="https://usegitflow.com/posts/insomnia-graphql-requests/">&lt;p&gt;Complete video tutorial is online. Please check &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PL13mreFCu1Josp4PCNb1WlOiaRY6p73D1&quot;&gt;here&lt;&#x2F;a&gt;. Total time would be within 8 minutes.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-cases-when-we-work-with-a-graphql-endpoint&quot;&gt;Use cases when we work with a GraphQL endpoint&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Send my first request to a new GraphQL endpoint&lt;&#x2F;li&gt;
&lt;li&gt;Introspection query to fetch the schema&lt;&#x2F;li&gt;
&lt;li&gt;Manage environment related variables
&lt;ul&gt;
&lt;li&gt;Authentication&lt;&#x2F;li&gt;
&lt;li&gt;Frequently used variables&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Manage a bunch of queries
&lt;ul&gt;
&lt;li&gt;Save&lt;&#x2F;li&gt;
&lt;li&gt;Share&lt;&#x2F;li&gt;
&lt;li&gt;Team Collaboration (for subscriber)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;how-to-use-insomnia-to-manage-my-requests&quot;&gt;How to use Insomnia to manage my requests?&lt;&#x2F;h3&gt;
&lt;p&gt;Please check the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PL13mreFCu1Josp4PCNb1WlOiaRY6p73D1&quot;&gt;complete youtube videos&lt;&#x2F;a&gt; for demo!&lt;&#x2F;p&gt;
&lt;p&gt;Here we’re going to communicate with Github’s &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;developer.github.com&#x2F;v4&#x2F;&quot;&gt;public GraphQL API&lt;&#x2F;a&gt;. Basic steps would be:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Automatically fetch the GraphQL Schema from the endpoint.&lt;&#x2F;li&gt;
&lt;li&gt;Authenticating the requests through a &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;developer.github.com&#x2F;v4&#x2F;guides&#x2F;forming-calls&#x2F;#authenticating-with-graphql&quot;&gt;personal access token&lt;&#x2F;a&gt;, set the token as an environment variable.&lt;&#x2F;li&gt;
&lt;li&gt;Construct your query with the auto-complete feature enabled. Use &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;graphql.org&#x2F;learn&#x2F;queries&#x2F;#variables&quot;&gt;variables&lt;&#x2F;a&gt; when needed.&lt;&#x2F;li&gt;
&lt;li&gt;Send and check your response, work on fixing errors.&lt;&#x2F;li&gt;
&lt;li&gt;Export your current workspace and send it to your teammates. (Or use ‘Share’ feature which requires an Insomnia Plus subscription.)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;support.insomnia.rest&#x2F;article&#x2F;61-graphql&quot;&gt;Insomnia Official document for GraphQL Queries&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;developer.github.com&#x2F;v4&#x2F;public_schema&#x2F;&quot;&gt;Github public schema&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Leetcode Contest 147</title>
          <pubDate>Sun, 28 Jul 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/leetcode-147/</link>
          <guid>https://usegitflow.com/posts/leetcode-147/</guid>
          <description xml:base="https://usegitflow.com/posts/leetcode-147/">&lt;h4 id=&quot;stone-game-ii&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-147&#x2F;problems&#x2F;stone-game-ii&#x2F;&quot;&gt;Stone Game II&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Alex and Lee continue their games with piles of stones.  There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].  The objective of the game is to end with the most stones.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Alex and Lee take turns, with Alex starting first.  Initially, M = 1. On each player’s turn, that player can take all the stones in the first X remaining piles, where 1 &amp;lt;= X &amp;lt;= 2M.  Then, we set M = max(M, X).&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;The game continues until all the stones have been taken. Assuming Alex and Lee play optimally, return the maximum number of stones Alex can get.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: &lt;strong&gt;DP&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;For the piles array, suppose Alex and Lee are at the position i, and Alex needs to make his best move now in order to get more stones. Suppose &lt;code&gt;f(x, M)&lt;&#x2F;code&gt; means the best move made at position &lt;code&gt;x&lt;&#x2F;code&gt;, we have the equation that &lt;code&gt;f(i, M) = min[sum - f(x) for x in range(i + 1, i + 2 * M)]&lt;&#x2F;code&gt;, as both sides need to make their best move.&lt;&#x2F;p&gt;
&lt;p&gt;It’s obvious that the complexity would be high and we need a cache to reduce time&#x2F;space cost. Here we use a dictionary to do so, but a better way would be using &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;functools.html&quot;&gt;&lt;code&gt;lrucache&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which is a decorator to wrap a function with a memoizing callable that saves up to the maxsize most recent calls.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; stoneGameII&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(self, piles):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type piles: List[int]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :rtype: int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(piles)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; return&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; sum&lt;&#x2F;span&gt;&lt;span&gt;(piles)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(length)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        record[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; piles[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            record[i]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; piles[i]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; record[i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;  # sum of all piles start from position i&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        cache&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt; # use cache to reduce time cost&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; optimalCanTake&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(pos, M):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;            # the `f` we mentioned above&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; (pos, M)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; cache:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span&gt; cache[(pos, M)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; pos&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;gt;=&lt;&#x2F;span&gt;&lt;span&gt; length:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; M&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;gt;=&lt;&#x2F;span&gt;&lt;span&gt; length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; pos:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span&gt; record[pos]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            nextMinValue&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 999999999&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(pos&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;, pos&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; M&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;                # i is X&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                nextMinValue&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; min&lt;&#x2F;span&gt;&lt;span&gt;(nextMinValue, optimalCanTake(i,&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; max&lt;&#x2F;span&gt;&lt;span&gt;(M, i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; pos)))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            result&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; record[pos]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; nextMinValue&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            cache[(pos, M)]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; optimalCanTake(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</description>
      </item>
      <item>
          <title>GraphQL Explained</title>
          <pubDate>Fri, 14 Jun 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/graphql-explained/</link>
          <guid>https://usegitflow.com/posts/graphql-explained/</guid>
          <description xml:base="https://usegitflow.com/posts/graphql-explained/">&lt;h3 id=&quot;some-concepts&quot;&gt;Some concepts&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;GraphQL&lt;&#x2F;strong&gt; is a query language for your APIs. It’s also a runtime for fulfilling queries with your data. The GraphQL service is transport agnostic but is typically served over HTTP. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;prisma&#x2F;graphql-playground&quot;&gt;GraphQL playground&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;strong&gt;QL&lt;&#x2F;strong&gt; stands for Query Language, but GraphQL and SQL are completely different. SQL is a query language for databases. GraphQL is a query language for the internet.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Design principles&lt;&#x2F;strong&gt; of GraphQL:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Hierarchical: A GraphQL query is hierarchical. Fields are nested within other fields and the query is shaped like the data that it returns.&lt;&#x2F;li&gt;
&lt;li&gt;Product-centric: GraphQL is driven by the data needs of the client and the language and runtime that support the client.&lt;&#x2F;li&gt;
&lt;li&gt;Strong typing: A GraphQL server is backed by the GraphQL type system. In the schema, each data point has a specific type against which it will be validated.&lt;&#x2F;li&gt;
&lt;li&gt;Client-specified queries: A GraphQL server provides the capabilities that the clients are allowed to consume.&lt;&#x2F;li&gt;
&lt;li&gt;Introspective: The GraphQL language is able to query the GraphQL server’s type system.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;GraphQL Versus REST&lt;&#x2F;strong&gt;: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.apollographql.com&#x2F;blog&#x2F;graphql-vs-rest&quot;&gt;link&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;What’s the drawback of REST?&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Overfetching, avoid extra fields being fetched&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Underfetching, avoid additional requests. The GraphQL solution to underfetching is to define a nested query and then request the data all in one fetch&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Lack of flexibility. With GraphQL, the typical architecture involves a single endpoint. The single endpoint can act as a gateway and orchestrate several data sources, but the one endpoint still makes the organization of data easier.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;In this discussion of REST drawbacks, it’s important to note that many organizations use GraphQL and REST together. Setting up a GraphQL endpoint that fetches data from REST endpoints is a perfectly valid way to use GraphQL. It can be a great way to incrementally adopt GraphQL at your organization.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This is what REST requests look like: &lt;img src=&quot;&#x2F;media&#x2F;graphql-explained&#x2F;rest-requests.png&quot; alt=&quot;REST requests&quot; &#x2F;&gt;
And this is what GraphQL requests look like: &lt;img src=&quot;&#x2F;media&#x2F;graphql-explained&#x2F;graphql-requests.png&quot; alt=&quot;GraphQL requests&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Apollo graphql&lt;&#x2F;strong&gt; is a platform implementation of GraphQL designed for building modern data-driven applications.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;graphql-query-language&quot;&gt;GraphQL Query Language&lt;&#x2F;h3&gt;
&lt;p&gt;Types: &lt;code&gt;query&lt;&#x2F;code&gt;, &lt;code&gt;mutation&lt;&#x2F;code&gt;, &lt;code&gt;subscription&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;h5 id=&quot;cheatsheet&quot;&gt;Cheatsheet&lt;&#x2F;h5&gt;
&lt;p&gt;To check the GraphQL Schema Language, we can use the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;sogko&#x2F;graphql-schema-language-cheat-sheet&quot;&gt;cheatsheet&lt;&#x2F;a&gt;. &lt;img src=&quot;&#x2F;media&#x2F;graphql-explained&#x2F;cheatsheet.png&quot; alt=&quot;cheatsheet&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;About GraphQL queries syntax, we can use &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;devhints.io&#x2F;graphql&quot;&gt;devhints cheatsheet&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h5 id=&quot;queries-reading-data&quot;&gt;Queries: reading data&lt;&#x2F;h5&gt;
&lt;p&gt;In the GraphQL query language, fields can be either &lt;strong&gt;scalar types or object types&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;the five built-in scalar types: integers (Int), floats (Float), strings (String), Booleans (Boolean), and unique identifiers (ID)&lt;&#x2F;li&gt;
&lt;li&gt;GraphQL object types are groups of one or more fields that you define in your schema.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;A GraphQL query document can contain definitions for operations and &lt;strong&gt;fragments&lt;&#x2F;strong&gt;. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;graphql.org&#x2F;learn&#x2F;queries&#x2F;#fragments&quot;&gt;Fragments&lt;&#x2F;a&gt; are selection sets that can be reused in multiple operations.&lt;&#x2F;p&gt;
&lt;p&gt;In each case so far, we’ve returned lists of a single type. If you wanted a list to return more than one type, you could create a &lt;strong&gt;union type&lt;&#x2F;strong&gt;, which creates an association between two different object types.&lt;&#x2F;p&gt;
&lt;h5 id=&quot;mutations-writing-updating-data&quot;&gt;Mutations: writing&#x2F;updating data&lt;&#x2F;h5&gt;
&lt;p&gt;Mutations are defined similarly as queries. They have names. They can have selection sets that return object types or scalars. The difference is that mutations perform some sort of a data change that affects the state of your backend data.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Variables&lt;&#x2F;strong&gt; replace the static value in the query so that we can pass dynamic values, instead.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;graphql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;mutation&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; createSong&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$title&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;String&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;!&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $numberOne&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;Int&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; $by&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;String&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;!&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;  addSong&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;title&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$title&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; numberOne&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$numberOne&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; performerName&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;$by&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;    id&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;    title&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;    numberOne&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h5 id=&quot;subscriptions-real-time-update&quot;&gt;Subscriptions: real time update&lt;&#x2F;h5&gt;
&lt;p&gt;Facebook live ‘Likes’ are a real-time use case that is powered by subscriptions. Every client is subscribed to the like event and sees likes being updated in real time. We listen to changes over a WebSocket.&lt;&#x2F;p&gt;
&lt;p&gt;To stop listening for status changes, you need to unsubscribe from your subscription.&lt;&#x2F;p&gt;
&lt;h5 id=&quot;introspection&quot;&gt;Introspection&lt;&#x2F;h5&gt;
&lt;p&gt;Introspection is the ability to query details about the current API’s schema. When getting to know a new GraphQL API, it is a good idea to find out what fields are available on the root types.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;graphql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;query&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; roots&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;  __schema&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;    queryType&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;      ...&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;typeFields&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;    mutationType&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;      ...&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;typeFields&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;    subscriptionType&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;      ...&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt;typeFields&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;fragment&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; typeFields&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; on&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; __Type&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;  name&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;  fields&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-variable&quot;&gt;    name&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;graphql-schema-definition-language-sdl&quot;&gt;GraphQL Schema Definition Language (SDL)&lt;&#x2F;h3&gt;
&lt;p&gt;In GraphQL, a &lt;strong&gt;type&lt;&#x2F;strong&gt; represents a custom object and these objects describe your application’s core features.&lt;&#x2F;p&gt;
&lt;p&gt;A &lt;strong&gt;schema&lt;&#x2F;strong&gt; is a collection of type definitions. You can write your schemas in a JavaScript file as a string or in any text file. These files usually carry the &lt;code&gt;.graphql&lt;&#x2F;code&gt; extension.&lt;&#x2F;p&gt;
&lt;p&gt;At the heart of all GraphQL projects is a solid, well-defined schema. This serves as a roadmap and a contract between the frontend and backend teams to ensure that the product built always serves the schema.&lt;&#x2F;p&gt;
&lt;p&gt;Some concepts in GraphQL Schema:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Scalar types, built in&#x2F;custom scalar types, &lt;code&gt;graphql-custom-types&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Enums&lt;&#x2F;li&gt;
&lt;li&gt;Connections and Lists. Most list definitions are non-nullable lists of non-nullable values.
&lt;ul&gt;
&lt;li&gt;One to one&lt;&#x2F;li&gt;
&lt;li&gt;One to many&lt;&#x2F;li&gt;
&lt;li&gt;Many to many&lt;&#x2F;li&gt;
&lt;li&gt;Through type&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Union type &lt;img src=&quot;&#x2F;media&#x2F;graphql-explained&#x2F;union-type.png&quot; alt=&quot;example&quot; &#x2F;&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Interface &lt;img src=&quot;&#x2F;media&#x2F;graphql-explained&#x2F;interface.png&quot; alt=&quot;example&quot; &#x2F;&gt; In general, if the objects contain completely different fields, it is a good idea to use union types. They are very effective. If an object type must contain specific fields in order to interface with another type of object, you will need to use an interface rather than a union type.&lt;&#x2F;li&gt;
&lt;li&gt;Arguments with type definition, could be used for:
&lt;ul&gt;
&lt;li&gt;querying or filtering&lt;&#x2F;li&gt;
&lt;li&gt;data paging&lt;&#x2F;li&gt;
&lt;li&gt;sorting, sort-by and sort-order, usually enum type&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Schema about ‘Mutations’. Mutations should represent the verbs in your application. They should consist of the things that users should be able to do with your service. When designing your GraphQL service, make a list of all of the actions that a user can take with your application. Those are most likely your mutations.&lt;&#x2F;li&gt;
&lt;li&gt;Mutation variables, similar to query variables.&lt;&#x2F;li&gt;
&lt;li&gt;Input type. There is a better way to organize these arguments using input types. An input type is similar to the GraphQL object type except it is used only for input arguments.&lt;&#x2F;li&gt;
&lt;li&gt;Return type&lt;&#x2F;li&gt;
&lt;li&gt;Subscription types, Subscription types are no different than any other object type in the GraphQL schema definition language.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;some-notes-about-real-world-implementations&quot;&gt;Some notes about real world implementations&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;resolvers&quot;&gt;Resolvers&lt;&#x2F;h4&gt;
&lt;p&gt;Check &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;MoonHighway&#x2F;learning-graphql&#x2F;blob&#x2F;master&#x2F;chapter-05&#x2F;photo-share-api&#x2F;resolvers&#x2F;index.js&quot;&gt;code example&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;A schema describes the data requirements but doesn’t perform the work of getting that data. That work is handled by resolvers.&lt;&#x2F;p&gt;
&lt;p&gt;A resolver is a function that returns data for a particular field. Resolver functions return data in the type and shape specified by the schema. Resolvers can be asynchronous and can fetch or update data from a REST API, database, or any other service.&lt;&#x2F;p&gt;
&lt;p&gt;Resolvers are key to the implementation of GraphQL. Every field must have a corresponding resolver function. The resolver must follow the rules of the schema. It must have the same name as the field that was defined in the schema, and it must return the datatype defined by the schema.&lt;&#x2F;p&gt;
&lt;p&gt;When we define a GraphQL schema, we describe the data requirements of our application. With resolvers, we can powerfully and flexibly fulfill those requirements. Functions give us this power and flexibility. Functions can be asynchronous, can return scalar types and return objects, and can return data from various sources. Resolvers are just functions, and every field in our GraphQL schema can map to a resolver.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;subscriptions&quot;&gt;Subscriptions&lt;&#x2F;h4&gt;
&lt;p&gt;In addition to fetching data using queries and modifying data using mutations, the GraphQL spec supports a third operation type, called &lt;code&gt;subscription&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Please refer to &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.apollographql.com&#x2F;docs&#x2F;react&#x2F;advanced&#x2F;subscriptions&#x2F;&quot;&gt;Apollo docs about subscriptions&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;security&quot;&gt;Security&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;Timeout: A request timeout is a first defense against large or malicious queries. A request timeout allows only a certain amount of time to process each request.&lt;&#x2F;li&gt;
&lt;li&gt;Data Limitations: You can return a specific number of records, or a page of data, by allowing your queries to specify how many records to return.&lt;&#x2F;li&gt;
&lt;li&gt;Limiting Query Depth&lt;&#x2F;li&gt;
&lt;li&gt;Limiting Query Complexity&lt;&#x2F;li&gt;
&lt;li&gt;Monitor service, like &lt;code&gt;Apollo Engine&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;schema-first-development&quot;&gt;Schema first development&lt;&#x2F;h4&gt;
&lt;p&gt;Problems with web projects usually stem from a lack of communication or miscommunication about what should be built. Schemas provide clarity and communication, which is why many projects practice schema-first development.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Reference&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Learning GraphQL, by Alex Banks, Eve Porcello&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.howtographql.com&#x2F;&quot;&gt;https:&#x2F;&#x2F;www.howtographql.com&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Real world example from the book: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;MoonHighway&#x2F;learning-graphql&#x2F;tree&#x2F;master&#x2F;chapter-05&#x2F;photo-share-api&#x2F;&quot;&gt;Chapter 5 (GraphQL Server)&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</description>
      </item>
      <item>
          <title>Leetcode Contest 140</title>
          <pubDate>Sun, 09 Jun 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/leetcode-140/</link>
          <guid>https://usegitflow.com/posts/leetcode-140/</guid>
          <description xml:base="https://usegitflow.com/posts/leetcode-140/">&lt;h4 id=&quot;letter-tile-possibilities&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-140&#x2F;problems&#x2F;letter-tile-possibilities&#x2F;&quot;&gt;Letter Tile Possibilities&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;You have a set of tiles, where each tile has one letter tiles[i] printed on it.  Return the number of possible non-empty sequences of letters you can make.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: &lt;strong&gt;permutation&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Sort not needed&lt;&#x2F;li&gt;
&lt;li&gt;Use a helper method to iterate over all possibilities, use a set to avoid repetition&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Similar to: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;problems&#x2F;permutations-ii&#x2F;&quot;&gt;47. Permutations II&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; numTilePossibilities&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(self, tiles):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type tiles: str&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :rtype: int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; set&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;        def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; helper&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(currString, remainingCharacters):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(remainingCharacters)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                record.add(currString)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                return&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; currString&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; record:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                return&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            record.add(currString)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;(remainingCharacters)):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                helper(currString&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; remainingCharacters[i], remainingCharacters[:i]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; remainingCharacters[i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;+&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;:])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        helper(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, tiles)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(record)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Another one-line brute-force solution from discuss:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; numTilePossibilities&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(self, S):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;({s[:i]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; s&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; itertools.permutations(S)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable&quot;&gt; xrange&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;)})&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;insufficient-nodes-in-root-to-leaf-paths&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-140&#x2F;problems&#x2F;insufficient-nodes-in-root-to-leaf-paths&#x2F;&quot;&gt;Insufficient Nodes in Root to Leaf Paths&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Given the root of a binary tree, consider all root to leaf paths: paths from the root to any leaf.  (A leaf is a node with no children.)
A node is insufficient if every such root to leaf path intersecting this node has sum strictly less than limit.
Delete all insufficient nodes simultaneously, and return the root of the resulting binary tree.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: &lt;strong&gt;Tree, DFS, recursive&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;I didn’t pass this question due to one very long test case failure.&lt;&#x2F;li&gt;
&lt;li&gt;However, the solution won’t be too different, so I consider it solved.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Recursive solution:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; sufficientSubset&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(self, root, limit):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type root: TreeNode&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type limit: int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :rtype: TreeNode&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; root&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; return&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; root.left&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; None&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; root.right&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span&gt; root&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; root.val&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;gt;=&lt;&#x2F;span&gt;&lt;span&gt; limit&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; else&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; root.left&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            root.left&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.sufficientSubset(root.left, limit&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; root.val)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; root.right&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            root.right&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-language&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.sufficientSubset(root.right, limit&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; root.val)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; root&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;smallest-subsequence-of-distinct-characters&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-140&#x2F;problems&#x2F;smallest-subsequence-of-distinct-characters&#x2F;&quot;&gt;Smallest Subsequence of Distinct Characters&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Return the lexicographically smallest subsequence of text that contains all the distinct characters of text exactly once.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: &lt;strong&gt;Greedy&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Same as &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;problems&#x2F;remove-duplicate-letters&#x2F;&quot;&gt;Remove Duplicate Letters&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Idea: when we meet a new character &lt;code&gt;c&lt;&#x2F;code&gt;, if the last item in our current result is larger than &lt;code&gt;c&lt;&#x2F;code&gt;, and the last item still remains later, then we remove it for now.&lt;&#x2F;li&gt;
&lt;li&gt;A very nice solution explained: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;problems&#x2F;smallest-subsequence-of-distinct-characters&#x2F;discuss&#x2F;308222&#x2F;show-my-thinking-process&quot;&gt;link&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; smallestSubsequence&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(self, text):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type text: str&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :rtype: str&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; index, c&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; enumerate&lt;&#x2F;span&gt;&lt;span&gt;(text):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            record[c]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; index&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        result&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; []&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; index, c&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; enumerate&lt;&#x2F;span&gt;&lt;span&gt;(text):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; c&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; result:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                continue&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            while&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(result)&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; result[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; c&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; record[result[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; index:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;                # if the last character is larger than c, and the character still remains in text, remove it&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                result.pop()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            result.append(c)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt; &amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;.join(result)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</description>
      </item>
      <item>
          <title>Leetcode Contest 135</title>
          <pubDate>Sun, 05 May 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/leetcode-135/</link>
          <guid>https://usegitflow.com/posts/leetcode-135/</guid>
          <description xml:base="https://usegitflow.com/posts/leetcode-135/">&lt;h4 id=&quot;minimum-score-triangulation-of-polygon&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-135&#x2F;problems&#x2F;minimum-score-triangulation-of-polygon&#x2F;&quot;&gt;Minimum Score Triangulation of Polygon&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Given N, consider a convex N-sided polygon with vertices labelled A[0], A[1], …, A[N-1] in clockwise order.&lt;&#x2F;p&gt;
&lt;p&gt;Suppose you triangulate the polygon into N-2 triangles.  For each triangle, the value of that triangle is the product of the labels of the vertices, and the total score of the triangulation is the sum of these values over all N-2 triangles in the triangulation.&lt;&#x2F;p&gt;
&lt;p&gt;Return the smallest possible total score that you can achieve with some triangulation of the polygon.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: DP. &lt;code&gt;record[i][j]&lt;&#x2F;code&gt; means the min score from &lt;code&gt;A[i]&lt;&#x2F;code&gt; to &lt;code&gt;A[j]&lt;&#x2F;code&gt; when the points &lt;code&gt;i-j&lt;&#x2F;code&gt; are connected.&lt;&#x2F;p&gt;
&lt;p&gt;Suppose &lt;code&gt;j = i + step&lt;&#x2F;code&gt;, where step could be in &lt;code&gt;range(2, length)&lt;&#x2F;code&gt;. Then in the range of points &lt;code&gt;i-j&lt;&#x2F;code&gt;, the value &lt;code&gt;record[i][j]&lt;&#x2F;code&gt; is the minimal sum of &lt;code&gt;A[i]*A[j]*A[k]&lt;&#x2F;code&gt; for k in &lt;code&gt;range(i, j)&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; minScoreTriangulation&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(self, A):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type A: List[int]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :rtype: int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(A)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        record&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(length)]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(length)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-comment&quot;&gt;        # record[i][j] means the min score from A[i] to A[j] when i-j connected&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; step&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;, length):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;, length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; step):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; step&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                record[i][j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 100&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 100&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; *&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 100&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;                for&lt;&#x2F;span&gt;&lt;span&gt; k&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;, i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; step):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    record[i][j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; min&lt;&#x2F;span&gt;&lt;span&gt;(record[i][j], record[i][k]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; record[k][j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; A[i]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; A[j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; A[k])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; record[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;][&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;moving-stones-until-consecutive-ii&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-135&#x2F;problems&#x2F;moving-stones-until-consecutive-ii&#x2F;&quot;&gt;Moving Stones Until Consecutive II&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;On an infinite number line, the position of the i-th stone is given by stones[i].  Call a stone an endpoint stone if it has the smallest or largest position.
Each turn, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.
When the game ends, what is the minimum and maximum number of moves that you could have made?  Return the answer as a length-2 array: answer = [minimum_moves, maximum_moves]&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Keyword: Math, sliding window&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Sort the array, &lt;code&gt;n = len(A)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Maximum move would be &lt;code&gt;(A[n-1] - A[1]) - (n - 2)&lt;&#x2F;code&gt; or &lt;code&gt;(A[n-2] - A[0]) - (n - 2)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Minimum move could be 0 or &amp;gt;= 2. We can use a sliding window with length n to scan and detect when the window contains the most stones.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;class&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; Solution&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-storage z-type&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name&quot;&gt; numMovesStonesII&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-function&quot;&gt;(self, stones):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :type stones: List[int]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;        :rtype: List[int]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(stones)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        stones.sort()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        high&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; max&lt;&#x2F;span&gt;&lt;span&gt;(stones[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; stones[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; (length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;), stones[&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; stones[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; (length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        low&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; length&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; in&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(length):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            while&lt;&#x2F;span&gt;&lt;span&gt; stones[i]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; stones[j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;gt;=&lt;&#x2F;span&gt;&lt;span&gt; length:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; stones[i]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; stones[j]&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                low&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; min&lt;&#x2F;span&gt;&lt;span&gt;(low,&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;            else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                low&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; =&lt;&#x2F;span&gt;&lt;span class=&quot;z-support&quot;&gt; min&lt;&#x2F;span&gt;&lt;span&gt;(low, length&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; (i&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; j&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword&quot;&gt; +&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-keyword&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; [low, high]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;valid-boomerang&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-135&#x2F;problems&#x2F;valid-boomerang&#x2F;&quot;&gt;Valid Boomerang&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Given a list of three points in the plane, return whether these points are a boomerang.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Calculate the slope of AB and AC (but avoid the same &lt;code&gt;x&lt;&#x2F;code&gt; value). Notice that we need a float type for the slope value.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Better solution:&lt;&#x2F;strong&gt; Use multiplication instead of division when calculating the slope.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;binary-search-tree-to-greater-sum-tree&quot;&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;leetcode.com&#x2F;contest&#x2F;weekly-contest-135&#x2F;problems&#x2F;binary-search-tree-to-greater-sum-tree&#x2F;&quot;&gt;Binary Search Tree to Greater Sum Tree&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Given the root of a binary search tree with distinct values, modify it so that every node has a new value equal to the sum of the values of the original tree that are greater than or equal to node.val.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Inorder traversal, then update the value from right to left.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>沉默的大多数</title>
          <pubDate>Sat, 27 Apr 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/wang-xiao-bo/</link>
          <guid>https://usegitflow.com/posts/wang-xiao-bo/</guid>
          <description xml:base="https://usegitflow.com/posts/wang-xiao-bo/">&lt;p&gt;Book link: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.amazon.cn&#x2F;dp&#x2F;B00DNX7Y3W&quot;&gt;kindle&lt;&#x2F;a&gt;
王小波: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;zh.wikipedia.org&#x2F;wiki&#x2F;%E7%8E%8B%E5%B0%8F%E6%B3%A2&quot;&gt;wiki&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h4 id=&quot;xu-yan&quot;&gt;序言&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;息教授问：你是恶棍还是傻瓜？这就是问：你假傻真傻？杜先生答：两样都有点，先生，凡人两样都得有点呀。在我身上，后者的成分多，前者的成分少。&lt;&#x2F;li&gt;
&lt;li&gt;在这个领域里发议论的人总是在说这个不宜提倡，那个不宜提倡，仿佛人活着就是为了被提倡。要真是这样，就不如不活。&lt;&#x2F;li&gt;
&lt;li&gt;我对自己的要求很低：我活在世上，无非想要明白些道理，遇见些有趣的事。倘能如我所愿，我的一生就算成功。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;chen-mo-de-da-duo-shu&quot;&gt;沉默的大多数&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;话语教给我们很多，但善恶还是可以自明。话语想要教给我们，人与人生来就不平等。在人间，尊卑有序是永恒的真理，但你也可以不听。&lt;&#x2F;li&gt;
&lt;li&gt;仔细推敲起来，毛病当然出在写书人的身上，是他有这种毛病。这种毛病就是：在使用话语时总想交税的强迫症。中国的读书人有很强的社会责任感，就是交纳税金，做一个好的纳税人——这是难听的说法。好听的说法就是以天下为己任。&lt;&#x2F;li&gt;
&lt;li&gt;但是在这世界上的一切人之中，我最希望予以提升的一个，就是我自己。这话很卑鄙，很自私，也很诚实。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;si-wei-de-le-qu&quot;&gt;思维的乐趣&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;我们这个国家里，只有很少的人觉得思想会有乐趣，却有很多的人感受过思想带来的恐慌。所以现在还有很多人以为，思想的味道就该是这样的。&lt;&#x2F;li&gt;
&lt;li&gt;胡思乱想并不有趣，有趣是有道理而且新奇。在我们生活的这个世界上，最大的不幸就是有些人完全拒绝新奇。&lt;&#x2F;li&gt;
&lt;li&gt;假设我相信上帝（其实我是不信的），并且正在为善恶不分而苦恼，我就会请求上帝让我聪明到足以明辨是非的程度，而绝不会请他让我愚蠢到让人家给我灌输善恶标准的程度。&lt;&#x2F;li&gt;
&lt;li&gt;现在我认为，愚蠢是一种极大的痛苦；降低人类的智能，乃是一种最大的罪孽。所以，以愚蠢教人，那是善良的人所能犯下的最严重的罪孽。&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;other-excerpts&quot;&gt;Other excerpts&lt;&#x2F;h4&gt;
&lt;ul&gt;
&lt;li&gt;我已经四十岁了，除了这只猪，还没见过谁敢于如此无视对生活的设置。相反，我倒见过很多想要设置别人生活的人，还有对被设置的生活安之若素的人。因为这个缘故，我一直怀念这只特立独行的猪。&lt;&#x2F;li&gt;
&lt;li&gt;我更相信乔治·奥威尔的话：一切的关键就在于必须承认一加一等于二；弄明白了这一点，其他一切全会迎刃而解。 &amp;lt;人性的逆转&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;弗洛伊德对受虐狂的成因有这样一种解释：人若落入一种无法摆脱的痛苦之中，到了难以承受的地步，就会把这种痛苦看作是幸福，用这种方式来寻求解脱——这样一来，他的价值观就被逆转过来了。&amp;lt;弗洛伊德和受虐狂&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;假如有人笃信自己的特异性一定是好的，是优越、正义的象征，举一千个例子也说服不了他。我也不想说服谁，只是想要问问，成天说这个，有什么用？&amp;lt;优越感种种&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;当然需要所有的人都有点文化修养，有点独立思考的能力，并且对自己的生活负起责任来，同时对别人的事少起点哄。这当然不容易，但这是唯一的希望。&amp;lt;东西方快乐观区别之我见&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;如罗素先生所说，最大的不平等是知识的差异——有人聪明有人笨，这就是问题之所在。这里所说的知识、聪明是广义的，不单包括科学知识，还包括文化素质、艺术的品位，等等。&lt;&#x2F;li&gt;
&lt;li&gt;另一种方法则是：一旦聪明人和傻人起了争执，我们总说傻人有理。久而久之，聪明人也会变傻。这种法子现在正用着呢。&amp;lt;椰子树与平等&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;自打孔孟到如今，我们这个社会里只有两种人。一种编写生活的脚本，另一种去演出这些脚本。&amp;lt;关于崇高&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;用不着花很多钱，受很多罪，跑好远的路，洗耳恭听别人说你是傻 ×。自己知道就够了。&amp;lt;谦卑学习班&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;中国数学、中国物理和中国化学，都不用特别发明出来，老祖宗都替我们发明好了：中国物理是阴阳，中国化学是五行，中国数学是八卦。到了那时，我们又退回到中世纪去了。&amp;lt;科学与邪道&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;人要爱平等、爱自由，人类开创的一切事业中，科学最有成就，就是因为有这两样做根基。对个人而言，没有这两样东西，不仅谈不上成就，而且会活得像一只猪。&lt;&#x2F;li&gt;
&lt;li&gt;比这还重要的只有一样，就是要爱智慧。无论是个人，还是民族，做聪明人才有前途，当笨蛋肯定是要倒霉。&amp;lt;科学的美好&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;但我总觉得，我这一生绝不会向虚无投降。我会一直战斗到死。&amp;lt;有或无&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;忠于已知事实叫作诚实，不忠于事实就叫作虚伪。还有些人只忠于经过选择的事实，这既不叫诚实，也不叫虚伪，我把它叫作浮嚣。&amp;lt;诚实与浮嚣&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;一个常常在进行着接近自己限度的斗争的人总是会常常失败的，一个想探索自然奥秘的人也常常会失败，一个想改革社会的人更是会常常失败。只有那些安于自己限度之内的生活的人才总是“胜利”，这种“胜利者”之所以常胜不败，只是因为他的对手是早已降伏的，或者说，他根本没有投入斗争。&amp;lt;海明威的《老人与海》&amp;gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
</description>
      </item>
      <item>
          <title>《乌合之众》说了些什么？</title>
          <pubDate>Fri, 26 Apr 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/wu-he-zhi-zhong/</link>
          <guid>https://usegitflow.com/posts/wu-he-zhi-zhong/</guid>
          <description xml:base="https://usegitflow.com/posts/wu-he-zhi-zhong/">&lt;p&gt;Related links for this book:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;The_Crowd:_A_Study_of_the_Popular_Mind&quot;&gt;Wikipedia&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.amazon.com&#x2F;Crowd-Study-Popular-Mind&#x2F;dp&#x2F;145382667X&#x2F;ref=sr_1_1?qid=1556287516&amp;amp;refinements=p_27%3AGustave+Le+Bon&amp;amp;s=books&amp;amp;sr=1-1&amp;amp;text=Gustave+Le+Bon&quot;&gt;Amazon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I read the Chinese version on &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.amazon.cn&#x2F;dp&#x2F;B079L684H1&quot;&gt;Kindle&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;qun-ti-de-yi-jian-he-xin-yang&quot;&gt;群体的意见和信仰&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;yao-yuan-cheng-yin&quot;&gt;遥远成因&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;种族因素
&lt;ol&gt;
&lt;li&gt;主导群体灵魂的特殊个性&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;传统因素
&lt;ol&gt;
&lt;li&gt;引导民族的是其历史传统&lt;&#x2F;li&gt;
&lt;li&gt;没有稳定的传统就没有文明&lt;&#x2F;li&gt;
&lt;li&gt;对传统的慢慢改变才有进步&lt;&#x2F;li&gt;
&lt;li&gt;需要在稳定和变化之间找到平衡&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;时间
&lt;ol&gt;
&lt;li&gt;时间是真正的创造者，也是伟大的毁灭者&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;政治和社会制度
&lt;ol&gt;
&lt;li&gt;一个民族不具备改变其制度的力量&lt;&#x2F;li&gt;
&lt;li&gt;制度往往是种族需求的表达&lt;&#x2F;li&gt;
&lt;li&gt;制度无法对群体的灵魂起到深刻作用&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;教育
&lt;ol&gt;
&lt;li&gt;教育既不让人变得更有道德，也不会让人更加幸福&lt;&#x2F;li&gt;
&lt;li&gt;背教材是无法提高智力水平的&lt;&#x2F;li&gt;
&lt;li&gt;群体的灵魂有一部分是随着教育而完善，或者沦丧&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;ji-shi-cheng-yin&quot;&gt;即时成因&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;意象、词语和口号
&lt;ol&gt;
&lt;li&gt;通过巧妙的词语和口号可以刺激意象，影响群体&lt;&#x2F;li&gt;
&lt;li&gt;理性和论证面对词语和口号是无能为力的&lt;&#x2F;li&gt;
&lt;li&gt;意义被胡乱定义的词语，反而在有时候更加能产生效果，比如民主自由平等&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;幻想
&lt;ol&gt;
&lt;li&gt;人类一直受到幻想的影响&lt;&#x2F;li&gt;
&lt;li&gt;谁能带来幻想，谁就能成为群体的主人&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;经验
&lt;ol&gt;
&lt;li&gt;经常的重复，是在群体的灵魂中稳定地建立起一种真理的有效手段&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;理性
&lt;ol&gt;
&lt;li&gt;群体不接受逻辑推理影响&lt;&#x2F;li&gt;
&lt;li&gt;演说家们总是付诸情感而非理性&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;qun-ti-de-ling-xiu&quot;&gt;群体的领袖&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;特征
&lt;ol&gt;
&lt;li&gt;某一种理念的坚定拥护者，这种理念给他力量&lt;&#x2F;li&gt;
&lt;li&gt;领袖将这种力量通过巧妙的演讲等手段传递给群体&lt;&#x2F;li&gt;
&lt;li&gt;领袖大多不是思想者，而是行动者&lt;&#x2F;li&gt;
&lt;li&gt;其权威都有独裁性&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;影响手段
&lt;ol&gt;
&lt;li&gt;断言越干脆就越具有权威&lt;&#x2F;li&gt;
&lt;li&gt;不断重复断言的内容才能更有影响力&lt;&#x2F;li&gt;
&lt;li&gt;让观念或信仰在群体中产生相互传染的效果&lt;&#x2F;li&gt;
&lt;li&gt;成功是威望产生的重要原因&lt;&#x2F;li&gt;
&lt;li&gt;威望会随着失败而消失&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;gu-ding-yu-ke-bian-de-yi-jian&quot;&gt;固定与可变的意见&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;固定的信仰
&lt;ol&gt;
&lt;li&gt;长期信仰在群体中一旦形成，很难摧毁&lt;&#x2F;li&gt;
&lt;li&gt;种族中有一些难以改变的心理特征，影响了种族中普遍信仰的形成&lt;&#x2F;li&gt;
&lt;li&gt;新的信仰和观念中或多或少会发现普遍信仰的痕迹&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;可变的意见&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;qun-ti-de-guan-nian-tui-li-he-xiang-xiang-li&quot;&gt;群体的观念、推理和想象力&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;群体的观念
&lt;ol&gt;
&lt;li&gt;一时被环境影响被创造出来的随机的观念&lt;&#x2F;li&gt;
&lt;li&gt;因为阶层、遗传、意见等原因具有强大稳定性的观念&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;群体的推理
&lt;ol&gt;
&lt;li&gt;只基于表象和经验&lt;&#x2F;li&gt;
&lt;li&gt;属于低级推理，非理性推理&lt;&#x2F;li&gt;
&lt;li&gt;未经证实的观点会很快具有普遍性&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;群体的想象力
&lt;ol&gt;
&lt;li&gt;群体只能通过意象来思考&lt;&#x2F;li&gt;
&lt;li&gt;群体的想象力是伟大的政治家、独裁者的权威支撑&lt;&#x2F;li&gt;
&lt;li&gt;群体的想象力不依靠事实本身，而是通过群体对事实“浓缩”后夸张的样子&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;qun-ti-de-fen-lei&quot;&gt;群体的分类&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;yi-zhi-qun-ti&quot;&gt;异质群体&lt;&#x2F;h4&gt;
&lt;p&gt;匿名：大街上的人
非匿名：评委，议会&lt;&#x2F;p&gt;
&lt;h4 id=&quot;tong-zhi-qun-ti&quot;&gt;同质群体&lt;&#x2F;h4&gt;
&lt;p&gt;宗派，等级集团，阶级&lt;&#x2F;p&gt;
&lt;h4 id=&quot;pei-shen-yuan&quot;&gt;陪审员&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;精英组成的陪审团和普通人组成的所作出的决定相似，说明智力在决定中起到的作用极其微小&lt;&#x2F;li&gt;
&lt;li&gt;陪审团成员注重情感&lt;&#x2F;li&gt;
&lt;li&gt;愿意屈服于威望&lt;&#x2F;li&gt;
&lt;li&gt;更有被说服的可能&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;xuan-min&quot;&gt;选民&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;没有逻辑推理能力&lt;&#x2F;li&gt;
&lt;li&gt;没有批判精神，易怒，轻信&lt;&#x2F;li&gt;
&lt;li&gt;是被控制的&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;yi-hui&quot;&gt;议会&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;意见过于简单化，总是通过简单的抽象原则去解决复杂的社会问题&lt;&#x2F;li&gt;
&lt;li&gt;议员的投票不是经过理性思考的，随意性很大&lt;&#x2F;li&gt;
&lt;li&gt;领导的权威对议员的影响大&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;qun-ti-de-yi-ban-te-zheng&quot;&gt;群体的一般特征&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;zu-cheng&quot;&gt;组成&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;个体可以分散在不同的地点&lt;&#x2F;li&gt;
&lt;li&gt;群体中的个性会自觉消失&lt;&#x2F;li&gt;
&lt;li&gt;感情和思想朝既定的方向发展&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;te-zheng&quot;&gt;特征&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;群体的智力低于个体&lt;&#x2F;li&gt;
&lt;li&gt;群体受到无意识的支配&lt;&#x2F;li&gt;
&lt;li&gt;群体既易于英勇无畏，也易于犯罪&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;xing-cheng-yuan-yin&quot;&gt;形成原因&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;行为受本能支配&lt;&#x2F;li&gt;
&lt;li&gt;群体间的感情和行为会互相传染&lt;&#x2F;li&gt;
&lt;li&gt;群体间的暗示&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;qun-ti-qing-gan-he-dao-de-te-zheng&quot;&gt;群体情感和道德特征&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;qing-gan-te-zheng&quot;&gt;情感特征&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;冲动，多变，易受刺激&lt;&#x2F;li&gt;
&lt;li&gt;容易受暗示和轻信&lt;&#x2F;li&gt;
&lt;li&gt;情感夸张，过于简单&lt;&#x2F;li&gt;
&lt;li&gt;不宽容，专横，保守&lt;&#x2F;li&gt;
&lt;li&gt;惧怕强权&lt;&#x2F;li&gt;
&lt;li&gt;走极端&lt;&#x2F;li&gt;
&lt;li&gt;沉迷于自己的幻想&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;dao-de-te-zheng&quot;&gt;道德特征&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;法不责众&lt;&#x2F;li&gt;
&lt;li&gt;受本能驱使的群体可能做出有崇高道德性质的行为&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h4 id=&quot;zong-jiao-te-dian&quot;&gt;宗教特点&lt;&#x2F;h4&gt;
&lt;ol&gt;
&lt;li&gt;盲目服从，极其狭隘，渴望传播&lt;&#x2F;li&gt;
&lt;li&gt;神化心目中的崇高者&lt;&#x2F;li&gt;
&lt;li&gt;这种情感可以让群体感到幸福&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
</description>
      </item>
      <item>
          <title>First post</title>
          <pubDate>Fri, 29 Mar 2019 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://usegitflow.com/posts/first-post/</link>
          <guid>https://usegitflow.com/posts/first-post/</guid>
          <description xml:base="https://usegitflow.com/posts/first-post/">&lt;p&gt;What I used for this website:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.gatsbyjs.org&#x2F;&quot;&gt;Gatsby.js&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Template: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;alxshelepenok&#x2F;gatsby-starter-lumen&quot;&gt;gatsby-starter-lumen&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;react-twitter-widgets&quot;&gt;Twitter integration&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
    </channel>
</rss>
