<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <updated>2026-09-26T21:22:51Z</updated>
  <generator>https://nostr.now</generator>

  <title>Nostr notes by codementor</title>
  <author>
    <name>codementor</name>
  </author>
  <link rel="self" type="application/atom+xml" href="https://nostr.now/npub1u69qs4hfpkve0v0hy85s2fycjeqjm4ts8xdfs7ew3l270l87yfuspv0yg2.rss" />
  <link href="https://nostr.now/npub1u69qs4hfpkve0v0hy85s2fycjeqjm4ts8xdfs7ew3l270l87yfuspv0yg2" />
  <id>https://nostr.now/npub1u69qs4hfpkve0v0hy85s2fycjeqjm4ts8xdfs7ew3l270l87yfuspv0yg2</id>
  <icon>https://blossom.primal.net/d87ea72911153368b450df15f0a7cf2040490ec1fd9b9c436c967316690dfcaf.jpg</icon>
  <logo>https://blossom.primal.net/d87ea72911153368b450df15f0a7cf2040490ec1fd9b9c436c967316690dfcaf.jpg</logo>




  <entry>
    <id>https://nostr.now/nevent1qqsx9kt08sk8cjw6la7uuu6a0k8rzwkvs2t7jjn8rqmn0wdknkgup3qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcv0p3x</id>
    
      <title type="html">Learn: Caching in one breath A cache keeps a copy of slow data ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsx9kt08sk8cjw6la7uuu6a0k8rzwkvs2t7jjn8rqmn0wdknkgup3qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcv0p3x" />
    <content type="html">
      Learn: Caching in one breath&lt;br/&gt;&lt;br/&gt;A cache keeps a copy of slow data (like a database result) somewhere fast (like memory). Reads get much faster.&lt;br/&gt;&lt;br/&gt;The hard part is staleness: when the real data changes, the copy is wrong. Common answers: an expiry time (TTL), or deleting the cached copy on every write.&lt;br/&gt;&lt;br/&gt;#tip · TIP-013
    </content>
    <updated>2026-10-28T15:08:03Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsdac0x9cmv7awjc8uw3ruxj8cjma58255hglj05n274jzhd43yphszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j2qxpwv</id>
    
      <title type="html">Learn: Bitwise tricks Operators: &amp;amp; (and), | (or), ^ (xor), ~ ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsdac0x9cmv7awjc8uw3ruxj8cjma58255hglj05n274jzhd43yphszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j2qxpwv" />
    <content type="html">
      Learn: Bitwise tricks&lt;br/&gt;&lt;br/&gt;Operators: &amp;amp; (and), | (or), ^ (xor), ~ (not), &amp;lt;&amp;lt; and &amp;gt;&amp;gt; (shift).&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int n = 12; // 1100 in binary&lt;br/&gt;Console.WriteLine(n &amp;amp; 1);&lt;br/&gt;Console.WriteLine((n &amp;amp; (n - 1)) == 0);&lt;br/&gt;Console.WriteLine(5 ^ 3 ^ 5);&lt;br/&gt;Console.WriteLine(1 &amp;lt;&amp;lt; 4);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;n &amp;amp; 1 is 0 for even numbers. n &amp;gt; 0 &amp;amp;&amp;amp; (n &amp;amp; (n - 1)) == 0 is true only for powers of two (.NET also has int.IsPow2). x ^ x is 0, so xor finds the one number without a pair. 1 &amp;lt;&amp;lt; 4 is 16.&lt;br/&gt;Use them for flags, compact sets of booleans, and these classic interview tricks.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/bitwise-algorithms/&#34;&gt;https://www.geeksforgeeks.org/dsa/bitwise-algorithms/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-042
    </content>
    <updated>2026-10-28T14:37:53Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs9mjsd020gkny3r5hqruvwdq53sta5h2mvvzvmgarca0j5g9z2f0qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j7p4v8s</id>
    
      <title type="html">Learn: Interface An interface is a contract: members a class must ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs9mjsd020gkny3r5hqruvwdq53sta5h2mvvzvmgarca0j5g9z2f0qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j7p4v8s" />
    <content type="html">
      Learn: Interface&lt;br/&gt;&lt;br/&gt;An interface is a contract: members a class must provide. It can&amp;#39;t hold instance data (no fields); since C# 8 it may give a method a default body.&lt;br/&gt;A class can implement many interfaces.&lt;br/&gt;Use it when: different classes should be usable the same way, for DI and testing with fakes, or plug-ins.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;IShape[] shapes = { new Square(2), new Circle(1) };&lt;br/&gt;foreach (var s in shapes) Console.WriteLine(s.Area().ToString(&amp;#34;0.00&amp;#34;));&lt;br/&gt;&lt;br/&gt;interface IShape { double Area(); }&lt;br/&gt;record Square(double Side) : IShape { public double Area() =&amp;gt; Side * Side; }&lt;br/&gt;record Circle(double R) : IShape { public double Area() =&amp;gt; Math.PI * R * R; }&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 4.00, then 3.14.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface&#34;&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-048
    </content>
    <updated>2026-10-28T10:38:27Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs8y6e66g9sy7c9gnxr4v7rhurgtjzguct9k3mxl4yqlym6heslpwgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j0lr5qn</id>
    
      <title type="html">Learn: Sharding splits data by a key When one database is too big ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs8y6e66g9sy7c9gnxr4v7rhurgtjzguct9k3mxl4yqlym6heslpwgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j0lr5qn" />
    <content type="html">
      Learn: Sharding splits data by a key&lt;br/&gt;&lt;br/&gt;When one database is too big or too busy, split the data across several databases (shards), for example by user ID.&lt;br/&gt;&lt;br/&gt;The risk is a hot shard: if one key gets most of the traffic, one shard does most of the work. Choose a key that spreads load evenly.&lt;br/&gt;&lt;br/&gt;#tip · TIP-016
    </content>
    <updated>2026-10-28T10:08:00Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsyrzx7zxz3gcaqeyl9gu7c2dvt54ppd43nn4t2mh26wjxf5fa0gqszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jmaal5h</id>
    
      <title type="html">Learn: Array What: items stored side by side in memory, each at ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsyrzx7zxz3gcaqeyl9gu7c2dvt54ppd43nn4t2mh26wjxf5fa0gqszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jmaal5h" />
    <content type="html">
      Learn: Array&lt;br/&gt;&lt;br/&gt;What: items stored side by side in memory, each at an index.&lt;br/&gt;Cost: read or write a[i] in O(1); insert or delete in the middle O(n), because items must shift.&lt;br/&gt;Use it when: you know the size, you read by position a lot, or you loop over everything.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int[] a = { 10, 20, 30 };&lt;br/&gt;Console.WriteLine(a[1]);&lt;br/&gt;var list = new List&amp;lt;int&amp;gt;(a) { 40 };&lt;br/&gt;Console.WriteLine(list.Count);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 20, then 4. In C#, int[] has a fixed size; List&amp;lt;T&amp;gt; is an array that grows.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/array-data-structure-guide/&#34;&gt;https://www.geeksforgeeks.org/dsa/array-data-structure-guide/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-023
    </content>
    <updated>2026-10-28T09:38:24Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqswaxyt5c5dye2a7px2rwja0wrf5ha7ysaleeav379j3nmyuhdlhxszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jspd6z9</id>
    
      <title type="html">Question: A candidate checks only that each node&amp;#39;s left child ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqswaxyt5c5dye2a7px2rwja0wrf5ha7ysaleeav379j3nmyuhdlhxszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jspd6z9" />
    <content type="html">
      Question: A candidate checks only that each node&amp;#39;s left child is smaller and its right child is bigger.&lt;br/&gt;&lt;br/&gt;Why is that not enough? Give a tree that passes their check but is not a BST.&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg005 · TG-005-Q2
    </content>
    <updated>2026-10-28T09:07:48Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsza6ddryg00y8ay2jm0cmwtr6wk6c5ntws7gny0mz9zrsp5677v8qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jk00q6d</id>
    
      <title type="html">The rule is about whole subtrees, not just children. A grandchild ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsza6ddryg00y8ay2jm0cmwtr6wk6c5ntws7gny0mz9zrsp5677v8qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jk00q6d" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqswaxyt5c5dye2a7px2rwja0wrf5ha7ysaleeav379j3nmyuhdlhxspz3mhxue69uhhyetvv9ujuerpd46hxtnfdu5fsls5&#39;&gt;nevent1q…sls5&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;The rule is about whole subtrees, not just children. A grandchild can be on the wrong side of its grandparent.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var bad = new Node(5, new Node(3, null, new Node(6)), new Node(8));&lt;br/&gt;Console.WriteLine(LocalCheck(bad));&lt;br/&gt;&lt;br/&gt;bool LocalCheck(Node? n) =&amp;gt;&lt;br/&gt;    n == null ||&lt;br/&gt;    (n.Left == null || n.Left.Value &amp;lt; n.Value) &amp;amp;&amp;amp; (n.Right == null || n.Right.Value &amp;gt; n.Value)&lt;br/&gt;    &amp;amp;&amp;amp; LocalCheck(n.Left) &amp;amp;&amp;amp; LocalCheck(n.Right);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints True, but the tree is not a BST: 6 sits in the left subtree of 5. Searching for 6 from the root would go right and miss it.&lt;br/&gt;&lt;br/&gt;This is the most common bug in this question.&lt;br/&gt;&lt;br/&gt;#tg005 · TG-005-A2
    </content>
    <updated>2026-10-28T09:07:48Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsy0tapvmrcsxa3ycthfwr4sslu6mgzfnde3we6txr2tr3xnhdlcqqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jf4hnuz</id>
    
      <title type="html">Learn: Linear search What: check the items one by one until you ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsy0tapvmrcsxa3ycthfwr4sslu6mgzfnde3we6txr2tr3xnhdlcqqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jf4hnuz" />
    <content type="html">
      Learn: Linear search&lt;br/&gt;&lt;br/&gt;What: check the items one by one until you find the target.&lt;br/&gt;Cost: O(n) in the worst case, O(1) extra memory.&lt;br/&gt;Use it when: the data is not sorted, is small, or you search only once. Sorting first costs O(n log n), more than one linear search.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int[] a = { 7, 3, 9, 1 };&lt;br/&gt;Console.WriteLine(Array.IndexOf(a, 9));&lt;br/&gt;Console.WriteLine(Array.IndexOf(a, 5));&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 2, then -1 (not found). Array.IndexOf and List&amp;lt;T&amp;gt;.Contains are linear searches.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/linear-search/&#34;&gt;https://www.geeksforgeeks.org/dsa/linear-search/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-033
    </content>
    <updated>2026-10-28T08:37:56Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsdzjxsar9l8gwlrq9qg579dy9hmhw22nkujxgu9j77gwhnam3tcaczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jajwgyl</id>
    
      <title type="html">Learn: Test your code by hand When your code is written, ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsdzjxsar9l8gwlrq9qg579dy9hmhw22nkujxgu9j77gwhnam3tcaczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jajwgyl" />
    <content type="html">
      Learn: Test your code by hand&lt;br/&gt;&lt;br/&gt;When your code is written, don&amp;#39;t just say &amp;#34;done&amp;#34;. Walk through it with a small example, line by line, and say the values out loud.&lt;br/&gt;&lt;br/&gt;Then try the edge cases: an empty input, one item, and all items the same. Most bugs show up in these three.&lt;br/&gt;&lt;br/&gt;#tip · TIP-004
    </content>
    <updated>2026-10-28T08:07:55Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqstna69mzc5prmjzsp0g2f7zur9a60puzwaagzdca0fkzx62pjrfxgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j3mzmxs</id>
    
      <title type="html">Learn: IDisposable and using Some objects hold things the garbage ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqstna69mzc5prmjzsp0g2f7zur9a60puzwaagzdca0fkzx62pjrfxgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j3mzmxs" />
    <content type="html">
      Learn: IDisposable and using&lt;br/&gt;&lt;br/&gt;Some objects hold things the garbage collector doesn&amp;#39;t manage well: files, network connections, database connections. They implement IDisposable, and you must call Dispose when done.&lt;br/&gt;using does it for you, even if an exception is thrown:&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;using (var r = new Resource()) Console.WriteLine(&amp;#34;working&amp;#34;);&lt;br/&gt;Console.WriteLine(&amp;#34;after&amp;#34;);&lt;br/&gt;&lt;br/&gt;class Resource : IDisposable { public void Dispose() =&amp;gt; Console.WriteLine(&amp;#34;cleaned up&amp;#34;); }&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints working, cleaned up, after.&lt;br/&gt;Shorter form: using var file = File.OpenRead(path); disposes at the end of the method or block.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using&#34;&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-101
    </content>
    <updated>2026-10-28T07:38:09Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs2g8s4cas4xecnxdve7mqde5truaak5q3k0pc247j2maw3d3z3cxczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j0al5kp</id>
    
      <title type="html">Both are O(n) time: each node is visited once. The level version ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs2g8s4cas4xecnxdve7mqde5truaak5q3k0pc247j2maw3d3z3cxczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j0al5kp" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqsfdme9wphdsplq6jpqynza7s4j0ak5zne8j6rn70jzznrmy3mcq4spz3mhxue69uhhyetvv9ujuerpd46hxtnfdur6chpp&#39;&gt;nevent1q…chpp&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Both are O(n) time: each node is visited once.&lt;br/&gt;&lt;br/&gt;The level version holds one full level in memory. In a balanced tree the last level has about n/2 nodes, so that is O(n).&lt;br/&gt;&lt;br/&gt;The recursive version uses the call stack: O(height). That is O(log n) for a balanced tree, but O(n) for a chain, where deep recursion can even overflow the stack.&lt;br/&gt;&lt;br/&gt;The result itself is O(n) either way, so in an interview both answers are fine. Just name the trade-off.&lt;br/&gt;&lt;br/&gt;#tg003 · TG-003-A3
    </content>
    <updated>2026-10-28T07:07:54Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsfdme9wphdsplq6jpqynza7s4j0ak5zne8j6rn70jzznrmy3mcq4szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jdn8mnk</id>
    
      <title type="html">Question: Compare the two versions: time, and extra memory ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsfdme9wphdsplq6jpqynza7s4j0ak5zne8j6rn70jzznrmy3mcq4szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jdn8mnk" />
    <content type="html">
      Question: Compare the two versions: time, and extra memory besides the result.&lt;br/&gt;&lt;br/&gt;For which tree shape is each one better?&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg003 · TG-003-Q3
    </content>
    <updated>2026-10-28T07:07:54Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsp7gtmua7264ujnm4ncssvjkc8xsdyvu0vu0pzv8kq9s9d044a0mszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jucmjq5</id>
    
      <title type="html">Learn: When recursion fits Use recursion when a problem contains ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsp7gtmua7264ujnm4ncssvjkc8xsdyvu0vu0pzv8kq9s9d044a0mszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jucmjq5" />
    <content type="html">
      Learn: When recursion fits&lt;br/&gt;&lt;br/&gt;Use recursion when a problem contains smaller copies of itself: trees, folders inside folders, divide and conquer, trying all options (backtracking).&lt;br/&gt;&lt;br/&gt;Every recursive function needs a base case and a step toward it.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;Console.WriteLine(Factorial(5));&lt;br/&gt;static long Factorial(int n) =&amp;gt; n &amp;lt;= 1 ? 1 : n * Factorial(n - 1);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 120. For very deep inputs, a loop is safer: each call uses stack memory.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/recursion-algorithms/&#34;&gt;https://www.geeksforgeeks.org/dsa/recursion-algorithms/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-041
    </content>
    <updated>2026-10-28T06:38:06Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs2dzw3xsaha2htyjlepq8c27ucpl7me3yslvcw8cccug6cz0wrnjczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jyx834s</id>
    
      <title type="html">Learn: Ask before you code Before writing anything, ask about the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs2dzw3xsaha2htyjlepq8c27ucpl7me3yslvcw8cccug6cz0wrnjczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jyx834s" />
    <content type="html">
      Learn: Ask before you code&lt;br/&gt;&lt;br/&gt;Before writing anything, ask about the input:&lt;br/&gt;&lt;br/&gt;Can it be empty or null?&lt;br/&gt;Are there duplicates or negative numbers?&lt;br/&gt;Is it sorted?&lt;br/&gt;How big can it get?&lt;br/&gt;&lt;br/&gt;The answers often change the best solution, and asking shows the interviewer you think about edge cases.&lt;br/&gt;&lt;br/&gt;#tip · TIP-002
    </content>
    <updated>2026-10-28T06:08:02Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsvne4wd7k2k6xdhrl24lw7wv3vxxs8yayshmjeny4ry2p7de07xeqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jska60l</id>
    
      <title type="html">Learn: Binary search in one post On a sorted array, look at the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsvne4wd7k2k6xdhrl24lw7wv3vxxs8yayshmjeny4ry2p7de07xeqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jska60l" />
    <content type="html">
      Learn: Binary search in one post&lt;br/&gt;&lt;br/&gt;On a sorted array, look at the middle. If the target is bigger, keep the right half; if smaller, the left half. Each step halves the range: O(log n).&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int[] a = { 1, 3, 5, 7, 9, 11 };&lt;br/&gt;int target = 7, lo = 0, hi = a.Length - 1;&lt;br/&gt;while (lo &amp;lt;= hi)&lt;br/&gt;{&lt;br/&gt;    int mid = lo &#43; (hi - lo) / 2;&lt;br/&gt;    if (a[mid] == target) { Console.WriteLine(mid); break; }&lt;br/&gt;    if (a[mid] &amp;lt; target) lo = mid &#43; 1; else hi = mid - 1;&lt;br/&gt;}&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 3. Write mid as lo &#43; (hi - lo) / 2: plain (lo &#43; hi) / 2 can overflow an int on huge arrays.&lt;br/&gt;&lt;br/&gt;#tip · TIP-006
    </content>
    <updated>2026-10-27T19:38:17Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqszxzmsgllkscw2lyrkd7nutyllduleh7yhaw30v2xcc9nxzrw3knszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jku8kxa</id>
    
      <title type="html">Learn: Binary search tree (BST) In a BST, every value in a ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqszxzmsgllkscw2lyrkd7nutyllduleh7yhaw30v2xcc9nxzrw3knszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jku8kxa" />
    <content type="html">
      Learn: Binary search tree (BST)&lt;br/&gt;&lt;br/&gt;In a BST, every value in a node&amp;#39;s left subtree is smaller than the node, and every value in its right subtree is bigger.&lt;br/&gt;&lt;br/&gt;To search, compare with the node and go left or right: one level per step. So the cost is O(height).&lt;br/&gt;&lt;br/&gt;A balanced tree has height about log₂ n, so search is O(log n). A tree that is a chain has height n, so search is O(n).&lt;br/&gt;&lt;br/&gt;That is why real libraries use self-balancing trees (like red-black or AVL trees), which fix the shape after each insert or delete.&lt;br/&gt;&lt;br/&gt;#tg002 · TG-002-N
    </content>
    <updated>2026-10-27T19:08:03Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsd6p0zkt5qehrac6l7dyhyzwzla6x4x78fectnfg6fq5jvt4y3zsczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jds6q6z</id>
    
      <title type="html">Learn: Concurrency vs parallelism Concurrency: several tasks are ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsd6p0zkt5qehrac6l7dyhyzwzla6x4x78fectnfg6fq5jvt4y3zsczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jds6q6z" />
    <content type="html">
      Learn: Concurrency vs parallelism&lt;br/&gt;&lt;br/&gt;Concurrency: several tasks are in progress at the same time, maybe taking turns on one core. Example: a server waiting on many database calls.&lt;br/&gt;Parallelism: work really runs at the same moment on several cores. Example: resizing 1,000 images.&lt;br/&gt;&lt;br/&gt;In .NET: waiting on I/O → async/await. CPU-heavy work → Parallel.For, or Task.Run in UI apps (on a server, Task.Run only moves work between pool threads). Both bring the same risk: shared data touched by two threads at once.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming&#34;&gt;https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-072
    </content>
    <updated>2026-10-27T18:38:04Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsryq9ee9qde527r6et69prd2gtryuz7gn9auvupu4vw03qk6jgvtqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jll7qkm</id>
    
      <title type="html">Learn: OAuth 2.0 vs OpenID Connect OAuth 2.0 is about access: it ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsryq9ee9qde527r6et69prd2gtryuz7gn9auvupu4vw03qk6jgvtqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jll7qkm" />
    <content type="html">
      Learn: OAuth 2.0 vs OpenID Connect&lt;br/&gt;&lt;br/&gt;OAuth 2.0 is about access: it lets an app call an API for the user, with an access token.&lt;br/&gt;OpenID Connect (OIDC) adds login on top: an ID token that says who the user is.&lt;br/&gt;The usual flow for web and mobile apps is the authorization code flow with PKCE: the user logs in at the identity provider, the app gets a code, and swaps it for tokens.&lt;br/&gt;Short version: access token → for the API; ID token → for the app, to know who logged in.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc&#34;&gt;https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-093
    </content>
    <updated>2026-10-27T18:07:51Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsp7pysm4r7yxh57ymucdj6nax5pxsu8q6wrgf3hsa0tvq5mxq4vrgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j06mpe4</id>
    
      <title type="html">Learn: Custom authorization policies When roles are not enough, ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsp7pysm4r7yxh57ymucdj6nax5pxsu8q6wrgf3hsa0tvq5mxq4vrgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j06mpe4" />
    <content type="html">
      Learn: Custom authorization policies&lt;br/&gt;&lt;br/&gt;When roles are not enough, write a policy:&lt;br/&gt;1. A requirement: a small class with the rule&amp;#39;s data, like MinimumAge = 18.&lt;br/&gt;2. A handler: AuthorizationHandler&amp;lt;TRequirement&amp;gt; that reads the user&amp;#39;s claims and calls context.Succeed(requirement).&lt;br/&gt;3. Register both, then use [Authorize(Policy = &amp;#34;Over18&amp;#34;)].&lt;br/&gt;For rules about one specific object (&amp;#34;may edit THIS order&amp;#34;), inject IAuthorizationService and call AuthorizeAsync(user, order, &amp;#34;CanEdit&amp;#34;).&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/aspnet/core/security/authorization/policies&#34;&gt;https://learn.microsoft.com/en-us/aspnet/core/security/authorization/policies&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-091
    </content>
    <updated>2026-10-27T17:37:55Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsd99hk54t7a5y764hljwd3pqsd4k3la4dvvzj2mjmvhs0t0dz6mxczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jj0aa2v</id>
    
      <title type="html">Learn: Breadth-first search (BFS) BFS visits the start node, then ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsd99hk54t7a5y764hljwd3pqsd4k3la4dvvzj2mjmvhs0t0dz6mxczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jj0aa2v" />
    <content type="html">
      Learn: Breadth-first search (BFS)&lt;br/&gt;&lt;br/&gt;BFS visits the start node, then all its neighbors, then their neighbors, and so on: rings of growing distance.&lt;br/&gt;&lt;br/&gt;It needs a Queue&amp;lt;T&amp;gt; for the nodes to visit and a HashSet&amp;lt;T&amp;gt; for the nodes already seen.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var graph = new Dictionary&amp;lt;int, int[]&amp;gt; { [1] = [2, 3], [2] = [4], [3] = [4, 5], [4] = [], [5] = [] };&lt;br/&gt;var seen = new HashSet&amp;lt;int&amp;gt; { 1 };&lt;br/&gt;var queue = new Queue&amp;lt;int&amp;gt;([1]);&lt;br/&gt;var order = new List&amp;lt;int&amp;gt;();&lt;br/&gt;while (queue.TryDequeue(out int n))&lt;br/&gt;{&lt;br/&gt;    order.Add(n);&lt;br/&gt;    foreach (int next in graph[n]) if (seen.Add(next)) queue.Enqueue(next); // mark when queued&lt;br/&gt;}&lt;br/&gt;Console.WriteLine(string.Join(&amp;#34; &amp;#34;, order));&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 1 2 3 4 5. Node 4 is reached twice, but queued once.&lt;br/&gt;&lt;br/&gt;Cost: O(V &#43; E). Because it goes ring by ring, BFS finds the route with the fewest edges.&lt;br/&gt;&lt;br/&gt;#tg001 · TG-001-N
    </content>
    <updated>2026-10-27T17:08:04Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsrvmr9j9sjhhzgnmg5fwt7knf4r3hhkwg3e999zppmyz3g99u3veczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jjfejz9</id>
    
      <title type="html">Learn: Think out loud In a coding interview, the interviewer ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsrvmr9j9sjhhzgnmg5fwt7knf4r3hhkwg3e999zppmyz3g99u3veczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jjfejz9" />
    <content type="html">
      Learn: Think out loud&lt;br/&gt;&lt;br/&gt;In a coding interview, the interviewer grades how you think, not only the final code. Say what you are trying, why, and what you would check next.&lt;br/&gt;&lt;br/&gt;Silence for five minutes looks the same as being stuck, even when you are close.&lt;br/&gt;&lt;br/&gt;#tip · TIP-001
    </content>
    <updated>2026-10-27T16:38:17Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs8kn7gvmq6uyqkd4zsr7wlev0sxv8qmapcgfxhtcqyman97czsz6szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jgw3fgk</id>
    
      <title type="html">Learn: Bitwise tricks Operators: &amp;amp; (and), | (or), ^ (xor), ~ ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs8kn7gvmq6uyqkd4zsr7wlev0sxv8qmapcgfxhtcqyman97czsz6szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jgw3fgk" />
    <content type="html">
      Learn: Bitwise tricks&lt;br/&gt;&lt;br/&gt;Operators: &amp;amp; (and), | (or), ^ (xor), ~ (not), &amp;lt;&amp;lt; and &amp;gt;&amp;gt; (shift).&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int n = 12; // 1100 in binary&lt;br/&gt;Console.WriteLine(n &amp;amp; 1);&lt;br/&gt;Console.WriteLine((n &amp;amp; (n - 1)) == 0);&lt;br/&gt;Console.WriteLine(5 ^ 3 ^ 5);&lt;br/&gt;Console.WriteLine(1 &amp;lt;&amp;lt; 4);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;n &amp;amp; 1 is 0 for even numbers. n &amp;gt; 0 &amp;amp;&amp;amp; (n &amp;amp; (n - 1)) == 0 is true only for powers of two (.NET also has int.IsPow2). x ^ x is 0, so xor finds the one number without a pair. 1 &amp;lt;&amp;lt; 4 is 16.&lt;br/&gt;Use them for flags, compact sets of booleans, and these classic interview tricks.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/bitwise-algorithms/&#34;&gt;https://www.geeksforgeeks.org/dsa/bitwise-algorithms/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-042
    </content>
    <updated>2026-10-27T16:07:58Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsrxs3vc0qdcdfpfm27yhz0ewalvnlvzymzcgv9rurrvrm0wl0hh8qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j5waesc</id>
    
      <title type="html">Learn: Task vs Thread A Thread is an operating system thread: ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsrxs3vc0qdcdfpfm27yhz0ewalvnlvzymzcgv9rurrvrm0wl0hh8qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j5waesc" />
    <content type="html">
      Learn: Task vs Thread&lt;br/&gt;&lt;br/&gt;A Thread is an operating system thread: expensive to create, and it holds memory the whole time.&lt;br/&gt;A Task is a promise of a result. CPU work started with Task.Run runs on a shared pool of threads. A task waiting for I/O (a web call, a database) holds no thread at all while it waits.&lt;br/&gt;&lt;br/&gt;In modern C#, use Task and async/await; create a Thread yourself only for rare long-running, dedicated work.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming&#34;&gt;https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-045
    </content>
    <updated>2026-10-27T15:38:02Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqstaetfz4yl38qv4rgsnvvtjfs33rynrgfup086npkqamdxac6a6qgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j8cd4st</id>
    
      <title type="html">Question: In a binary tree (not a search tree), find the first ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqstaetfz4yl38qv4rgsnvvtjfs33rynrgfup086npkqamdxac6a6qgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j8cd4st" />
    <content type="html">
      Question: In a binary tree (not a search tree), find the first common ancestor of two nodes: the lowest node that has both of them below it (a node counts as below itself).&lt;br/&gt;&lt;br/&gt;There are no parent links, and you may not store nodes in an extra data structure.&lt;br/&gt;&lt;br/&gt;(CtCI 4.8)&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg008 · TG-008-Q1
    </content>
    <updated>2026-10-27T15:07:54Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs8acdre4welm02gc02n5ghnq5tzjj0rcx3x6hhkj88pqcq4qnvp2qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jkurrnw</id>
    
      <title type="html">Recurse. A call returns p or q if it finds one of them, and null ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs8acdre4welm02gc02n5ghnq5tzjj0rcx3x6hhkj88pqcq4qnvp2qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jkurrnw" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqstaetfz4yl38qv4rgsnvvtjfs33rynrgfup086npkqamdxac6a6qgpz3mhxue69uhhyetvv9ujuerpd46hxtnfdut4lqpc&#39;&gt;nevent1q…lqpc&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Recurse. A call returns p or q if it finds one of them, and null if it finds neither. If a node gets a non-null answer from both sides, p and q split there: that node is the answer. Otherwise pass up whichever side found something.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;Node a = new(2), b = new(7);&lt;br/&gt;var root = new Node(8, new Node(4, a, new Node(6, new Node(5), b)), new Node(9));&lt;br/&gt;Console.WriteLine(Lca(root, a, b)?.Value);&lt;br/&gt;&lt;br/&gt;Node? Lca(Node? n, Node p, Node q)&lt;br/&gt;{&lt;br/&gt;    if (n == null || n == p || n == q) return n; // compares references&lt;br/&gt;    Node? l = Lca(n.Left, p, q), r = Lca(n.Right, p, q);&lt;br/&gt;    return l != null &amp;amp;&amp;amp; r != null ? n : l ?? r;&lt;br/&gt;}&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 4.&lt;br/&gt;&lt;br/&gt;n == p compares references: the same node object, not just the same value. O(n) time, O(height) stack.&lt;br/&gt;&lt;br/&gt;#tg008 · TG-008-A1
    </content>
    <updated>2026-10-27T15:07:54Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsy358f97s23wc69sg5zqj3vutr4wjrtyveqd3g27f7uvuam2n5zmqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jatf9me</id>
    
      <title type="html">Learn: Array What: items stored side by side in memory, each at ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsy358f97s23wc69sg5zqj3vutr4wjrtyveqd3g27f7uvuam2n5zmqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jatf9me" />
    <content type="html">
      Learn: Array&lt;br/&gt;&lt;br/&gt;What: items stored side by side in memory, each at an index.&lt;br/&gt;Cost: read or write a[i] in O(1); insert or delete in the middle O(n), because items must shift.&lt;br/&gt;Use it when: you know the size, you read by position a lot, or you loop over everything.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int[] a = { 10, 20, 30 };&lt;br/&gt;Console.WriteLine(a[1]);&lt;br/&gt;var list = new List&amp;lt;int&amp;gt;(a) { 40 };&lt;br/&gt;Console.WriteLine(list.Count);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 20, then 4. In C#, int[] has a fixed size; List&amp;lt;T&amp;gt; is an array that grows.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/array-data-structure-guide/&#34;&gt;https://www.geeksforgeeks.org/dsa/array-data-structure-guide/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-023
    </content>
    <updated>2026-10-27T14:38:04Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs2yefwwrsjh9jj064jgtj0dppjndfqqcadwfpepuhah2hkdz6vquqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j5nhgna</id>
    
      <title type="html">Learn: Interface or abstract class? Interface: a contract with no ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs2yefwwrsjh9jj064jgtj0dppjndfqqcadwfpepuhah2hkdz6vquqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j5nhgna" />
    <content type="html">
      Learn: Interface or abstract class?&lt;br/&gt;&lt;br/&gt;Interface: a contract with no instance fields (since C# 8 it can have default method bodies). Many per class. Best for &amp;#34;can do&amp;#34;: IComparable, IDisposable, services you inject.&lt;br/&gt;Abstract class: a partial implementation. Only one base class. Best for &amp;#34;is a&amp;#34; families that share code and state.&lt;br/&gt;&lt;br/&gt;A common interview answer: start with an interface; add an abstract base class when several implementations repeat the same code.&lt;br/&gt;&lt;br/&gt;#tip · TIP-050
    </content>
    <updated>2026-10-27T14:07:56Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsf5djne42k6s4n8u6y92dk5jh56dgvxnd34qeaudcxaen3n79yccgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jqvet0a</id>
    
      <title type="html">Learn: Linked list classic: reverse it Interviewers want your own ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsf5djne42k6s4n8u6y92dk5jh56dgvxnd34qeaudcxaen3n79yccgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jqvet0a" />
    <content type="html">
      Learn: Linked list classic: reverse it&lt;br/&gt;&lt;br/&gt;Interviewers want your own Node class, not LinkedList&amp;lt;T&amp;gt;. Walk the list and point each node back to the one before it. Save the next node first, or you lose the rest of the list.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;Node? cur = new Node(1, new Node(2, new Node(3, null))), prev = null;&lt;br/&gt;while (cur != null)&lt;br/&gt;{&lt;br/&gt;    Node? next = cur.Next; // save it before relinking&lt;br/&gt;    cur.Next = prev;&lt;br/&gt;    prev = cur;&lt;br/&gt;    cur = next;&lt;br/&gt;}&lt;br/&gt;Console.WriteLine($&amp;#34;{prev!.Value} {prev.Next!.Value} {prev.Next.Next!.Value}&amp;#34;);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 3 2 1. O(n) time, O(1) memory.&lt;br/&gt;The other classic: fast and slow pointers (fast moves 2, slow moves 1) find the middle, or detect a cycle when they meet.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/linked-list-data-structure/&#34;&gt;https://www.geeksforgeeks.org/dsa/linked-list-data-structure/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-063
    </content>
    <updated>2026-10-27T13:32:19Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs8u3xhp32vnracqk8xp90fjhaa8uqygd208pe3ry9tfar35hdwafszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j4y7tna</id>
    
      <title type="html">Question: You get a list of projects and a list of pairs (a, b): ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs8u3xhp32vnracqk8xp90fjhaa8uqygd208pe3ry9tfar35hdwafszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j4y7tna" />
    <content type="html">
      Question: You get a list of projects and a list of pairs (a, b): a must be built before b. Find an order to build all projects, or report that there is none.&lt;br/&gt;&lt;br/&gt;Example: core before data, core before auth, data before web, auth before web, web before tests. A project docs has no rules.&lt;br/&gt;&lt;br/&gt;(CtCI 4.7)&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg007 · TG-007-Q1
    </content>
    <updated>2026-10-27T13:08:08Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs95gqaw6vr5e4lzkgptgcnxw04yhzrmcdjdvhljtj0aqjaqwwdylgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jpe3ndr</id>
    
      <title type="html">Count, for each project, how many projects it waits on. Projects ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs95gqaw6vr5e4lzkgptgcnxw04yhzrmcdjdvhljtj0aqjaqwwdylgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jpe3ndr" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqs8u3xhp32vnracqk8xp90fjhaa8uqygd208pe3ry9tfar35hdwafspz3mhxue69uhhyetvv9ujuerpd46hxtnfduzhx7sx&#39;&gt;nevent1q…x7sx&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Count, for each project, how many projects it waits on. Projects with 0 are ready: put them in a queue. Take one, add it to the order, and lower the count of every project that waits on it. A count that drops to 0 makes that project ready.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var waitingOn = projects.ToDictionary(p =&amp;gt; p, p =&amp;gt; deps.Count(x =&amp;gt; x.After == p));&lt;br/&gt;var ready = new Queue&amp;lt;string&amp;gt;(projects.Where(p =&amp;gt; waitingOn[p] == 0));&lt;br/&gt;var order = new List&amp;lt;string&amp;gt;();&lt;br/&gt;while (ready.TryDequeue(out var p))&lt;br/&gt;{&lt;br/&gt;    order.Add(p);&lt;br/&gt;    foreach (var x in deps.Where(x =&amp;gt; x.Before == p))&lt;br/&gt;        if (--waitingOn[x.After] == 0) ready.Enqueue(x.After);&lt;br/&gt;}&lt;br/&gt;Console.WriteLine(order.Count == projects.Length ? string.Join(&amp;#34; &amp;#34;, order) : &amp;#34;cycle&amp;#34;);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints core docs data auth web tests.&lt;br/&gt;&lt;br/&gt;This is a topological sort (Kahn&amp;#39;s algorithm). Any order that keeps the rules is correct.&lt;br/&gt;&lt;br/&gt;#tg007 · TG-007-A1
    </content>
    <updated>2026-10-27T13:08:08Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsv0rrml4zr9fs442wcayy3tk3ue2n5l2zee3exzvtdcqwjcwc080szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jaatlh5</id>
    
      <title type="html">Learn: Scoped services in a singleton or BackgroundService A ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsv0rrml4zr9fs442wcayy3tk3ue2n5l2zee3exzvtdcqwjcwc080szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jaatlh5" />
    <content type="html">
      Learn: Scoped services in a singleton or BackgroundService&lt;br/&gt;&lt;br/&gt;A BackgroundService is a singleton, but a DbContext is scoped. Injecting the DbContext directly would keep one DbContext forever.&lt;br/&gt;Fix: inject IServiceScopeFactory. For each piece of work: create a scope, get the DbContext from it, and dispose the scope when done.&lt;br/&gt;In Development, ASP.NET Core checks this for you (scope validation) and throws at startup if a singleton depends on a scoped service.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection&#34;&gt;https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-096
    </content>
    <updated>2026-10-27T12:38:11Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsyvakur7dkf46pq6clua7g3z84ype97frffpwkj6sv4dkect6s64szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jtyu5rc</id>
    
      <title type="html">Learn: SOLID in one post S: Single responsibility. One class, one ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsyvakur7dkf46pq6clua7g3z84ype97frffpwkj6sv4dkect6s64szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jtyu5rc" />
    <content type="html">
      Learn: SOLID in one post&lt;br/&gt;&lt;br/&gt;S: Single responsibility. One class, one reason to change.&lt;br/&gt;O: Open/closed. Add behavior with new code, not by editing working code.&lt;br/&gt;L: Liskov substitution. A subclass must work anywhere its base class works.&lt;br/&gt;I: Interface segregation. Many small interfaces beat one huge one.&lt;br/&gt;D: Dependency inversion. Depend on interfaces, not concrete classes (this is what DI makes easy).&lt;br/&gt;&lt;br/&gt;In an interview, give one real example for each letter you mention.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://roadmap.sh/software-design-architecture&#34;&gt;https://roadmap.sh/software-design-architecture&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-071
    </content>
    <updated>2026-10-27T12:07:55Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsfd8f5ggqk5424ptdppjqdah3vakxfgvgeczmts2vkwu9cm850kfgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jsvqhld</id>
    
      <title type="html">Learn: Building strings in a loop A C# string can&amp;#39;t change, ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsfd8f5ggqk5424ptdppjqdah3vakxfgvgeczmts2vkwu9cm850kfgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jsvqhld" />
    <content type="html">
      Learn: Building strings in a loop&lt;br/&gt;&lt;br/&gt;A C# string can&amp;#39;t change, so result &#43;= text creates a brand new string every time and copies everything so far. In a loop that adds up to O(n²).&lt;br/&gt;&lt;br/&gt;The docs warn that many repeated changes to a string cost a lot of performance. Use a StringBuilder, then call ToString() once at the end.&lt;br/&gt;&lt;br/&gt;#tip · TIP-019
    </content>
    <updated>2026-10-27T11:37:50Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqstazj6xy9qw23zmpc59alezntz5ax6sutkldxm0mjhsh0jw0h50rczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38ja3jxr4</id>
    
      <title type="html">Question: A simpler version: at each node, call a separate ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqstazj6xy9qw23zmpc59alezntz5ax6sutkldxm0mjhsh0jw0h50rczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38ja3jxr4" />
    <content type="html">
      Question: A simpler version: at each node, call a separate Height(left) and Height(right), compare them, then check both children the same way.&lt;br/&gt;&lt;br/&gt;It is correct. What does it cost?&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg004 · TG-004-Q2
    </content>
    <updated>2026-10-27T11:07:58Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsf5mzyapcz4nkynmkhzvuvyw5c55cv9vp6qg4av4v6f8r97lsmlygzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jzq4n6a</id>
    
      <title type="html">Height(subtree) visits every node of that subtree. Doing it at ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsf5mzyapcz4nkynmkhzvuvyw5c55cv9vp6qg4av4v6f8r97lsmlygzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jzq4n6a" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqstazj6xy9qw23zmpc59alezntz5ax6sutkldxm0mjhsh0jw0h50rcpz3mhxue69uhhyetvv9ujuerpd46hxtnfduk97te2&#39;&gt;nevent1q…7te2&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Height(subtree) visits every node of that subtree. Doing it at every node means each node is counted once for each of its ancestors.&lt;br/&gt;&lt;br/&gt;In a balanced tree, a node has about log n ancestors, so the check is O(n log n).&lt;br/&gt;&lt;br/&gt;The one-pass version computes each height once and reuses it in the parent: O(n). Interviewers often ask for this improvement.&lt;br/&gt;&lt;br/&gt;#tg004 · TG-004-A2
    </content>
    <updated>2026-10-27T11:07:58Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsyavjdqnva8v88vxynjsql9557ag57kjwfurntfp805z49sa8qd9qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jzs620p</id>
    
      <title type="html">Learn: The lock statement lock lets only one thread at a time run ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsyavjdqnva8v88vxynjsql9557ag57kjwfurntfp805z49sa8qd9qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jzs620p" />
    <content type="html">
      Learn: The lock statement&lt;br/&gt;&lt;br/&gt;lock lets only one thread at a time run a block of code; the others wait.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var sync = new object();&lt;br/&gt;int total = 0;&lt;br/&gt;Parallel.For(0, 1000, i =&amp;gt; { lock (sync) total &#43;= i; });&lt;br/&gt;Console.WriteLine(total);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 499500 (0 &#43; 1 &#43; ... &#43; 999) every time. On a plain object, lock is Monitor.Enter/Exit in a try/finally, so it is released even when an exception is thrown, and the same thread may enter it again (it is reentrant).&lt;br/&gt;Rules: lock on a private object, never on this, a string or a type. Keep the block short. You can&amp;#39;t await inside a lock.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/lock&#34;&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/lock&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-074
    </content>
    <updated>2026-10-27T10:37:53Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsd40gdqcv4vyal3c2fv35ecjezn63ese3yvvy463jgcyk4kad64cgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jvrtt7q</id>
    
      <title type="html">Learn: ASP.NET Core Identity Identity is the built-in user ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsd40gdqcv4vyal3c2fv35ecjezn63ese3yvvy463jgcyk4kad64cgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jvrtt7q" />
    <content type="html">
      Learn: ASP.NET Core Identity&lt;br/&gt;&lt;br/&gt;Identity is the built-in user system: accounts, passwords, roles, email confirmation, lockout after failed logins, and two-factor login. Users can also log in with an external provider.&lt;br/&gt;It stores passwords as PBKDF2 hashes (salted and repeated many times), never as plain text. Data goes through a pluggable store, usually EF Core with SQL Server. Lockout only counts failed logins when you pass lockoutOnFailure: true.&lt;br/&gt;Main classes: UserManager (create users, check passwords, roles) and SignInManager (log in and out).&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity&#34;&gt;https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-086
    </content>
    <updated>2026-10-27T10:07:52Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqstg0s84vr5spxulkuuktvz7vpp4mhx6cmqcnjmwdt3wcd94pnrqvszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jdwpc9c</id>
    
      <title type="html">Learn: Starvation Starvation: a thread is ready to work but never ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqstg0s84vr5spxulkuuktvz7vpp4mhx6cmqcnjmwdt3wcd94pnrqvszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jdwpc9c" />
    <content type="html">
      Learn: Starvation&lt;br/&gt;&lt;br/&gt;Starvation: a thread is ready to work but never gets the resource or CPU time, because others keep taking it. Unlike a deadlock, the program still moves; one part just never does.&lt;br/&gt;Classic example: a lock that is not fair. Monitor (lock) doesn&amp;#39;t promise first come, first served, so under heavy use one thread can keep losing.&lt;br/&gt;In .NET servers, a related problem is thread-pool starvation: blocking calls (.Result, .Wait()) hold pool threads, so new requests wait.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/standard/threading/managed-threading-best-practices&#34;&gt;https://learn.microsoft.com/en-us/dotnet/standard/threading/managed-threading-best-practices&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-080
    </content>
    <updated>2026-10-27T09:38:00Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs8cy08qc2wpvnk824agjtedju8z2j80j9tfmhuu7unrws05cvlvngzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38je3kv2d</id>
    
      <title type="html">Question: Why not just insert the values one by one, in the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs8cy08qc2wpvnk824agjtedju8z2j80j9tfmhuu7unrws05cvlvngzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38je3kv2d" />
    <content type="html">
      Question: Why not just insert the values one by one, in the array&amp;#39;s order, into a normal binary search tree?&lt;br/&gt;&lt;br/&gt;What tree do you get from 1, 2, 3, 4, 5, 6, 7?&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg002 · TG-002-Q3
    </content>
    <updated>2026-10-27T09:07:59Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsp7t9urklkrs6yet7x5x92kpr3ahparjmqyz62tc89apupn8p2swczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jf6yxmn</id>
    
      <title type="html">Each new value is bigger than everything before it, so it always ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsp7t9urklkrs6yet7x5x92kpr3ahparjmqyz62tc89apupn8p2swczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jf6yxmn" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqs8cy08qc2wpvnk824agjtedju8z2j80j9tfmhuu7unrws05cvlvngpz3mhxue69uhhyetvv9ujuerpd46hxtnfdu9dm0pk&#39;&gt;nevent1q…m0pk&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Each new value is bigger than everything before it, so it always goes right. You get a chain, like a linked list.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;Node? root = null;&lt;br/&gt;for (int v = 1; v &amp;lt;= 7; v&#43;&#43;) root = Insert(root, v);&lt;br/&gt;Console.WriteLine(Height(root));&lt;br/&gt;&lt;br/&gt;Node Insert(Node? n, int v)&lt;br/&gt;{&lt;br/&gt;    if (n == null) return new Node(v);&lt;br/&gt;    if (v &amp;lt; n.Value) n.Left = Insert(n.Left, v); else n.Right = Insert(n.Right, v);&lt;br/&gt;    return n;&lt;br/&gt;}&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 7: one level per value.&lt;br/&gt;&lt;br/&gt;Searching that tree is O(n) instead of O(log n). Sorted input is the worst case for a plain BST, and it is common in real data.&lt;br/&gt;&lt;br/&gt;#tg002 · TG-002-A3
    </content>
    <updated>2026-10-27T09:07:59Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs85l90hydukp27eumwayhpkzq7u2c9saszsn0cnzeqjeeqcs4xekgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jgyxktm</id>
    
      <title type="html">Learn: Hashing rules in C# Equal objects must have equal hash ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs85l90hydukp27eumwayhpkzq7u2c9saszsn0cnzeqjeeqcs4xekgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jgyxktm" />
    <content type="html">
      Learn: Hashing rules in C#&lt;br/&gt;&lt;br/&gt;Equal objects must have equal hash codes, so if you override Equals, override GetHashCode too. Records do both for you.&lt;br/&gt;Don&amp;#39;t read a missing key with dict[key]: it throws KeyNotFoundException. Use TryGetValue.&lt;br/&gt;Lookups are O(1) on average, but O(n) in the worst case, when many keys collide.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var ages = new Dictionary&amp;lt;string, int&amp;gt; { [&amp;#34;ann&amp;#34;] = 30 };&lt;br/&gt;Console.WriteLine(ages.TryGetValue(&amp;#34;bob&amp;#34;, out int age) ? age : -1);&lt;br/&gt;var set = new HashSet&amp;lt;Point&amp;gt; { new Point(1, 2) };&lt;br/&gt;Console.WriteLine(set.Contains(new Point(1, 2)));&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints -1 (no bob), then True (records compare by value).&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/hashing-data-structure/&#34;&gt;https://www.geeksforgeeks.org/dsa/hashing-data-structure/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-065
    </content>
    <updated>2026-10-27T08:37:51Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsg2ph698s9vnlk7644tzktam6dqnnyl4ehay2amt5met559lrzlqgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jqyngng</id>
    
      <title type="html">Learn: Linked list What: nodes, each holding a value and a link ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsg2ph698s9vnlk7644tzktam6dqnnyl4ehay2amt5met559lrzlqgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jqyngng" />
    <content type="html">
      Learn: Linked list&lt;br/&gt;&lt;br/&gt;What: nodes, each holding a value and a link to the next node.&lt;br/&gt;Cost: insert or remove at a node you already hold is O(1); reaching item k is O(k), because you must walk.&lt;br/&gt;Use it when: you add and remove at the ends or in the middle a lot, and rarely jump to a position. Example: an LRU cache, which pairs a Dictionary (find a node fast) with a linked list (move it to the front).&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var list = new LinkedList&amp;lt;int&amp;gt;();&lt;br/&gt;list.AddLast(2); list.AddLast(3); list.AddFirst(1);&lt;br/&gt;Console.WriteLine(string.Join(&amp;#34; &amp;#34;, list));&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 1 2 3. .NET&amp;#39;s LinkedList&amp;lt;T&amp;gt; is doubly linked. In practice List&amp;lt;T&amp;gt; is often faster, because its items sit next to each other in memory.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/linked-list-data-structure/&#34;&gt;https://www.geeksforgeeks.org/dsa/linked-list-data-structure/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-026
    </content>
    <updated>2026-10-27T07:37:55Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsw64dqzqn69pljeqxdq0m2h2vj0h0gwwd0yaydgq5lu4kae67lmhczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jl8t2zt</id>
    
      <title type="html">It never stops. Node 5 can&amp;#39;t be reached, so the search never ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsw64dqzqn69pljeqxdq0m2h2vj0h0gwwd0yaydgq5lu4kae67lmhczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jl8t2zt" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqs2gupcxe07uda5g3t56a9ye34qvdplrjf4n3tl83tmeeqpf7sjgwgpz3mhxue69uhhyetvv9ujuerpd46hxtnfduejw6kn&#39;&gt;nevent1q…w6kn&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;It never stops. Node 5 can&amp;#39;t be reached, so the search never returns true. Meanwhile the cycle 1 → 2 → 4 → 1 keeps putting the same nodes back in the queue, forever.&lt;br/&gt;&lt;br/&gt;The seen set is what makes the search finish: each node goes into the queue at most once.&lt;br/&gt;&lt;br/&gt;Add the node to seen when you enqueue it, not when you dequeue it. Otherwise the same node can sit in the queue many times.&lt;br/&gt;&lt;br/&gt;#tg001 · TG-001-A3
    </content>
    <updated>2026-10-27T07:07:59Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs2gupcxe07uda5g3t56a9ye34qvdplrjf4n3tl83tmeeqpf7sjgwgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j2kcae8</id>
    
      <title type="html">Question: In HasRoute, remove the seen set and enqueue every ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs2gupcxe07uda5g3t56a9ye34qvdplrjf4n3tl83tmeeqpf7sjgwgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j2kcae8" />
    <content type="html">
      Question: In HasRoute, remove the seen set and enqueue every neighbor.&lt;br/&gt;&lt;br/&gt;What happens for HasRoute(1, 5) on the same graph (1→2, 2→3, 2→4, 4→1)?&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg001 · TG-001-Q3
    </content>
    <updated>2026-10-27T07:07:59Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs0qzf4cnavavx7jsjrkx0ak0y2a04t8wk3cvqem3cdup2792a5pxczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j5k4gk3</id>
    
      <title type="html">Learn: Grid problems: flood fill How to walk a grid in four ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs0qzf4cnavavx7jsjrkx0ak0y2a04t8wk3cvqem3cdup2792a5pxczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j5k4gk3" />
    <content type="html">
      In reply to &lt;a href=&#39;/naddr1qqt4gj2s95crvw2qxgcryd3dxycz6v3h2scrsvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsyg8x3gy9d6gdnxtmraepayzjfxykgyka2upen2v8kt506hnlel3z0ypsgqqqw4rse3fp28&#39;&gt;naddr1qq…fp28&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Learn: Grid problems: flood fill&lt;br/&gt;&lt;br/&gt;How to walk a grid in four directions, stay inside the bounds, and count connected areas.&lt;br/&gt;&lt;br/&gt;Read the full article:&lt;blockquote class=&#34;border-l-05rem border-l-strongpink border-solid&#34;&gt;&lt;div class=&#34;-ml-4 bg-gradient-to-r from-gray-100 dark:from-zinc-800 to-transparent mr-0 mt-0 mb-4 pl-4 pr-2 py-2&#34;&gt;quoting  &lt;span itemprop=&#34;mentions&#34; itemscope itemtype=&#34;https://schema.org/Article&#34;&gt;&lt;a itemprop=&#34;url&#34; href=&#34;/naddr1qqt4gj2s95crvw2qxgcryd3dxycz6v3h2scrsvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszrthwden5te0dehhxtnvdakqz9nhwden5te0wfjkccte9ec8y6tdv9kzumn9wspzpe52pptwjrvej7clwg0fq5jf39jp9h2hqwv6npajar74ul70ugneqvzqqqr4guu3hmrd&#34; class=&#34;bg-lavender dark:prose:text-neutral-50 dark:text-neutral-50 dark:bg-garnet px-1&#34;&gt;naddr1qq…hmrd&lt;/a&gt;&lt;/span&gt;&lt;br/&gt; &lt;/div&gt; 
&lt;h2 id=&#34;grid-problems-flood-fill-2&#34;&gt;Grid problems: flood fill&lt;/h2&gt;

&lt;p&gt;Many interview questions give you a grid of cells: a map, an image, a maze. The key move is &lt;strong&gt;flood fill&lt;/strong&gt;: from one cell, visit every connected cell of the same kind.&lt;/p&gt;

&lt;h3 id=&#34;counting-areas-2&#34;&gt;Counting areas&lt;/h3&gt;

&lt;p&gt;Count the separate areas of &lt;code&gt;1&lt;/code&gt;s (cells connected up, down, left or right):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;string[] map = { &amp;#34;11000&amp;#34;, &amp;#34;11001&amp;#34;, &amp;#34;00001&amp;#34; };
int rows = map.Length, cols = map[0].Length, areas = 0; var seen = new bool[rows, cols];
for (int r = 0; r &amp;lt; rows; r&#43;&#43;) for (int c = 0; c &amp;lt; cols; c&#43;&#43;)
    if (map[r][c] == &amp;#39;1&amp;#39; &amp;amp;&amp;amp; !seen[r, c]) { areas&#43;&#43;; Fill(r, c); }
Console.WriteLine(areas);
void Fill(int r, int c)
{
    if (r &amp;lt; 0 || c &amp;lt; 0 || r &amp;gt;= rows || c &amp;gt;= cols || seen[r, c] || map[r][c] == &amp;#39;0&amp;#39;) return;
    seen[r, c] = true; Fill(r &#43; 1, c); Fill(r - 1, c); Fill(r, c &#43; 1); Fill(r, c - 1);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It prints &lt;code&gt;2&lt;/code&gt;: one area of four cells top-left, and one of two cells on the right.&lt;/p&gt;

&lt;h3 id=&#34;the-pattern-2&#34;&gt;The pattern&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Loop over every cell.&lt;/li&gt;
&lt;li&gt;When you find an unvisited &lt;code&gt;1&lt;/code&gt;, count a new area and flood-fill it.&lt;/li&gt;
&lt;li&gt;The fill marks cells as seen and spreads in four directions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check the bounds first&lt;/strong&gt; (row and column inside the grid) before reading a cell; this is where most bugs are.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&#34;cost-2&#34;&gt;Cost&lt;/h3&gt;

&lt;p&gt;Each cell is visited a constant number of times: &lt;strong&gt;O(rows × cols)&lt;/strong&gt; time. The &lt;code&gt;seen&lt;/code&gt; grid is O(rows × cols) memory. The recursion can go as deep as the area is big; for very large grids, use a queue (breadth-first) instead of recursion.&lt;/p&gt;

&lt;h3 id=&#34;c-note-2&#34;&gt;C# note&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;int[,]&lt;/code&gt; is one rectangular block; &lt;code&gt;int[][]&lt;/code&gt; (jagged) is an array of arrays, where rows can differ in length. Many online judges give you jagged arrays.&lt;/p&gt;

&lt;p&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/matrix/&#34;&gt;https://www.geeksforgeeks.org/dsa/matrix/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;#tip · TIP-069&lt;/p&gt;
 &lt;/blockquote&gt;&lt;br/&gt;#tip · TIP-069
    </content>
    <updated>2026-10-27T06:37:53Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsqtczzf44m0rl5srku23620p5cuhth4usx5rl02g9ywu8pjplfh2czyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jkf6fy3</id>
    
      <title type="html">Learn: IDisposable and using Some objects hold things the garbage ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsqtczzf44m0rl5srku23620p5cuhth4usx5rl02g9ywu8pjplfh2czyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jkf6fy3" />
    <content type="html">
      Learn: IDisposable and using&lt;br/&gt;&lt;br/&gt;Some objects hold things the garbage collector doesn&amp;#39;t manage well: files, network connections, database connections. They implement IDisposable, and you must call Dispose when done.&lt;br/&gt;using does it for you, even if an exception is thrown:&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;using (var r = new Resource()) Console.WriteLine(&amp;#34;working&amp;#34;);&lt;br/&gt;Console.WriteLine(&amp;#34;after&amp;#34;);&lt;br/&gt;&lt;br/&gt;class Resource : IDisposable { public void Dispose() =&amp;gt; Console.WriteLine(&amp;#34;cleaned up&amp;#34;); }&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints working, cleaned up, after.&lt;br/&gt;Shorter form: using var file = File.OpenRead(path); disposes at the end of the method or block.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using&#34;&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-101
    </content>
    <updated>2026-10-27T06:07:57Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsvhxepfhtgrr697f5vkpuxs3vvlqs9j8xu07v85n94gxn0z5q84uszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jpj3e6f</id>
    
      <title type="html">Learn: Making microservices resilient Timeouts, retries with ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsvhxepfhtgrr697f5vkpuxs3vvlqs9j8xu07v85n94gxn0z5q84uszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jpj3e6f" />
    <content type="html">
      In reply to &lt;a href=&#39;/naddr1qqt4gj2s95crjw2qxgcryd3dxycz6v3k2serzvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsyg8x3gy9d6gdnxtmraepayzjfxykgyka2upen2v8kt506hnlel3z0ypsgqqqw4rss0yuje&#39;&gt;naddr1qq…yuje&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Learn: Making microservices resilient&lt;br/&gt;&lt;br/&gt;Timeouts, retries with backoff, circuit breakers, idempotency and the outbox: how services survive each other&amp;#39;s failures.&lt;br/&gt;&lt;br/&gt;Read the full article:&lt;blockquote class=&#34;border-l-05rem border-l-strongpink border-solid&#34;&gt;&lt;div class=&#34;-ml-4 bg-gradient-to-r from-gray-100 dark:from-zinc-800 to-transparent mr-0 mt-0 mb-4 pl-4 pr-2 py-2&#34;&gt;quoting  &lt;span itemprop=&#34;mentions&#34; itemscope itemtype=&#34;https://schema.org/Article&#34;&gt;&lt;a itemprop=&#34;url&#34; href=&#34;/naddr1qqt4gj2s95crjw2qxgcryd3dxycz6v3k2serzvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszrthwden5te0dehhxtnvdakqz9nhwden5te0wfjkccte9ec8y6tdv9kzumn9wspzpe52pptwjrvej7clwg0fq5jf39jp9h2hqwv6npajar74ul70ugneqvzqqqr4guxwa08n&#34; class=&#34;bg-lavender dark:prose:text-neutral-50 dark:text-neutral-50 dark:bg-garnet px-1&#34;&gt;naddr1qq…a08n&lt;/a&gt;&lt;/span&gt;&lt;br/&gt; &lt;/div&gt; 
&lt;h2 id=&#34;making-microservices-resilient-2&#34;&gt;Making microservices resilient&lt;/h2&gt;

&lt;p&gt;In a microservice system, some call always fails somewhere: a service restarts, the network hiccups, a database is slow. Design for these partial failures instead of hoping they don&amp;#39;t happen.&lt;/p&gt;

&lt;h3 id=&#34;the-toolbox-2&#34;&gt;The toolbox&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Timeout:&lt;/strong&gt; never wait forever for another service. A slow dependency must not hold your threads and requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Retry with backoff:&lt;/strong&gt; retry short, temporary failures, waiting longer each time (for example 200 ms, 400 ms, 800 ms) and adding a little randomness (jitter), so many clients don&amp;#39;t retry at the same moment.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Circuit breaker:&lt;/strong&gt; after many failures, stop calling the broken service for a while and fail fast. Then try again carefully.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bulkhead:&lt;/strong&gt; limit how many calls can go to one dependency, so one slow service can&amp;#39;t use up everything.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fallback:&lt;/strong&gt; return a cached or default answer when a call fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In .NET, &lt;code&gt;Microsoft.Extensions.Http.Resilience&lt;/code&gt; (built on Polly) adds these to &lt;code&gt;HttpClient&lt;/code&gt; in a few lines.&lt;/p&gt;

&lt;h3 id=&#34;a-retry-by-hand-2&#34;&gt;A retry, by hand&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;int calls = 0;
Console.WriteLine(await RetryAsync(() =&amp;gt; &#43;&#43;calls &amp;lt; 3 ? throw new HttpRequestException(&amp;#34;busy&amp;#34;) : Task.FromResult(&amp;#34;ok&amp;#34;)));
async Task&amp;lt;string&amp;gt; RetryAsync(Func&amp;lt;Task&amp;lt;string&amp;gt;&amp;gt; action)
{
    for (int attempt = 1; ; attempt&#43;&#43;)
    {
        try { return await action(); }
        catch (HttpRequestException) when (attempt &amp;lt; 5) { await Task.Delay(10 * (1 &amp;lt;&amp;lt; attempt)); } // wait longer each time
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It prints &lt;code&gt;ok&lt;/code&gt;: the first two calls fail, the third succeeds, with a growing wait between tries.&lt;/p&gt;

&lt;h3 id=&#34;data-across-services-2&#34;&gt;Data across services&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Idempotency:&lt;/strong&gt; retries mean the same request can arrive twice. Make handlers safe to repeat, for example with a request ID.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Outbox:&lt;/strong&gt; save the business change and the message to send in the same database transaction; a background job publishes the messages. No lost events, but a message may be published twice, so consumers must be idempotent.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Saga:&lt;/strong&gt; a business process across services is a series of local steps, each with a compensating step to undo it if a later step fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;at-the-edge-2&#34;&gt;At the edge&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;API gateway&lt;/strong&gt; gives clients one entry point and handles routing, authentication and rate limiting for the services behind it.&lt;/p&gt;

&lt;p&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/&#34;&gt;https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;#tip · TIP-099&lt;/p&gt;
 &lt;/blockquote&gt;&lt;br/&gt;#tip · TIP-099
    </content>
    <updated>2026-10-26T19:37:57Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqspcmdudm3pdxk5xd9kxf936hwxgwgffas2wy3q3q8rht45f7ys3kgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jl0a8qk</id>
    
      <title type="html">Learn: Queue&amp;lt;T&amp;gt;: first in, first out A queue gives items ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqspcmdudm3pdxk5xd9kxf936hwxgwgffas2wy3q3q8rht45f7ys3kgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jl0a8qk" />
    <content type="html">
      Learn: Queue&amp;lt;T&amp;gt;: first in, first out&lt;br/&gt;&lt;br/&gt;A queue gives items back in the order they came in. Enqueue adds at the back, Dequeue removes from the front, and Peek looks at the front without removing it.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var q = new Queue&amp;lt;string&amp;gt;();&lt;br/&gt;q.Enqueue(&amp;#34;first&amp;#34;); q.Enqueue(&amp;#34;second&amp;#34;);&lt;br/&gt;Console.WriteLine(q.Peek());&lt;br/&gt;Console.WriteLine(q.Dequeue() &#43; &amp;#34; &amp;#34; &#43; q.Dequeue());&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints first, then first second.&lt;br/&gt;&lt;br/&gt;Queues are the tool for &amp;#34;handle in order of arrival&amp;#34;: jobs, messages, and breadth-first search.&lt;br/&gt;&lt;br/&gt;#sq006 · SQ-006-N
    </content>
    <updated>2026-10-26T19:08:02Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsxhyq282thu2enq52pkt9g2qkwfh8t3jneu97rvglwx93r6w3g25szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jl5p743</id>
    
      <title type="html">Learn: Concurrency vs parallelism Concurrency: several tasks are ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsxhyq282thu2enq52pkt9g2qkwfh8t3jneu97rvglwx93r6w3g25szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jl5p743" />
    <content type="html">
      Learn: Concurrency vs parallelism&lt;br/&gt;&lt;br/&gt;Concurrency: several tasks are in progress at the same time, maybe taking turns on one core. Example: a server waiting on many database calls.&lt;br/&gt;Parallelism: work really runs at the same moment on several cores. Example: resizing 1,000 images.&lt;br/&gt;&lt;br/&gt;In .NET: waiting on I/O → async/await. CPU-heavy work → Parallel.For, or Task.Run in UI apps (on a server, Task.Run only moves work between pool threads). Both bring the same risk: shared data touched by two threads at once.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming&#34;&gt;https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-072
    </content>
    <updated>2026-10-26T18:38:04Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsprgswsntfhxs7cms0wtg4vafjy48n9fhjcgdmj0d4relgqfvwnngzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jw7yzed</id>
    
      <title type="html">Learn: Costs worth knowing by heart Read array[i]: O(1) Search an ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsprgswsntfhxs7cms0wtg4vafjy48n9fhjcgdmj0d4relgqfvwnngzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jw7yzed" />
    <content type="html">
      Learn: Costs worth knowing by heart&lt;br/&gt;&lt;br/&gt;Read array[i]: O(1)&lt;br/&gt;Search an unsorted array: O(n)&lt;br/&gt;Sort: O(n log n)&lt;br/&gt;HashSet or Dictionary lookup: O(1) on average&lt;br/&gt;Search a sorted array with binary search: O(log n)&lt;br/&gt;&lt;br/&gt;When you state a solution in an interview, say its Big-O with it.&lt;br/&gt;&lt;br/&gt;#tip · TIP-005
    </content>
    <updated>2026-10-26T18:08:16Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs9pf2snrnutq6l7cgyqahkdhx07zurqvy2gnkduuv588k84txn56gzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jfwpefd</id>
    
      <title type="html">Learn: PriorityQueue for &amp;#34;smallest first&amp;#34; .NET has ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs9pf2snrnutq6l7cgyqahkdhx07zurqvy2gnkduuv588k84txn56gzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jfwpefd" />
    <content type="html">
      Learn: PriorityQueue for &amp;#34;smallest first&amp;#34;&lt;br/&gt;&lt;br/&gt;.NET has PriorityQueue&amp;lt;TElement, TPriority&amp;gt;. Dequeue always returns the item with the lowest priority value.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var pq = new PriorityQueue&amp;lt;string, int&amp;gt;();&lt;br/&gt;pq.Enqueue(&amp;#34;low&amp;#34;, 5); pq.Enqueue(&amp;#34;urgent&amp;#34;, 1); pq.Enqueue(&amp;#34;mid&amp;#34;, 3);&lt;br/&gt;Console.WriteLine(pq.Dequeue());&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints urgent. Use it for &amp;#34;top k&amp;#34; problems, merging k sorted lists, and Dijkstra&amp;#39;s shortest path.&lt;br/&gt;&lt;br/&gt;#tip · TIP-011
    </content>
    <updated>2026-10-26T17:37:56Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsg8zzce5sa82x7z5dn4jug0cgzzx494l4hl94aml2wnuxrh5yw2cczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jhy475k</id>
    
      <title type="html">Learn: Which end of a Stack&amp;lt;T&amp;gt; is the top? new ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsg8zzce5sa82x7z5dn4jug0cgzzx494l4hl94aml2wnuxrh5yw2cczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jhy475k" />
    <content type="html">
      Learn: Which end of a Stack&amp;lt;T&amp;gt; is the top?&lt;br/&gt;&lt;br/&gt;new Stack&amp;lt;int&amp;gt;(items) pushes the items in order, so the last item ends up on top.&lt;br/&gt;&lt;br/&gt;foreach, ToArray and string.Join all go from the top down, not in the order you added the items.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var s = new Stack&amp;lt;int&amp;gt;(new[] { 1, 2, 3 });&lt;br/&gt;Console.WriteLine(s.Peek());&lt;br/&gt;Console.WriteLine(string.Join(&amp;#34; &amp;#34;, s));&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 3, then 3 2 1.&lt;br/&gt;&lt;br/&gt;This catches people when they print a stack to check their answer, so say &amp;#34;read from the top&amp;#34;.&lt;br/&gt;&lt;br/&gt;#sq005 · SQ-005-N
    </content>
    <updated>2026-10-26T17:08:02Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqst7lm096sh2ajz2gmauk0axccqq6heckg08prlmvmm0qvd6apzmaczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jc5m8wx</id>
    
      <title type="html">Learn: From recursion to memoization Plain recursive Fibonacci ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqst7lm096sh2ajz2gmauk0axccqq6heckg08prlmvmm0qvd6apzmaczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jc5m8wx" />
    <content type="html">
      Learn: From recursion to memoization&lt;br/&gt;&lt;br/&gt;Plain recursive Fibonacci recomputes the same values again and again: O(2ⁿ). Remember each answer the first time, and every value is computed once: O(n).&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var memo = new Dictionary&amp;lt;int, long&amp;gt;();&lt;br/&gt;Console.WriteLine(Fib(60));&lt;br/&gt;long Fib(int n)&lt;br/&gt;{&lt;br/&gt;    if (n &amp;lt; 2) return n;&lt;br/&gt;    if (memo.TryGetValue(n, out long known)) return known;&lt;br/&gt;    return memo[n] = Fib(n - 1) &#43; Fib(n - 2);&lt;br/&gt;}&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 1548008755920 at once. Plain recursion would take hours for n = 60.&lt;br/&gt;This is the first step of dynamic programming: overlapping subproblems &#43; a cache.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/recursion-algorithms/&#34;&gt;https://www.geeksforgeeks.org/dsa/recursion-algorithms/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-097
    </content>
    <updated>2026-10-26T16:37:57Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsxxmrtndgulz6gf9ahy8pz57w7slh8fmtssxaj4qpj2kl7sn0tndqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jdhl4f7</id>
    
      <title type="html">Learn: Async mistakes interviewers ask about async void: ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsxxmrtndgulz6gf9ahy8pz57w7slh8fmtssxaj4qpj2kl7sn0tndqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jdhl4f7" />
    <content type="html">
      Learn: Async mistakes interviewers ask about&lt;br/&gt;&lt;br/&gt;async void: exceptions can&amp;#39;t be caught by the caller and can crash the app. Use async Task (only event handlers are async void).&lt;br/&gt;.Result or .Wait() in a request: blocks a pool thread; under load, thread-pool starvation.&lt;br/&gt;Ignoring CancellationToken: when the user leaves, the work keeps running. Pass the request&amp;#39;s token down.&lt;br/&gt;Task.Run in a controller: moves work to another pool thread and gains nothing.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/&#34;&gt;https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-068
    </content>
    <updated>2026-10-26T16:08:09Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsrgt6edgzuvv3w3wwcxwexrqc5h2sn4yaq5hwdym94d6d86f2fjdszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j9s556m</id>
    
      <title type="html">Learn: Singleton One instance for the whole app, with a global ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsrgt6edgzuvv3w3wwcxwexrqc5h2sn4yaq5hwdym94d6d86f2fjdszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j9s556m" />
    <content type="html">
      Learn: Singleton&lt;br/&gt;&lt;br/&gt;One instance for the whole app, with a global access point.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;Console.WriteLine(ReferenceEquals(Config.Instance, Config.Instance));&lt;br/&gt;&lt;br/&gt;sealed class Config&lt;br/&gt;{&lt;br/&gt;    private static readonly Lazy&amp;lt;Config&amp;gt; instance = new(() =&amp;gt; new Config());&lt;br/&gt;    public static Config Instance =&amp;gt; instance.Value;&lt;br/&gt;    private Config() { }&lt;br/&gt;}&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints True: both reads return the same object. Lazy&amp;lt;T&amp;gt; creates it once, on first use, even with many threads; the object itself must still be thread-safe.&lt;br/&gt;In ASP.NET Core, prefer AddSingleton in DI: same effect, easier to test. Watch out: singletons are shared global state.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/system-design/singleton-design-pattern/&#34;&gt;https://www.geeksforgeeks.org/system-design/singleton-design-pattern/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-051
    </content>
    <updated>2026-10-26T15:37:57Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqswrfwefrm4yufwzsmhe68et4ay29w2v70xv2qdtg9z6vnr6srcluczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jew9plh</id>
    
      <title type="html">Case 1: the node has a right subtree. The next node is the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqswrfwefrm4yufwzsmhe68et4ay29w2v70xv2qdtg9z6vnr6srcluczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jew9plh" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqsg5nkqcn5zl97t38uesk9nf6mnveyxf80v4jtwnuv4k7yt8er23pgpz3mhxue69uhhyetvv9ujuerpd46hxtnfduay4ept&#39;&gt;nevent1q…4ept&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Case 1: the node has a right subtree. The next node is the leftmost node of that subtree.&lt;br/&gt;&lt;br/&gt;Case 2: no right subtree. Climb up while you are a right child. The first parent you reach from its left side is the next node.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var root = Tree(20, Tree(10, Tree(5), Tree(15)), Tree(30));&lt;br/&gt;var asked = new[] { root.Left!, root.Left!.Right!, root.Right! };&lt;br/&gt;Console.WriteLine(string.Join(&amp;#34; &amp;#34;, asked.Select(n =&amp;gt; Successor(n)?.Value.ToString() ?? &amp;#34;none&amp;#34;)));&lt;br/&gt;&lt;br/&gt;PNode? Successor(PNode n)&lt;br/&gt;{&lt;br/&gt;    if (n.Right != null) { n = n.Right; while (n.Left != null) n = n.Left; return n; }&lt;br/&gt;    while (n.Parent != null &amp;amp;&amp;amp; n == n.Parent.Right) n = n.Parent; // climb while n is a right child&lt;br/&gt;    return n.Parent;&lt;br/&gt;}&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 15 20 none. From 15 you climb to 10, then reach 20 from its left side.&lt;br/&gt;&lt;br/&gt;O(height) time, O(1) memory.&lt;br/&gt;&lt;br/&gt;#tg006 · TG-006-A1
    </content>
    <updated>2026-10-26T15:08:10Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsg5nkqcn5zl97t38uesk9nf6mnveyxf80v4jtwnuv4k7yt8er23pgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jjuzv2z</id>
    
      <title type="html">Question: In a binary search tree, each node also has a link to ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsg5nkqcn5zl97t38uesk9nf6mnveyxf80v4jtwnuv4k7yt8er23pgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jjuzv2z" />
    <content type="html">
      Question: In a binary search tree, each node also has a link to its parent. Given a node, find the next node in sorted (in-order) order.&lt;br/&gt;&lt;br/&gt;There are two cases. What are they?&lt;br/&gt;&lt;br/&gt;(CtCI 4.6)&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg006 · TG-006-Q1
    </content>
    <updated>2026-10-26T15:08:10Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqszcmtzz5euz608u5djt4zujzuuc406ehn9flfe036e0hq0xuj57vgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jlgg2rp</id>
    
      <title type="html">Learn: OAuth 2.0 vs OpenID Connect OAuth 2.0 is about access: it ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqszcmtzz5euz608u5djt4zujzuuc406ehn9flfe036e0hq0xuj57vgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jlgg2rp" />
    <content type="html">
      Learn: OAuth 2.0 vs OpenID Connect&lt;br/&gt;&lt;br/&gt;OAuth 2.0 is about access: it lets an app call an API for the user, with an access token.&lt;br/&gt;OpenID Connect (OIDC) adds login on top: an ID token that says who the user is.&lt;br/&gt;The usual flow for web and mobile apps is the authorization code flow with PKCE: the user logs in at the identity provider, the app gets a code, and swaps it for tokens.&lt;br/&gt;Short version: access token → for the API; ID token → for the app, to know who logged in.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc&#34;&gt;https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-093
    </content>
    <updated>2026-10-26T14:38:13Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs2lvr26mq2lhrwmhh5pncypn5wndm92n7xh8wqhk8pl3gfh4kwhdszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jevj7pj</id>
    
      <title type="html">Learn: Scoped services in a singleton or BackgroundService A ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs2lvr26mq2lhrwmhh5pncypn5wndm92n7xh8wqhk8pl3gfh4kwhdszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jevj7pj" />
    <content type="html">
      Learn: Scoped services in a singleton or BackgroundService&lt;br/&gt;&lt;br/&gt;A BackgroundService is a singleton, but a DbContext is scoped. Injecting the DbContext directly would keep one DbContext forever.&lt;br/&gt;Fix: inject IServiceScopeFactory. For each piece of work: create a scope, get the DbContext from it, and dispose the scope when done.&lt;br/&gt;In Development, ASP.NET Core checks this for you (scope validation) and throws at startup if a singleton depends on a scoped service.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection&#34;&gt;https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-096
    </content>
    <updated>2026-10-26T14:07:59Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsrj88d0nz7yg0ur6lgs9sat2f66e9qmmf30swhqdff2y2tr9kp0fszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38js8n45k</id>
    
      <title type="html">Learn: Factory A factory creates objects for you, so the caller ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsrj88d0nz7yg0ur6lgs9sat2f66e9qmmf30swhqdff2y2tr9kp0fszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38js8n45k" />
    <content type="html">
      Learn: Factory&lt;br/&gt;&lt;br/&gt;A factory creates objects for you, so the caller asks for &amp;#34;a pdf exporter&amp;#34; without naming the class.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;Console.WriteLine(Create(&amp;#34;pdf&amp;#34;).Export());&lt;br/&gt;static IExporter Create(string kind) =&amp;gt; kind switch&lt;br/&gt;{&lt;br/&gt;    &amp;#34;pdf&amp;#34; =&amp;gt; new PdfExporter(),&lt;br/&gt;    &amp;#34;csv&amp;#34; =&amp;gt; new CsvExporter(),&lt;br/&gt;    _ =&amp;gt; throw new ArgumentException(kind),&lt;br/&gt;};&lt;br/&gt;interface IExporter { string Export(); }&lt;br/&gt;class PdfExporter : IExporter { public string Export() =&amp;gt; &amp;#34;PDF file&amp;#34;; }&lt;br/&gt;class CsvExporter : IExporter { public string Export() =&amp;gt; &amp;#34;CSV file&amp;#34;; }&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints PDF file.&lt;br/&gt;Use it when: which class to create depends on input or configuration, or creating it is complicated.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/system-design/factory-method-for-designing-pattern/&#34;&gt;https://www.geeksforgeeks.org/system-design/factory-method-for-designing-pattern/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-052
    </content>
    <updated>2026-10-26T13:37:59Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsv2rd4gyuj5d44ldxajhlh2ka4et908e3elfc20ak04xwx82k5mzgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jvj2wyn</id>
    
      <title type="html">Question: Check whether a binary tree is a binary search tree. ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsv2rd4gyuj5d44ldxajhlh2ka4et908e3elfc20ak04xwx82k5mzgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jvj2wyn" />
    <content type="html">
      Question: Check whether a binary tree is a binary search tree. Assume all values are different.&lt;br/&gt;&lt;br/&gt;What must be true for every node, and how do you check it?&lt;br/&gt;&lt;br/&gt;(CtCI 4.5)&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg005 · TG-005-Q1
    </content>
    <updated>2026-10-26T13:07:54Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsgxc97wzmh06que9vt7we3fsjagl27w5gkkl0crvdxcxzp9vpu9qczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jhymgx0</id>
    
      <title type="html">Every node must be bigger than everything in its left subtree and ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsgxc97wzmh06que9vt7we3fsjagl27w5gkkl0crvdxcxzp9vpu9qczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jhymgx0" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqsv2rd4gyuj5d44ldxajhlh2ka4et908e3elfc20ak04xwx82k5mzgpz3mhxue69uhhyetvv9ujuerpd46hxtnfdux8nt5l&#39;&gt;nevent1q…nt5l&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Every node must be bigger than everything in its left subtree and smaller than everything in its right subtree. Pass down the allowed range (min, max). Going left, the node&amp;#39;s value becomes the new max. Going right, it becomes the new min.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var good = new Node(5, new Node(3, null, new Node(4)), new Node(8));&lt;br/&gt;var bad = new Node(5, new Node(3, null, new Node(6)), new Node(8));&lt;br/&gt;Console.WriteLine($&amp;#34;{IsBst(good, null, null)} {IsBst(bad, null, null)}&amp;#34;);&lt;br/&gt;&lt;br/&gt;bool IsBst(Node? n, int? min, int? max) =&amp;gt;&lt;br/&gt;    n == null ||&lt;br/&gt;    (min == null || n.Value &amp;gt; min) &amp;amp;&amp;amp; (max == null || n.Value &amp;lt; max)&lt;br/&gt;    &amp;amp;&amp;amp; IsBst(n.Left, min, n.Value) &amp;amp;&amp;amp; IsBst(n.Right, n.Value, max);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints True False. In the bad tree, 6 is right of 3 but on the left side of 5.&lt;br/&gt;&lt;br/&gt;O(n) time. null means &amp;#34;no limit yet&amp;#34;; using int.MinValue and int.MaxValue as limits would wrongly reject a tree that holds those values.&lt;br/&gt;&lt;br/&gt;#tg005 · TG-005-A1
    </content>
    <updated>2026-10-26T13:07:54Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsg5r6dhylhndj4qswcup70tmv3mjzpzqy0z2uuwxlzashl3zv5qqszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j97a0uu</id>
    
      <title type="html">Learn: Queues decouple services Put a message queue between a ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsg5r6dhylhndj4qswcup70tmv3mjzpzqy0z2uuwxlzashl3zv5qqszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j97a0uu" />
    <content type="html">
      Learn: Queues decouple services&lt;br/&gt;&lt;br/&gt;Put a message queue between a service that produces work and one that does it. The producer doesn&amp;#39;t wait, and a slow consumer just builds a backlog instead of failing.&lt;br/&gt;&lt;br/&gt;Most queues deliver &amp;#34;at least once&amp;#34;, so a message can arrive twice. Make consumers idempotent (same result when repeated): processing the same message twice must be safe.&lt;br/&gt;&lt;br/&gt;#tip · TIP-018
    </content>
    <updated>2026-10-26T12:37:55Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsv7uvr9rannhdluy4tz6wav08thnckjzeqmxuv6tr9n5kd0u9562gzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j2d730u</id>
    
      <title type="html">Learn: Authentication vs authorization Authentication: who are ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsv7uvr9rannhdluy4tz6wav08thnckjzeqmxuv6tr9n5kd0u9562gzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j2d730u" />
    <content type="html">
      Learn: Authentication vs authorization&lt;br/&gt;&lt;br/&gt;Authentication: who are you? (login, a cookie, a token)&lt;br/&gt;Authorization: what may you do? (roles, policies)&lt;br/&gt;On a protected endpoint: no valid login → 401; logged in but not allowed → 403. (Cookie login redirects web pages to a login page; since .NET 10, API endpoints get 401/403.)&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, &amp;#34;ann&amp;#34;), new Claim(ClaimTypes.Role, &amp;#34;Admin&amp;#34;) }, &amp;#34;demo&amp;#34;);&lt;br/&gt;var user = new ClaimsPrincipal(identity);&lt;br/&gt;Console.WriteLine($&amp;#34;{user.Identity!.IsAuthenticated} {user.IsInRole(&amp;#34;Admin&amp;#34;)} {user.IsInRole(&amp;#34;Billing&amp;#34;)}&amp;#34;);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints True True False. IsAuthenticated is true only because an authentication type (&amp;#34;demo&amp;#34;) was given. ASP.NET Core builds this ClaimsPrincipal for every request (HttpContext.User).&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/aspnet/core/security/authentication/&#34;&gt;https://learn.microsoft.com/en-us/aspnet/core/security/authentication/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-083
    </content>
    <updated>2026-10-26T12:08:13Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsymgteej9csm2dsgwq5p3cxzjle0k3za9ayxz5h46lrxx5guqxh0szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jjtc3xa</id>
    
      <title type="html">Learn: Tree traversals The four ways to visit a tree, when each ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsymgteej9csm2dsgwq5p3cxzjle0k3za9ayxz5h46lrxx5guqxh0szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jjtc3xa" />
    <content type="html">
      In reply to &lt;a href=&#39;/naddr1qqt4gj2s95crvdzqxgcryd3dxycz6v3k2scnxvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsyg8x3gy9d6gdnxtmraepayzjfxykgyka2upen2v8kt506hnlel3z0ypsgqqqw4rsv4ah98&#39;&gt;naddr1qq…ah98&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Learn: Tree traversals&lt;br/&gt;&lt;br/&gt;The four ways to visit a tree, when each one is useful, and how much memory they need.&lt;br/&gt;&lt;br/&gt;Read the full article:&lt;blockquote class=&#34;border-l-05rem border-l-strongpink border-solid&#34;&gt;&lt;div class=&#34;-ml-4 bg-gradient-to-r from-gray-100 dark:from-zinc-800 to-transparent mr-0 mt-0 mb-4 pl-4 pr-2 py-2&#34;&gt;quoting  &lt;span itemprop=&#34;mentions&#34; itemscope itemtype=&#34;https://schema.org/Article&#34;&gt;&lt;a itemprop=&#34;url&#34; href=&#34;/naddr1qqt4gj2s95crvdzqxgcryd3dxycz6v3k2scnxvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszrthwden5te0dehhxtnvdakqz9nhwden5te0wfjkccte9ec8y6tdv9kzumn9wspzpe52pptwjrvej7clwg0fq5jf39jp9h2hqwv6npajar74ul70ugneqvzqqqr4guvgxjh2&#34; class=&#34;bg-lavender dark:prose:text-neutral-50 dark:text-neutral-50 dark:bg-garnet px-1&#34;&gt;naddr1qq…xjh2&lt;/a&gt;&lt;/span&gt;&lt;br/&gt; &lt;/div&gt; 
&lt;h2 id=&#34;tree-traversals-2&#34;&gt;Tree traversals&lt;/h2&gt;

&lt;p&gt;Most tree questions start with visiting every node in some order.&lt;/p&gt;

&lt;h3 id=&#34;depth-first-recursion-2&#34;&gt;Depth-first (recursion)&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Pre-order:&lt;/strong&gt; node, then left, then right. Use it to copy a tree or print it top-down.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;In-order:&lt;/strong&gt; left, then node, then right. On a &lt;strong&gt;binary search tree this gives the values in sorted order&lt;/strong&gt;, a favorite interview fact.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Post-order:&lt;/strong&gt; left, then right, then node. Use it to delete a tree or compute sizes (children first).&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;var root = new Tree(2, new Tree(1, null, null), new Tree(3, null, null));
var order = new List&amp;lt;int&amp;gt;();
InOrder(root, order);
Console.WriteLine(string.Join(&amp;#34; &amp;#34;, order));

static void InOrder(Tree? t, List&amp;lt;int&amp;gt; order)
{
    if (t == null) return;
    InOrder(t.Left, order); order.Add(t.Value); InOrder(t.Right, order);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It prints &lt;code&gt;1 2 3&lt;/code&gt;: in-order on a BST is sorted.&lt;/p&gt;

&lt;h3 id=&#34;breadth-first-level-by-level-2&#34;&gt;Breadth-first (level by level)&lt;/h3&gt;

&lt;p&gt;Use a &lt;strong&gt;queue&lt;/strong&gt;: take a node out, add its children at the back. Use it for &amp;#34;shortest path in steps&amp;#34;, &amp;#34;print level by level&amp;#34;, or &amp;#34;nodes closest to the root&amp;#34;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var root = new Tree(1, new Tree(2, new Tree(4, null, null), null), new Tree(3, null, null));
var queue = new Queue&amp;lt;Tree&amp;gt;(new[] { root });
var visited = new List&amp;lt;int&amp;gt;();
while (queue.Count &amp;gt; 0)
{
    var t = queue.Dequeue(); visited.Add(t.Value);
    if (t.Left != null) queue.Enqueue(t.Left);
    if (t.Right != null) queue.Enqueue(t.Right);
}
Console.WriteLine(string.Join(&amp;#34; &amp;#34;, visited));
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It prints &lt;code&gt;1 2 3 4&lt;/code&gt;: the root, then its children, then the next level.&lt;/p&gt;

&lt;h3 id=&#34;cost-5&#34;&gt;Cost&lt;/h3&gt;

&lt;p&gt;Every traversal visits each node once: &lt;strong&gt;O(n) time&lt;/strong&gt;. Memory: recursion uses O(h), where h is the tree&amp;#39;s height (O(log n) if balanced, O(n) if it is a chain); breadth-first keeps up to one full level in the queue.&lt;/p&gt;

&lt;p&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/tree-data-structure/&#34;&gt;https://www.geeksforgeeks.org/dsa/tree-data-structure/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;#tip · TIP-064&lt;/p&gt;
 &lt;/blockquote&gt;&lt;br/&gt;#tip · TIP-064
    </content>
    <updated>2026-10-26T11:38:07Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqswqe3yjnc8qcr8emkv0m9k8yvqwupjq6dhzdxfk6ng8j5fm0xk06czyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jeqqugs</id>
    
      <title type="html">Yes. Pass the depth down. When a call reaches a depth for the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqswqe3yjnc8qcr8emkv0m9k8yvqwupjq6dhzdxfk6ng8j5fm0xk06czyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jeqqugs" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqspvj6y948xj9nz9d7923rhk5cqh2kmpkcyg3j0n6kmejtumeezmegpz3mhxue69uhhyetvv9ujuerpd46hxtnfdu5aqycl&#39;&gt;nevent1q…qycl&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Yes. Pass the depth down. When a call reaches a depth for the first time, add a new list. Then add the node&amp;#39;s value to the list for its depth.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var levels = new List&amp;lt;List&amp;lt;int&amp;gt;&amp;gt;();&lt;br/&gt;Visit(new Node(1, new Node(2, new Node(4)), new Node(3, null, new Node(5))), 0);&lt;br/&gt;Console.WriteLine(string.Join(&amp;#34; | &amp;#34;, levels.Select(l =&amp;gt; string.Join(&amp;#34; &amp;#34;, l))));&lt;br/&gt;void Visit(Node? n, int depth)&lt;br/&gt;{&lt;br/&gt;    if (n == null) return;&lt;br/&gt;    if (depth == levels.Count) levels.Add([]); // first node seen at this depth&lt;br/&gt;    levels[depth].Add(n.Value);&lt;br/&gt;    Visit(n.Left, depth &#43; 1); Visit(n.Right, depth &#43; 1);&lt;br/&gt;}&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 1 | 2 3 | 4 5, the same as before. Left is visited before right, so each list is in left-to-right order.&lt;br/&gt;&lt;br/&gt;#tg003 · TG-003-A2
    </content>
    <updated>2026-10-26T11:07:57Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqspvj6y948xj9nz9d7923rhk5cqh2kmpkcyg3j0n6kmejtumeezmegzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38je0jvnn</id>
    
      <title type="html">Question: Can you get the same lists with a depth-first walk ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqspvj6y948xj9nz9d7923rhk5cqh2kmpkcyg3j0n6kmejtumeezmegzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38je0jvnn" />
    <content type="html">
      Question: Can you get the same lists with a depth-first walk (recursion) instead of going level by level?&lt;br/&gt;&lt;br/&gt;What extra information does each call need?&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg003 · TG-003-Q2
    </content>
    <updated>2026-10-26T11:07:57Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsr65f2reaqm2zx7cy4h4lna0gc8x0g0klhte7q6fyhl978m98p76szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j78urlp</id>
    
      <title type="html">Learn: Tree What: nodes in a hierarchy. One root at the top, each ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsr65f2reaqm2zx7cy4h4lna0gc8x0g0klhte7q6fyhl978m98p76szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j78urlp" />
    <content type="html">
      Learn: Tree&lt;br/&gt;&lt;br/&gt;What: nodes in a hierarchy. One root at the top, each node has children, nodes with no children are leaves.&lt;br/&gt;Use it when: data is nested: folders, HTML, company org charts, menus, and database indexes.&lt;br/&gt;Most tree problems are recursion: solve for the children, then combine.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var root = new Tree(1, new Tree(2, null, null), new Tree(3, new Tree(4, null, null), null));&lt;br/&gt;Console.WriteLine(Count(root));&lt;br/&gt;&lt;br/&gt;static int Count(Tree? t) =&amp;gt; t == null ? 0 : 1 &#43; Count(t.Left) &#43; Count(t.Right);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 4: the number of nodes.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/tree-data-structure/&#34;&gt;https://www.geeksforgeeks.org/dsa/tree-data-structure/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-030
    </content>
    <updated>2026-10-26T10:37:49Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs2axaq0fy59z37d7s2a2ft8vmvkecuqwc2wdafd3k0ccw6lgyqjtszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j6apzk4</id>
    
      <title type="html">Learn: Two pointers Two indexes walk the data instead of nested ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs2axaq0fy59z37d7s2a2ft8vmvkecuqwc2wdafd3k0ccw6lgyqjtszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j6apzk4" />
    <content type="html">
      Learn: Two pointers&lt;br/&gt;&lt;br/&gt;Two indexes walk the data instead of nested loops. Two common shapes:&lt;br/&gt;From both ends of a sorted array, to find a pair with a given sum (here 11):&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int[] a = { 1, 3, 4, 7, 9 };&lt;br/&gt;int left = 0, right = a.Length - 1, target = 11;&lt;br/&gt;while (left &amp;lt; right &amp;amp;&amp;amp; a[left] &#43; a[right] != target)&lt;br/&gt;    if (a[left] &#43; a[right] &amp;lt; target) left&#43;&#43;; else right--;&lt;br/&gt;Console.WriteLine(left &amp;lt; right ? $&amp;#34;{a[left]} &#43; {a[right]}&amp;#34; : &amp;#34;no pair&amp;#34;);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 4 &#43; 7 (or &amp;#34;no pair&amp;#34;). Too small: move left; too big: move right.&lt;br/&gt;Same direction, to remove duplicates from a sorted array in place:&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int[] a = { 1, 1, 2, 3, 3 };&lt;br/&gt;int w = Math.Min(1, a.Length); // 0 for an empty array&lt;br/&gt;for (int r = 1; r &amp;lt; a.Length; r&#43;&#43;)&lt;br/&gt;    if (a[r] != a[w - 1]) a[w&#43;&#43;] = a[r];&lt;br/&gt;Console.WriteLine(string.Join(&amp;#34; &amp;#34;, a[..w]));&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 1 2 3. Both are O(n) time, O(1) memory.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/two-pointers-technique/&#34;&gt;https://www.geeksforgeeks.org/dsa/two-pointers-technique/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-038
    </content>
    <updated>2026-10-26T10:07:56Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs08sxzaax0v0rg03k826wuts0a0tj54vtedqclj252ggwg36afq4szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jd9t636</id>
    
      <title type="html">Learn: Array What: items stored side by side in memory, each at ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs08sxzaax0v0rg03k826wuts0a0tj54vtedqclj252ggwg36afq4szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jd9t636" />
    <content type="html">
      Learn: Array&lt;br/&gt;&lt;br/&gt;What: items stored side by side in memory, each at an index.&lt;br/&gt;Cost: read or write a[i] in O(1); insert or delete in the middle O(n), because items must shift.&lt;br/&gt;Use it when: you know the size, you read by position a lot, or you loop over everything.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int[] a = { 10, 20, 30 };&lt;br/&gt;Console.WriteLine(a[1]);&lt;br/&gt;var list = new List&amp;lt;int&amp;gt;(a) { 40 };&lt;br/&gt;Console.WriteLine(list.Count);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 20, then 4. In C#, int[] has a fixed size; List&amp;lt;T&amp;gt; is an array that grows.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/array-data-structure-guide/&#34;&gt;https://www.geeksforgeeks.org/dsa/array-data-structure-guide/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-023
    </content>
    <updated>2026-10-26T09:38:01Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs0uylwq6zp282969gnh0rmrlqvlr63m24e4dvrcg47497zqyvvgtszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jrnnjt0</id>
    
      <title type="html">Question: A teammate wants to store the arrival time ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs0uylwq6zp282969gnh0rmrlqvlr63m24e4dvrcg47497zqyvvgtszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jrnnjt0" />
    <content type="html">
      Question: A teammate wants to store the arrival time (DateTime.UtcNow) instead of a counter.&lt;br/&gt;&lt;br/&gt;What can go wrong?&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#sq006 · SQ-006-Q3
    </content>
    <updated>2026-10-26T09:07:58Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqszdpvyx9lwerpjm8a0tpv26g2unnxuxxecnp668082pj896d2zepgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j6ldq0c</id>
    
      <title type="html">Two devices that arrive very close together can get the same ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqszdpvyx9lwerpjm8a0tpv26g2unnxuxxecnp668082pj896d2zepgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j6ldq0c" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqs0uylwq6zp282969gnh0rmrlqvlr63m24e4dvrcg47497zqyvvgtspz3mhxue69uhhyetvv9ujuerpd46hxtnfdur5ak8q&#39;&gt;nevent1q…ak8q&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Two devices that arrive very close together can get the same time, because the clock has a limited resolution. Then TakeAny can&amp;#39;t tell which came first.&lt;br/&gt;&lt;br/&gt;On a server the clock can also be adjusted, so a later arrival could even get an earlier time.&lt;br/&gt;&lt;br/&gt;A counter has neither problem: every arrival gets a new, bigger number. You can still store the time as well, for display.&lt;br/&gt;&lt;br/&gt;#sq006 · SQ-006-A3
    </content>
    <updated>2026-10-26T09:07:58Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsfrqz8d6eqx5mx7hc55cy3fhrw04lddsze3qmh6yvpranjuhgnnzszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcpq9tf</id>
    
      <title type="html">Learn: Making microservices resilient Timeouts, retries with ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsfrqz8d6eqx5mx7hc55cy3fhrw04lddsze3qmh6yvpranjuhgnnzszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcpq9tf" />
    <content type="html">
      In reply to &lt;a href=&#39;/naddr1qqt4gj2s95crjw2qxgcryd3dxycz6v3k2scnqvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsyg8x3gy9d6gdnxtmraepayzjfxykgyka2upen2v8kt506hnlel3z0ypsgqqqw4rsen757x&#39;&gt;naddr1qq…757x&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Learn: Making microservices resilient&lt;br/&gt;&lt;br/&gt;Timeouts, retries with backoff, circuit breakers, idempotency and the outbox: how services survive each other&amp;#39;s failures.&lt;br/&gt;&lt;br/&gt;Read the full article:&lt;blockquote class=&#34;border-l-05rem border-l-strongpink border-solid&#34;&gt;&lt;div class=&#34;-ml-4 bg-gradient-to-r from-gray-100 dark:from-zinc-800 to-transparent mr-0 mt-0 mb-4 pl-4 pr-2 py-2&#34;&gt;quoting  &lt;span itemprop=&#34;mentions&#34; itemscope itemtype=&#34;https://schema.org/Article&#34;&gt;&lt;a itemprop=&#34;url&#34; href=&#34;/naddr1qqt4gj2s95crjw2qxgcryd3dxycz6v3k2scnqvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszrthwden5te0dehhxtnvdakqz9nhwden5te0wfjkccte9ec8y6tdv9kzumn9wspzpe52pptwjrvej7clwg0fq5jf39jp9h2hqwv6npajar74ul70ugneqvzqqqr4gujdl0j8&#34; class=&#34;bg-lavender dark:prose:text-neutral-50 dark:text-neutral-50 dark:bg-garnet px-1&#34;&gt;naddr1qq…l0j8&lt;/a&gt;&lt;/span&gt;&lt;br/&gt; &lt;/div&gt; 
&lt;h2 id=&#34;making-microservices-resilient-5&#34;&gt;Making microservices resilient&lt;/h2&gt;

&lt;p&gt;In a microservice system, some call always fails somewhere: a service restarts, the network hiccups, a database is slow. Design for these partial failures instead of hoping they don&amp;#39;t happen.&lt;/p&gt;

&lt;h3 id=&#34;the-toolbox-5&#34;&gt;The toolbox&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Timeout:&lt;/strong&gt; never wait forever for another service. A slow dependency must not hold your threads and requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Retry with backoff:&lt;/strong&gt; retry short, temporary failures, waiting longer each time (for example 200 ms, 400 ms, 800 ms) and adding a little randomness (jitter), so many clients don&amp;#39;t retry at the same moment.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Circuit breaker:&lt;/strong&gt; after many failures, stop calling the broken service for a while and fail fast. Then try again carefully.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bulkhead:&lt;/strong&gt; limit how many calls can go to one dependency, so one slow service can&amp;#39;t use up everything.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fallback:&lt;/strong&gt; return a cached or default answer when a call fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In .NET, &lt;code&gt;Microsoft.Extensions.Http.Resilience&lt;/code&gt; (built on Polly) adds these to &lt;code&gt;HttpClient&lt;/code&gt; in a few lines.&lt;/p&gt;

&lt;h3 id=&#34;a-retry-by-hand-5&#34;&gt;A retry, by hand&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;int calls = 0;
Console.WriteLine(await RetryAsync(() =&amp;gt; &#43;&#43;calls &amp;lt; 3 ? throw new HttpRequestException(&amp;#34;busy&amp;#34;) : Task.FromResult(&amp;#34;ok&amp;#34;)));
async Task&amp;lt;string&amp;gt; RetryAsync(Func&amp;lt;Task&amp;lt;string&amp;gt;&amp;gt; action)
{
    for (int attempt = 1; ; attempt&#43;&#43;)
    {
        try { return await action(); }
        catch (HttpRequestException) when (attempt &amp;lt; 5) { await Task.Delay(10 * (1 &amp;lt;&amp;lt; attempt)); } // wait longer each time
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It prints &lt;code&gt;ok&lt;/code&gt;: the first two calls fail, the third succeeds, with a growing wait between tries.&lt;/p&gt;

&lt;h3 id=&#34;data-across-services-5&#34;&gt;Data across services&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Idempotency:&lt;/strong&gt; retries mean the same request can arrive twice. Make handlers safe to repeat, for example with a request ID.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Outbox:&lt;/strong&gt; save the business change and the message to send in the same database transaction; a background job publishes the messages. No lost events, but a message may be published twice, so consumers must be idempotent.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Saga:&lt;/strong&gt; a business process across services is a series of local steps, each with a compensating step to undo it if a later step fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;at-the-edge-5&#34;&gt;At the edge&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;API gateway&lt;/strong&gt; gives clients one entry point and handles routing, authentication and rate limiting for the services behind it.&lt;/p&gt;

&lt;p&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/&#34;&gt;https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;#tip · TIP-099&lt;/p&gt;
 &lt;/blockquote&gt;&lt;br/&gt;#tip · TIP-099
    </content>
    <updated>2026-10-26T08:38:03Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsfgq2ec8tr8je6qwssr2fngzns0yd06705zqqrumm5qlk2yw6n8nszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jq86h3p</id>
    
      <title type="html">Learn: Designing a URL shortener A step-by-step way to answer the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsfgq2ec8tr8je6qwssr2fngzns0yd06705zqqrumm5qlk2yw6n8nszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jq86h3p" />
    <content type="html">
      In reply to &lt;a href=&#39;/naddr1qqt4gj2s95cryvjqxgcryd3dxycz6v3k2scnqvpsqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsyg8x3gy9d6gdnxtmraepayzjfxykgyka2upen2v8kt506hnlel3z0ypsgqqqw4rscdq5e6&#39;&gt;naddr1qq…q5e6&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Learn: Designing a URL shortener&lt;br/&gt;&lt;br/&gt;A step-by-step way to answer the classic system design question: requirements, API, short codes, storage, caching and scaling.&lt;br/&gt;&lt;br/&gt;Read the full article:&lt;blockquote class=&#34;border-l-05rem border-l-strongpink border-solid&#34;&gt;&lt;div class=&#34;-ml-4 bg-gradient-to-r from-gray-100 dark:from-zinc-800 to-transparent mr-0 mt-0 mb-4 pl-4 pr-2 py-2&#34;&gt;quoting  &lt;span itemprop=&#34;mentions&#34; itemscope itemtype=&#34;https://schema.org/Article&#34;&gt;&lt;a itemprop=&#34;url&#34; href=&#34;/naddr1qqt4gj2s95cryvjqxgcryd3dxycz6v3k2scnqvpsqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszrthwden5te0dehhxtnvdakqz9nhwden5te0wfjkccte9ec8y6tdv9kzumn9wspzpe52pptwjrvej7clwg0fq5jf39jp9h2hqwv6npajar74ul70ugneqvzqqqr4gucfw9gx&#34; class=&#34;bg-lavender dark:prose:text-neutral-50 dark:text-neutral-50 dark:bg-garnet px-1&#34;&gt;naddr1qq…w9gx&lt;/a&gt;&lt;/span&gt;&lt;br/&gt; &lt;/div&gt; 
&lt;h2 id=&#34;designing-a-url-shortener-2&#34;&gt;Designing a URL shortener&lt;/h2&gt;

&lt;p&gt;This is one of the most common system design interview questions. Here is a simple way to walk through it.&lt;/p&gt;

&lt;h3 id=&#34;1-requirements-first-2&#34;&gt;1. Requirements first&lt;/h3&gt;

&lt;p&gt;Ask before you draw anything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Functional:&lt;/strong&gt; make a short link for a long URL; redirect a short link to the long URL.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Non-functional:&lt;/strong&gt; redirects must be fast; links must not collide; the service must stay up.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scale:&lt;/strong&gt; how many new links a day, and how many redirects? Redirects are usually far more common than new links, so this is a &lt;em&gt;read-heavy&lt;/em&gt; system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;2-the-api-2&#34;&gt;2. The API&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;POST /links&lt;/code&gt; with the long URL returns the short code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET /{code}&lt;/code&gt; answers with a redirect (HTTP 301 or 302) to the long URL.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;3-making-the-short-code-2&#34;&gt;3. Making the short code&lt;/h3&gt;

&lt;p&gt;Give every link a unique number (an ID from the database or an ID service), then write that number in base 62 (0-9, a-z, A-Z). Seven base-62 characters give about 3.5 trillion codes.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;const string chars = &amp;#34;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&amp;#34;;
long id = 125;
var code = &amp;#34;&amp;#34;;
do { code = chars[(int)(id % 62)] &#43; code; id /= 62; } while (id &amp;gt; 0);
Console.WriteLine(code);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It prints &lt;code&gt;21&lt;/code&gt;, because 125 = 2 × 62 &#43; 1. Using unique IDs means two links can never get the same code.&lt;/p&gt;

&lt;h3 id=&#34;4-storage-2&#34;&gt;4. Storage&lt;/h3&gt;

&lt;p&gt;A simple table: code → long URL, plus creation time. Reads by code must be fast, so the code is the key. A key-value store fits well.&lt;/p&gt;

&lt;h3 id=&#34;5-making-redirects-fast-2&#34;&gt;5. Making redirects fast&lt;/h3&gt;

&lt;p&gt;Put a cache in front of the database: most traffic goes to a small number of popular links. Links rarely change, so cached copies stay correct for a long time.&lt;/p&gt;

&lt;h3 id=&#34;6-growing-2&#34;&gt;6. Growing&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;More app servers behind a &lt;strong&gt;load balancer&lt;/strong&gt;; the servers keep no state.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Shard&lt;/strong&gt; the storage by code when one database is not enough.&lt;/li&gt;
&lt;li&gt;Replicate data so a failed server doesn&amp;#39;t lose links.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;what-interviewers-look-for-2&#34;&gt;What interviewers look for&lt;/h3&gt;

&lt;p&gt;Clear requirements, a simple design first, then the bottlenecks: the read load, the ID generation, and what happens when a part fails.&lt;/p&gt;

&lt;p&gt;#tip · TIP-022&lt;/p&gt;
 &lt;/blockquote&gt;&lt;br/&gt;#tip · TIP-022
    </content>
    <updated>2026-10-26T08:04:58Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs2k0axu8y2jl6uh8tyq2nq70l2luc4g80t4u28smsht349qgzgmlgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jg2czn0</id>
    
      <title type="html">Learn: The classic async deadlock In UI apps and classic ASP.NET ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs2k0axu8y2jl6uh8tyq2nq70l2luc4g80t4u28smsht349qgzgmlgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jg2czn0" />
    <content type="html">
      Learn: The classic async deadlock&lt;br/&gt;&lt;br/&gt;In UI apps and classic ASP.NET there is a SynchronizationContext: code after an await must continue on the original thread.&lt;br/&gt;If that thread calls task.Result, it blocks and waits for the task. The task finishes its await and needs that same thread to continue. Each waits for the other: deadlock.&lt;br/&gt;Fixes: await instead of .Result. In library code, add .ConfigureAwait(false) so it doesn&amp;#39;t need the original thread.&lt;br/&gt;ASP.NET Core has no SynchronizationContext, so it doesn&amp;#39;t deadlock this way.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/&#34;&gt;https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-089
    </content>
    <updated>2026-10-26T07:37:56Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsvkgmd6qw79hh3qrqthln0k4646qze2c482tqq7d4ln8t47gyrfugzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jt493g8</id>
    
      <title type="html">Interviewer&amp;#39;s follow-up: &amp;#34;Now you may use any data ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsvkgmd6qw79hh3qrqthln0k4646qze2c482tqq7d4ln8t47gyrfugzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jt493g8" />
    <content type="html">
      Interviewer&amp;#39;s follow-up: &amp;#34;Now you may use any data structure you like.&amp;#34;&lt;br/&gt;&lt;br/&gt;How do you sort the stack faster, and what does it cost?&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#sq005 · SQ-005-Q3
    </content>
    <updated>2026-10-26T07:07:48Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsxmffueyllgnvrykmsq9dua4tdkwhjr8gp829lvmf444ga3jcqv7gzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jnuxxr3</id>
    
      <title type="html">Copy the values to an array, sort it, and push them back largest ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsxmffueyllgnvrykmsq9dua4tdkwhjr8gp829lvmf444ga3jcqv7gzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jnuxxr3" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqsvkgmd6qw79hh3qrqthln0k4646qze2c482tqq7d4ln8t47gyrfugpz3mhxue69uhhyetvv9ujuerpd46hxtnfdunct5e6&#39;&gt;nevent1q…t5e6&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Copy the values to an array, sort it, and push them back largest first, so the smallest ends on top.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var s = new Stack&amp;lt;int&amp;gt;(new[] { 5, 1, 4, 2 });&lt;br/&gt;int[] a = s.ToArray();&lt;br/&gt;Array.Sort(a);&lt;br/&gt;s.Clear();&lt;br/&gt;for (int i = a.Length - 1; i &amp;gt;= 0; i--) s.Push(a[i]); // largest first, so smallest ends on top&lt;br/&gt;Console.WriteLine(string.Join(&amp;#34; &amp;#34;, s));&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 1 2 4 5.&lt;br/&gt;&lt;br/&gt;The docs say Array.Sort &amp;#34;is an O(n log n) operation&amp;#34;. Copying in and out is O(n), so the total is O(n log n) time and O(n) extra memory.&lt;br/&gt;&lt;br/&gt;#sq005 · SQ-005-A3
    </content>
    <updated>2026-10-26T07:07:48Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqszs522dh5v4957r2wfdzja4ppc4k94dgqywvsecxhlrpphnh47jxczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jt8td3c</id>
    
      <title type="html">Learn: From recursion to memoization Plain recursive Fibonacci ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqszs522dh5v4957r2wfdzja4ppc4k94dgqywvsecxhlrpphnh47jxczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jt8td3c" />
    <content type="html">
      Learn: From recursion to memoization&lt;br/&gt;&lt;br/&gt;Plain recursive Fibonacci recomputes the same values again and again: O(2ⁿ). Remember each answer the first time, and every value is computed once: O(n).&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var memo = new Dictionary&amp;lt;int, long&amp;gt;();&lt;br/&gt;Console.WriteLine(Fib(60));&lt;br/&gt;long Fib(int n)&lt;br/&gt;{&lt;br/&gt;    if (n &amp;lt; 2) return n;&lt;br/&gt;    if (memo.TryGetValue(n, out long known)) return known;&lt;br/&gt;    return memo[n] = Fib(n - 1) &#43; Fib(n - 2);&lt;br/&gt;}&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 1548008755920 at once. Plain recursion would take hours for n = 60.&lt;br/&gt;This is the first step of dynamic programming: overlapping subproblems &#43; a cache.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/recursion-algorithms/&#34;&gt;https://www.geeksforgeeks.org/dsa/recursion-algorithms/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-097
    </content>
    <updated>2026-10-26T06:37:56Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsgnd4t6anythgmn80uymjjvavj2mpzs3y7gcxu39zynlafpgdx5hszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jvz6y3u</id>
    
      <title type="html">Learn: Decorator Wrap an object in another object of the same ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsgnd4t6anythgmn80uymjjvavj2mpzs3y7gcxu39zynlafpgdx5hszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jvz6y3u" />
    <content type="html">
      Learn: Decorator&lt;br/&gt;&lt;br/&gt;Wrap an object in another object of the same type that adds behavior before or after it.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;INotifier n = new Loud(new Plain());&lt;br/&gt;Console.WriteLine(n.Send(&amp;#34;hi&amp;#34;));&lt;br/&gt;&lt;br/&gt;interface INotifier { string Send(string m); }&lt;br/&gt;class Plain : INotifier { public string Send(string m) =&amp;gt; m; }&lt;br/&gt;class Loud(INotifier inner) : INotifier { public string Send(string m) =&amp;gt; inner.Send(m).ToUpper() &#43; &amp;#34;!&amp;#34;; }&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints HI!.&lt;br/&gt;You already use it: GZipStream wraps another Stream and adds compression. (ASP.NET Core middleware is a similar wrapping idea, usually called a pipeline.) Use it to add logging, caching or retries without changing the original class.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/system-design/decorator-pattern/&#34;&gt;https://www.geeksforgeeks.org/system-design/decorator-pattern/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-055
    </content>
    <updated>2026-10-26T06:07:57Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsygyf9d6cgclqemj9uqymj9hd94qejs9j7wyt3lmy3jjc74gyfcjqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jssa2vy</id>
    
      <title type="html">Learn: volatile Without it, the compiler or CPU may keep reusing ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsygyf9d6cgclqemj9uqymj9hd94qejs9j7wyt3lmy3jjc74gyfcjqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jssa2vy" />
    <content type="html">
      Learn: volatile&lt;br/&gt;&lt;br/&gt;Without it, the compiler or CPU may keep reusing an old read of a field, so a loop can miss a &amp;#34;stop&amp;#34; flag that another thread set. volatile makes every read and write go to the field itself (the compiler can&amp;#39;t keep an old copy), and limits how those reads and writes are reordered.&lt;br/&gt;What it doesn&amp;#39;t do: make count&#43;&#43; safe (use Interlocked or lock), or guarantee the very latest value on every processor.&lt;br/&gt;For stopping work, prefer a CancellationToken.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile&#34;&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-090
    </content>
    <updated>2026-10-25T19:37:53Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqst75pc5jpzm4emc6z6h8udhcvuxnjkryka64nqqtv3gm6qk352jqszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j9t2e02</id>
    
      <title type="html">Learn: Amortized O(1) &amp;#34;Amortized&amp;#34; means the average cost ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqst75pc5jpzm4emc6z6h8udhcvuxnjkryka64nqqtv3gm6qk352jqszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j9t2e02" />
    <content type="html">
      Learn: Amortized O(1)&lt;br/&gt;&lt;br/&gt;&amp;#34;Amortized&amp;#34; means the average cost per operation over a long run, even if a few operations are slow.&lt;br/&gt;&lt;br/&gt;List&amp;lt;T&amp;gt;.Add is the classic case. The docs say: &amp;#34;If Count is less than Capacity, this method is an O(1) operation.&amp;#34; When the list is full, it &amp;#34;becomes an O(n) operation&amp;#34;, because it copies everything into a bigger array.&lt;br/&gt;&lt;br/&gt;The capacity doubles each time (in a test run it went 4, 8, 16, 32), so copies get rarer as the list grows. For n adds the copies sum to less than 2n, so Add is amortized O(1).&lt;br/&gt;&lt;br/&gt;The queue made of two stacks works the same way: each value is moved at most once.&lt;br/&gt;&lt;br/&gt;Source: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.add&#34;&gt;https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.add&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#sq004 · SQ-004-N
    </content>
    <updated>2026-10-25T19:07:58Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs28nvmaqyjczcyuzq8npufw8fxsmzaus37e3ww39z4wgywdvfcw6qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j8vegap</id>
    
      <title type="html">Learn: async and await await pauses this method until a task ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs28nvmaqyjczcyuzq8npufw8fxsmzaus37e3ww39z4wgywdvfcw6qzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j8vegap" />
    <content type="html">
      Learn: async and await&lt;br/&gt;&lt;br/&gt;await pauses this method until a task finishes, and frees the thread while it waits. The task itself was already started.&lt;br/&gt;Start independent work first, then await it together, and the waits overlap:&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var watch = System.Diagnostics.Stopwatch.StartNew();&lt;br/&gt;Task first = Task.Delay(200), second = Task.Delay(200);&lt;br/&gt;await Task.WhenAll(first, second);&lt;br/&gt;Console.WriteLine(watch.ElapsedMilliseconds &amp;lt; 350 ? &amp;#34;ran together&amp;#34; : &amp;#34;ran one after another&amp;#34;);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints ran together: two 200 ms waits took about 200 ms, not 400.&lt;br/&gt;In ASP.NET Core, async endpoints let one server handle many more requests.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/&#34;&gt;https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-046
    </content>
    <updated>2026-10-25T18:37:57Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsza97zgzqa9mscjqx9nf6zsm90a5cv7kz3hgze50j7h6ek8jp5a9gzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcy85fp</id>
    
      <title type="html">Learn: Costs worth knowing by heart Read array[i]: O(1) Search an ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsza97zgzqa9mscjqx9nf6zsm90a5cv7kz3hgze50j7h6ek8jp5a9gzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcy85fp" />
    <content type="html">
      Learn: Costs worth knowing by heart&lt;br/&gt;&lt;br/&gt;Read array[i]: O(1)&lt;br/&gt;Search an unsorted array: O(n)&lt;br/&gt;Sort: O(n log n)&lt;br/&gt;HashSet or Dictionary lookup: O(1) on average&lt;br/&gt;Search a sorted array with binary search: O(log n)&lt;br/&gt;&lt;br/&gt;When you state a solution in an interview, say its Big-O with it.&lt;br/&gt;&lt;br/&gt;#tip · TIP-005
    </content>
    <updated>2026-10-25T18:07:53Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs0dyaqa4h3hu24c8hryr2w2gqm9zpyff4sg7g0w8pr7z2xh0824tgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jrfg7p4</id>
    
      <title type="html">Learn: Mutex A Mutex is a lock that can also work across ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs0dyaqa4h3hu24c8hryr2w2gqm9zpyff4sg7g0w8pr7z2xh0824tgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jrfg7p4" />
    <content type="html">
      Learn: Mutex&lt;br/&gt;&lt;br/&gt;A Mutex is a lock that can also work across processes when you give it a name. Example: allow only one copy of your app to run.&lt;br/&gt;It has thread affinity (it belongs to one thread): only the thread that took it can release it.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var m = new Mutex();&lt;br/&gt;m.WaitOne();&lt;br/&gt;var t = new Thread(() =&amp;gt;&lt;br/&gt;{&lt;br/&gt;    try { m.ReleaseMutex(); } catch (ApplicationException) { Console.WriteLine(&amp;#34;only the owner can release&amp;#34;); }&lt;br/&gt;});&lt;br/&gt;t.Start(); t.Join();&lt;br/&gt;m.ReleaseMutex();&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints only the owner can release. Don&amp;#39;t hold a Mutex across await: the code after it may run on another thread, which can&amp;#39;t release it. Without a name, use lock instead: it is much faster.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/standard/threading/overview-of-synchronization-primitives&#34;&gt;https://learn.microsoft.com/en-us/dotnet/standard/threading/overview-of-synchronization-primitives&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-076
    </content>
    <updated>2026-10-25T17:37:55Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsyussrg8jtl4tn6ruru50cazfm5v50l3cgzmvalxfy7wyf4fqunxqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38js5qf48</id>
    
      <title type="html">Learn: Index from the end with ^ In C#, list[^1] is the last ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsyussrg8jtl4tn6ruru50cazfm5v50l3cgzmvalxfy7wyf4fqunxqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38js5qf48" />
    <content type="html">
      Learn: Index from the end with ^&lt;br/&gt;&lt;br/&gt;In C#, list[^1] is the last item, and list[^2] the one before it. It is short for list[list.Count - 1].&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var list = new List&amp;lt;string&amp;gt; { &amp;#34;a&amp;#34;, &amp;#34;b&amp;#34;, &amp;#34;c&amp;#34; };&lt;br/&gt;Console.WriteLine(list[^1]);&lt;br/&gt;Console.WriteLine(list[^2]);&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints c, then b.&lt;br/&gt;&lt;br/&gt;It works on arrays, List&amp;lt;T&amp;gt; and strings. On an empty list, list[^1] throws, like list[list.Count - 1] would.&lt;br/&gt;&lt;br/&gt;#sq003 · SQ-003-N
    </content>
    <updated>2026-10-25T17:07:50Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsfdudxjcdk5rvuj9shvedat74jedf7kpysms724as8wgxr3hwa30czyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jpxx65x</id>
    
      <title type="html">Learn: Sorting cheat sheet Costs, memory and stability of the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsfdudxjcdk5rvuj9shvedat74jedf7kpysms724as8wgxr3hwa30czyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jpxx65x" />
    <content type="html">
      In reply to &lt;a href=&#39;/naddr1qqt4gj2s95crvd6qxgcryd3dxycz6v342scnsvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hsyg8x3gy9d6gdnxtmraepayzjfxykgyka2upen2v8kt506hnlel3z0ypsgqqqw4rs3enuxk&#39;&gt;naddr1qq…nuxk&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Learn: Sorting cheat sheet&lt;br/&gt;&lt;br/&gt;Costs, memory and stability of the common sorts, and what C#&amp;#39;s built-in sorts really do.&lt;br/&gt;&lt;br/&gt;Read the full article:&lt;blockquote class=&#34;border-l-05rem border-l-strongpink border-solid&#34;&gt;&lt;div class=&#34;-ml-4 bg-gradient-to-r from-gray-100 dark:from-zinc-800 to-transparent mr-0 mt-0 mb-4 pl-4 pr-2 py-2&#34;&gt;quoting  &lt;span itemprop=&#34;mentions&#34; itemscope itemtype=&#34;https://schema.org/Article&#34;&gt;&lt;a itemprop=&#34;url&#34; href=&#34;/naddr1qqt4gj2s95crvd6qxgcryd3dxycz6v342scnsvesqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszrthwden5te0dehhxtnvdakqz9nhwden5te0wfjkccte9ec8y6tdv9kzumn9wspzpe52pptwjrvej7clwg0fq5jf39jp9h2hqwv6npajar74ul70ugneqvzqqqr4guchgccd&#34; class=&#34;bg-lavender dark:prose:text-neutral-50 dark:text-neutral-50 dark:bg-garnet px-1&#34;&gt;naddr1qq…gccd&lt;/a&gt;&lt;/span&gt;&lt;br/&gt; &lt;/div&gt; 
&lt;h2 id=&#34;sorting-cheat-sheet-2&#34;&gt;Sorting cheat sheet&lt;/h2&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Sort&lt;/th&gt;
&lt;th&gt;Average&lt;/th&gt;
&lt;th&gt;Worst&lt;/th&gt;
&lt;th&gt;Extra memory&lt;/th&gt;
&lt;th&gt;Stable?&lt;/th&gt;
&lt;th&gt;Good for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Bubble&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;teaching, tiny arrays&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Insertion&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;small or nearly sorted data&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Merge&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;linked lists, stable sorting&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Quick&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;O(log n)&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;fast in practice on arrays&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Heap&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;guaranteed O(n log n) in place&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Stable&lt;/strong&gt; means equal items keep their original order. It matters when you sort by one field after another (sort by name, then by age).&lt;/p&gt;

&lt;h3 id=&#34;what-c-does-2&#34;&gt;What C# does&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Array.Sort&lt;/code&gt; and &lt;code&gt;List&amp;lt;T&amp;gt;.Sort&lt;/code&gt; are O(n log n) but &lt;strong&gt;not stable&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;LINQ &lt;code&gt;OrderBy&lt;/code&gt; / &lt;code&gt;ThenBy&lt;/code&gt; &lt;strong&gt;is stable&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Both take a custom order: a comparison or a key.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;var people = new List&amp;lt;(string Name, int Age)&amp;gt; { (&amp;#34;Ann&amp;#34;, 30), (&amp;#34;Bob&amp;#34;, 25), (&amp;#34;Cy&amp;#34;, 30) };
var byAge = people.OrderBy(p =&amp;gt; p.Age).Select(p =&amp;gt; p.Name); // stable: Ann stays before Cy
Console.WriteLine(string.Join(&amp;#34; &amp;#34;, byAge));
int[] nums = { 3, 1, 2 };
Array.Sort(nums, (a, b) =&amp;gt; b.CompareTo(a)); // custom order: largest first
Console.WriteLine(string.Join(&amp;#34; &amp;#34;, nums));
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It prints &lt;code&gt;Bob Ann Cy&lt;/code&gt; (Ann stays before Cy: stable), then &lt;code&gt;3 2 1&lt;/code&gt; (largest first).&lt;/p&gt;

&lt;h3 id=&#34;interview-tips-2&#34;&gt;Interview tips&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Say the cost &lt;em&gt;and&lt;/em&gt; whether it is stable.&lt;/li&gt;
&lt;li&gt;&amp;#34;Why is quick sort usually fast but O(n²) at worst?&amp;#34; Bad pivots split the array unevenly, for example always picking the first item of sorted data.&lt;/li&gt;
&lt;li&gt;Sorting first often makes the rest easy (two pointers, duplicates next to each other), but adds O(n log n).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/merge-sort/&#34;&gt;https://www.geeksforgeeks.org/dsa/merge-sort/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;#tip · TIP-067&lt;/p&gt;
 &lt;/blockquote&gt;&lt;br/&gt;#tip · TIP-067
    </content>
    <updated>2026-10-25T16:37:55Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsvh39740ktq8n8xe99zzh6hhv43cf0quhhcjjc839t09scn5dsktgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j84l8fl</id>
    
      <title type="html">Learn: Linked list What: nodes, each holding a value and a link ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsvh39740ktq8n8xe99zzh6hhv43cf0quhhcjjc839t09scn5dsktgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j84l8fl" />
    <content type="html">
      Learn: Linked list&lt;br/&gt;&lt;br/&gt;What: nodes, each holding a value and a link to the next node.&lt;br/&gt;Cost: insert or remove at a node you already hold is O(1); reaching item k is O(k), because you must walk.&lt;br/&gt;Use it when: you add and remove at the ends or in the middle a lot, and rarely jump to a position. Example: an LRU cache, which pairs a Dictionary (find a node fast) with a linked list (move it to the front).&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var list = new LinkedList&amp;lt;int&amp;gt;();&lt;br/&gt;list.AddLast(2); list.AddLast(3); list.AddFirst(1);&lt;br/&gt;Console.WriteLine(string.Join(&amp;#34; &amp;#34;, list));&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 1 2 3. .NET&amp;#39;s LinkedList&amp;lt;T&amp;gt; is doubly linked. In practice List&amp;lt;T&amp;gt; is often faster, because its items sit next to each other in memory.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/linked-list-data-structure/&#34;&gt;https://www.geeksforgeeks.org/dsa/linked-list-data-structure/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-026
    </content>
    <updated>2026-10-25T16:07:58Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqspdj3kxqal69qgz6lr7tf386hhhv0he0emwa8rrkfzj62lyxk3ktszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jz4v7zq</id>
    
      <title type="html">Learn: Interface An interface is a contract: members a class must ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqspdj3kxqal69qgz6lr7tf386hhhv0he0emwa8rrkfzj62lyxk3ktszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jz4v7zq" />
    <content type="html">
      Learn: Interface&lt;br/&gt;&lt;br/&gt;An interface is a contract: members a class must provide. It can&amp;#39;t hold instance data (no fields); since C# 8 it may give a method a default body.&lt;br/&gt;A class can implement many interfaces.&lt;br/&gt;Use it when: different classes should be usable the same way, for DI and testing with fakes, or plug-ins.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;IShape[] shapes = { new Square(2), new Circle(1) };&lt;br/&gt;foreach (var s in shapes) Console.WriteLine(s.Area().ToString(&amp;#34;0.00&amp;#34;));&lt;br/&gt;&lt;br/&gt;interface IShape { double Area(); }&lt;br/&gt;record Square(double Side) : IShape { public double Area() =&amp;gt; Side * Side; }&lt;br/&gt;record Circle(double R) : IShape { public double Area() =&amp;gt; Math.PI * R * R; }&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 4.00, then 3.14.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface&#34;&gt;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-048
    </content>
    <updated>2026-10-25T15:37:52Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs2dnhrxhk6ma43l0wdzkptd7r5mpp0499gtrqujj3dtguhpzf6d6szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcd9zjh</id>
    
      <title type="html">Let one recursive function return the height of a subtree, or ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs2dnhrxhk6ma43l0wdzkptd7r5mpp0499gtrqujj3dtguhpzf6d6szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcd9zjh" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqs80vx3m9hvaa2vfd0y9w2h9a7gjhr7a5mnpfdmkhe8jcet52ac33spz3mhxue69uhhyetvv9ujuerpd46hxtnfduvs7k0d&#39;&gt;nevent1q…7k0d&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Let one recursive function return the height of a subtree, or −1 when it has found an unbalanced node. A parent that gets −1 from a child just passes −1 up.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;var ok = new Node(1, new Node(2, new Node(4)), new Node(3));&lt;br/&gt;var bad = new Node(1, new Node(2, new Node(3, new Node(4))));&lt;br/&gt;Console.WriteLine($&amp;#34;{Check(ok) != -1} {Check(bad) != -1}&amp;#34;);&lt;br/&gt;&lt;br/&gt;int Check(Node? n) // the height, or -1 if some subtree is unbalanced&lt;br/&gt;{&lt;br/&gt;    if (n == null) return 0;&lt;br/&gt;    int l = Check(n.Left), r = Check(n.Right);&lt;br/&gt;    return l &amp;lt; 0 || r &amp;lt; 0 || Math.Abs(l - r) &amp;gt; 1 ? -1 : 1 &#43; Math.Max(l, r);&lt;br/&gt;}&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints True False.&lt;br/&gt;&lt;br/&gt;Each node is visited once, so it is O(n) time, plus O(height) for the call stack.&lt;br/&gt;&lt;br/&gt;#tg004 · TG-004-A1
    </content>
    <updated>2026-10-25T15:08:09Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs80vx3m9hvaa2vfd0y9w2h9a7gjhr7a5mnpfdmkhe8jcet52ac33szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jq4n275</id>
    
      <title type="html">Question: A binary tree is balanced if, at every node, the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs80vx3m9hvaa2vfd0y9w2h9a7gjhr7a5mnpfdmkhe8jcet52ac33szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jq4n275" />
    <content type="html">
      Question: A binary tree is balanced if, at every node, the heights of the left and right subtrees differ by at most 1.&lt;br/&gt;&lt;br/&gt;Write a check that visits each node only once.&lt;br/&gt;&lt;br/&gt;(CtCI 4.4)&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg004 · TG-004-Q1
    </content>
    <updated>2026-10-25T15:08:09Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsvjwxata85pz6pqlqah4yvtmu3cet9t0ett7u875hfr5d3kh8k4uczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jvs9ksw</id>
    
      <title type="html">Learn: Concurrency vs parallelism Concurrency: several tasks are ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsvjwxata85pz6pqlqah4yvtmu3cet9t0ett7u875hfr5d3kh8k4uczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jvs9ksw" />
    <content type="html">
      Learn: Concurrency vs parallelism&lt;br/&gt;&lt;br/&gt;Concurrency: several tasks are in progress at the same time, maybe taking turns on one core. Example: a server waiting on many database calls.&lt;br/&gt;Parallelism: work really runs at the same moment on several cores. Example: resizing 1,000 images.&lt;br/&gt;&lt;br/&gt;In .NET: waiting on I/O → async/await. CPU-heavy work → Parallel.For, or Task.Run in UI apps (on a server, Task.Run only moves work between pool threads). Both bring the same risk: shared data touched by two threads at once.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming&#34;&gt;https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-072
    </content>
    <updated>2026-10-25T14:33:00Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs97yn33kgyxpr72yu0l5746l5wsylpudky6mxe9m7c35yl48qrr3szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcwrr8t</id>
    
      <title type="html">Learn: Caching in one breath A cache keeps a copy of slow data ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs97yn33kgyxpr72yu0l5746l5wsylpudky6mxe9m7c35yl48qrr3szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jcwrr8t" />
    <content type="html">
      Learn: Caching in one breath&lt;br/&gt;&lt;br/&gt;A cache keeps a copy of slow data (like a database result) somewhere fast (like memory). Reads get much faster.&lt;br/&gt;&lt;br/&gt;The hard part is staleness: when the real data changes, the copy is wrong. Common answers: an expiry time (TTL), or deleting the cached copy on every write.&lt;br/&gt;&lt;br/&gt;#tip · TIP-013
    </content>
    <updated>2026-10-25T14:07:55Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqswm9f05ltrx40yx7lkeun24v3396rrf04f6rpnrremeyx8v6p5jfgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j08f7g6</id>
    
      <title type="html">Learn: Divide and conquer The pattern: split the problem into ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqswm9f05ltrx40yx7lkeun24v3396rrf04f6rpnrremeyx8v6p5jfgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j08f7g6" />
    <content type="html">
      Learn: Divide and conquer&lt;br/&gt;&lt;br/&gt;The pattern: split the problem into smaller parts of the same kind, solve each part (usually with recursion), then combine the answers.&lt;br/&gt;&lt;br/&gt;Examples: merge sort (split, sort halves, merge), quick sort, binary search (keep only one half).&lt;br/&gt;&lt;br/&gt;Why it helps: splitting in half again and again gives about log n levels, which is where the &amp;#34;log n&amp;#34; in O(n log n) comes from.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/divide-and-conquer/&#34;&gt;https://www.geeksforgeeks.org/dsa/divide-and-conquer/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-036
    </content>
    <updated>2026-10-25T13:37:50Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsvhx935etz3alxn8lctty2jdfrlpem6ve6xxprc34lvxr87zwr5lqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j6fn96n</id>
    
      <title type="html">Question: What is the time cost of building the tree from the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsvhx935etz3alxn8lctty2jdfrlpem6ve6xxprc34lvxr87zwr5lqzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j6fn96n" />
    <content type="html">
      Question: What is the time cost of building the tree from the middle, and how deep does the recursion go?&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg002 · TG-002-Q2
    </content>
    <updated>2026-10-25T13:08:00Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs9aj4898fc93wxwk8wjlaqlmt6agzcl5kv7k254xlk9486urajvvszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jgychh2</id>
    
      <title type="html">Time: O(n). Each call creates one node and does O(1) work besides ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs9aj4898fc93wxwk8wjlaqlmt6agzcl5kv7k254xlk9486urajvvszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jgychh2" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqsvhx935etz3alxn8lctty2jdfrlpem6ve6xxprc34lvxr87zwr5lqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduts4833&#39;&gt;nevent1q…4833&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Time: O(n). Each call creates one node and does O(1) work besides its two recursive calls, and each value becomes exactly one node.&lt;br/&gt;&lt;br/&gt;Recursion depth: O(log n), because each call works on half the range. That is also the height of the tree.&lt;br/&gt;&lt;br/&gt;No copying is needed: pass lo and hi indexes instead of making smaller arrays. Copying sub-arrays would add O(n log n) work.&lt;br/&gt;&lt;br/&gt;#tg002 · TG-002-A2
    </content>
    <updated>2026-10-25T13:08:00Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs8yuqpk9njtq9fh67ptuz3sc4hzc5tdm5erkwd3muaygld9d04fgczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jsez5ht</id>
    
      <title type="html">Learn: Factory A factory creates objects for you, so the caller ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs8yuqpk9njtq9fh67ptuz3sc4hzc5tdm5erkwd3muaygld9d04fgczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jsez5ht" />
    <content type="html">
      Learn: Factory&lt;br/&gt;&lt;br/&gt;A factory creates objects for you, so the caller asks for &amp;#34;a pdf exporter&amp;#34; without naming the class.&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;Console.WriteLine(Create(&amp;#34;pdf&amp;#34;).Export());&lt;br/&gt;static IExporter Create(string kind) =&amp;gt; kind switch&lt;br/&gt;{&lt;br/&gt;    &amp;#34;pdf&amp;#34; =&amp;gt; new PdfExporter(),&lt;br/&gt;    &amp;#34;csv&amp;#34; =&amp;gt; new CsvExporter(),&lt;br/&gt;    _ =&amp;gt; throw new ArgumentException(kind),&lt;br/&gt;};&lt;br/&gt;interface IExporter { string Export(); }&lt;br/&gt;class PdfExporter : IExporter { public string Export() =&amp;gt; &amp;#34;PDF file&amp;#34;; }&lt;br/&gt;class CsvExporter : IExporter { public string Export() =&amp;gt; &amp;#34;CSV file&amp;#34;; }&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints PDF file.&lt;br/&gt;Use it when: which class to create depends on input or configuration, or creating it is complicated.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/system-design/factory-method-for-designing-pattern/&#34;&gt;https://www.geeksforgeeks.org/system-design/factory-method-for-designing-pattern/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-052
    </content>
    <updated>2026-10-25T12:38:07Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqs89zfae2ysz8wm3n5fmtcny4mgxp5sjvu8q968y3rs5ss3tj2kekgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jsc2jjr</id>
    
      <title type="html">Learn: Bubble sort What: walk the array and swap neighbors that ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqs89zfae2ysz8wm3n5fmtcny4mgxp5sjvu8q968y3rs5ss3tj2kekgzyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jsc2jjr" />
    <content type="html">
      Learn: Bubble sort&lt;br/&gt;&lt;br/&gt;What: walk the array and swap neighbors that are in the wrong order; repeat until nothing moves. The biggest item &amp;#34;bubbles&amp;#34; to the end each pass.&lt;br/&gt;Cost: O(n²). With an early stop when a pass makes no swap, O(n) on already sorted data.&lt;br/&gt;Use it when: teaching, or tiny arrays. In real code use Array.Sort, which is O(n log n).&lt;br/&gt;&lt;br/&gt;```csharp&lt;br/&gt;int[] a = { 5, 1, 4, 2 };&lt;br/&gt;for (int end = a.Length - 1; end &amp;gt; 0; end--)&lt;br/&gt;{&lt;br/&gt;    bool swapped = false;&lt;br/&gt;    for (int i = 0; i &amp;lt; end; i&#43;&#43;)&lt;br/&gt;        if (a[i] &amp;gt; a[i &#43; 1]) { (a[i], a[i &#43; 1]) = (a[i &#43; 1], a[i]); swapped = true; }&lt;br/&gt;    if (!swapped) break; // already sorted: stop early&lt;br/&gt;}&lt;br/&gt;Console.WriteLine(string.Join(&amp;#34; &amp;#34;, a));&lt;br/&gt;```&lt;br/&gt;&lt;br/&gt;It prints 1 2 4 5.&lt;br/&gt;&lt;br/&gt;Read more: &lt;a href=&#34;https://www.geeksforgeeks.org/dsa/bubble-sort-algorithm/&#34;&gt;https://www.geeksforgeeks.org/dsa/bubble-sort-algorithm/&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;#tip · TIP-035
    </content>
    <updated>2026-10-25T12:08:03Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsvtz083vrrakxse83ylqdtwzqtnv3gtujfnf5ska500xzkqzn5jvczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j0lyrey</id>
    
      <title type="html">Learn: Brute force first, then improve If you don&amp;#39;t see the ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsvtz083vrrakxse83ylqdtwzqtnv3gtujfnf5ska500xzkqzn5jvczyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38j0lyrey" />
    <content type="html">
      Learn: Brute force first, then improve&lt;br/&gt;&lt;br/&gt;If you don&amp;#39;t see the best solution right away, say the simple one first, with its Big-O. For example: &amp;#34;Check every pair: O(n²).&amp;#34;&lt;br/&gt;&lt;br/&gt;Then ask yourself what work is repeated. A HashSet, sorting, or two pointers often removes it. A working slow answer beats an unfinished fast one.&lt;br/&gt;&lt;br/&gt;#tip · TIP-003
    </content>
    <updated>2026-10-25T11:38:01Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsgvxhvgn26mckg55rlfh3egslug3q6vn0jah045j8wvz6z0lmdh2szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jqwprvp</id>
    
      <title type="html">Both are O(V &#43; E) and both answer &amp;#34;is there a route?&amp;#34;. ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsgvxhvgn26mckg55rlfh3egslug3q6vn0jah045j8wvz6z0lmdh2szyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jqwprvp" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqsz55svffya6slk4syncatv0hu705zwcc65h9gywrr878e2j4lfavspz3mhxue69uhhyetvv9ujuerpd46hxtnfdu725msp&#39;&gt;nevent1q…5msp&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;Both are O(V &#43; E) and both answer &amp;#34;is there a route?&amp;#34;.&lt;br/&gt;&lt;br/&gt;Pick breadth-first when you also want the shortest route (fewest edges), or when the target is probably close: it explores in rings around the start.&lt;br/&gt;&lt;br/&gt;Pick depth-first when you need to go deep anyway, for example to find cycles or a build order. It is short to write with recursion, but a very deep graph can overflow the call stack, so use your own Stack&amp;lt;T&amp;gt; for big inputs.&lt;br/&gt;&lt;br/&gt;#tg001 · TG-001-A2
    </content>
    <updated>2026-10-25T11:07:55Z</updated>
  </entry>

  <entry>
    <id>https://nostr.now/nevent1qqsz55svffya6slk4syncatv0hu705zwcc65h9gywrr878e2j4lfavszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jp9van3</id>
    
      <title type="html">Question: Depth-first search would also work here. When would you ...</title>
    
    <link rel="alternate" href="https://nostr.now/nevent1qqsz55svffya6slk4syncatv0hu705zwcc65h9gywrr878e2j4lfavszyrng5zzkayxen9a37us7jpfynztyztw4wque4xrm968atelulc38jp9van3" />
    <content type="html">
      Question: Depth-first search would also work here. When would you pick breadth-first, and when depth-first?&lt;br/&gt;&lt;br/&gt;Try to answer before you open the reply.&lt;br/&gt;&lt;br/&gt;#tg001 · TG-001-Q2
    </content>
    <updated>2026-10-25T11:07:55Z</updated>
  </entry>

</feed>