<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Clark Ngo</title>
    <description>The latest articles on DEV Community by Clark Ngo (@clarkngo).</description>
    <link>https://dev.to/clarkngo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F140868%2F9d0d6245-5d1e-450d-baae-489706829100.jpeg</url>
      <title>DEV Community: Clark Ngo</title>
      <link>https://dev.to/clarkngo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/clarkngo"/>
    <language>en</language>
    <item>
      <title>Case Study - Slack: Scaling to Hundred Thousand Users</title>
      <dc:creator>Clark Ngo</dc:creator>
      <pubDate>Thu, 07 Jul 2022 05:22:03 +0000</pubDate>
      <link>https://dev.to/clarkngo/case-study-slack-scaling-to-hundred-thousand-users-m86</link>
      <guid>https://dev.to/clarkngo/case-study-slack-scaling-to-hundred-thousand-users-m86</guid>
      <description>&lt;h3&gt;
  
  
  Follow Me, Shout Out, or Give Thanks!
&lt;/h3&gt;

&lt;p&gt;Please 💖 this article. a small thing to keep me motivated =)&lt;br&gt;
Twitter: &lt;a href="https://twitter.com/djjasonclark" rel="noopener noreferrer"&gt;@djjasonclark&lt;/a&gt;&lt;br&gt;
Linkedin: &lt;a href="https://www.linkedin.com/in/clarkngo/" rel="noopener noreferrer"&gt;in/clarkngo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4kqws1sg53rxlu3riti3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4kqws1sg53rxlu3riti3.png" alt="Case Study Slack 1" width="800" height="843"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwx9nsj34forme65oenlw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwx9nsj34forme65oenlw.png" alt="Case Study Slack 2" width="800" height="755"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>slack</category>
      <category>scaling</category>
    </item>
    <item>
      <title>Simple and Better Pull Requests</title>
      <dc:creator>Clark Ngo</dc:creator>
      <pubDate>Tue, 28 Jun 2022 11:34:23 +0000</pubDate>
      <link>https://dev.to/clarkngo/simple-and-better-pull-requests-469o</link>
      <guid>https://dev.to/clarkngo/simple-and-better-pull-requests-469o</guid>
      <description>&lt;h3&gt;
  
  
  Follow Me, Shout Out, or Give Thanks!
&lt;/h3&gt;

&lt;p&gt;Please 💖 this article. a small thing to keep me motivated =)&lt;br&gt;
Twitter: &lt;a href="https://twitter.com/djjasonclark"&gt;@djjasonclark&lt;/a&gt;&lt;br&gt;
Linkedin: &lt;a href="https://www.linkedin.com/in/clarkngo/"&gt;in/clarkngo&lt;/a&gt;&lt;br&gt;
Note: if there are technical jargons here, that is by design (its a way for me to impart my experience as software engineer). I'd like readers to expand their tech jargon dictionary. you can google or leave a comment. 😊&lt;/p&gt;

&lt;p&gt;Are you guilty  of naming your commits and PRs (pull requests) such as &lt;strong&gt;add button&lt;/strong&gt;, &lt;strong&gt;fix bug on form&lt;/strong&gt;, etc.? &lt;/p&gt;

&lt;p&gt;Are you having a hard time linking this to a user story/task/ticket?&lt;/p&gt;

&lt;p&gt;Say no more. &lt;/p&gt;

&lt;p&gt;Why do we need this? 🤔 &lt;/p&gt;

&lt;p&gt;Well... gives us more info. new code changes can lead to... breaking the application (hoping its not a production pool and serving lots of traffic) 😬&lt;/p&gt;

&lt;p&gt;With PR integration to a project management tool, It adds visibility to managers. They don't need to always look at your code repository (like GitHub) to know the status of a feature request or bug fix.&lt;/p&gt;
&lt;h2&gt;
  
  
  Linking your ticket and PRs - that lazy manual way
&lt;/h2&gt;

&lt;p&gt;If you have a ticket with title: &lt;code&gt;app-1234 enhance-response-performance&lt;/code&gt;, then before you push your code base, then use this as commit message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m 'app-1234 enhance-response-performance'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this way if something breaks, then when you do RCA (root cause analysis) it easier to track down, and get more information, instead of just the owner. Then we can do the necessary fix. Maybe rollback the latest manifest deployed, or do a roll forward fix instead. &lt;/p&gt;

&lt;p&gt;Bonus tip: &lt;br&gt;
don't know who wrote that code line?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git blame Filename.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;want more visualization in git (helpful for very active code bases with lots of contributors and branches)? Download &lt;a href="https://www.syntevo.com/smartgit/"&gt;SmartGit&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Automate that manual process
&lt;/h2&gt;

&lt;p&gt;Enter webhooks (do something when event happens)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;when you create a new PR with the same jira title (well just appname-1234 without the extra text might work already), then it will update your JIRA ticket with the status of that PR.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://confluence.atlassian.com/automation070/how-to-integrate-jira-and-github-using-automation-for-jira-1014664530.html"&gt;How to automate&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus
&lt;/h2&gt;

&lt;p&gt;Jira &lt;br&gt;
what is Jira? It is a popular project management tool. How popular? Jira market share is 44.11% with more than 72391 companies using this software. Data from &lt;a href="https://www.datanyze.com/market-share/project-management--217/jira-market-share"&gt;Datanyze&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A tool where most developers dread. Story points? estimate? can I just work?&lt;/p&gt;

&lt;p&gt;What creating button takes 5 days when hooking up and reading/writing to a database took 1 day? 🤪&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zJ9Jb89Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h983a7yxqa22h1r8u83e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zJ9Jb89Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h983a7yxqa22h1r8u83e.png" alt="JIRA" width="730" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>pullrequest</category>
      <category>codechanges</category>
      <category>sdlc</category>
      <category>shortread</category>
    </item>
    <item>
      <title>Why use Java - Map.computeIfAbsent</title>
      <dc:creator>Clark Ngo</dc:creator>
      <pubDate>Tue, 28 Jun 2022 10:47:06 +0000</pubDate>
      <link>https://dev.to/clarkngo/why-use-java-mapcomputeifabsent-4945</link>
      <guid>https://dev.to/clarkngo/why-use-java-mapcomputeifabsent-4945</guid>
      <description>&lt;h3&gt;
  
  
  Follow Me, Shout Out, or Give Thanks!
&lt;/h3&gt;

&lt;p&gt;Please 💖 this article. a small thing to keep me motivated =)&lt;br&gt;
Twitter: &lt;a href="https://twitter.com/djjasonclark"&gt;@djjasonclark&lt;/a&gt;&lt;br&gt;
Linkedin: &lt;a href="https://www.linkedin.com/in/clarkngo/"&gt;in/clarkngo&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  computeIfAbsent
&lt;/h1&gt;

&lt;p&gt;When to use?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if we want to do call a function if key is not found&lt;/li&gt;
&lt;li&gt;good for initializing a data structure and inserting to map&lt;/li&gt;
&lt;li&gt;a shorter implementation instead of doing on your own
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;default V computeIfAbsent(K key,
                          Function&amp;lt;? super K,? extends V&amp;gt; mappingFunction)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#computeIfAbsent-K-java.util.function.Function-"&gt;Java docs - computeIfAbsent&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It means, we can &lt;strong&gt;compute&lt;/strong&gt; (call) a function, if &lt;strong&gt;key&lt;/strong&gt; is absent (not found). &lt;/p&gt;

&lt;p&gt;Scenario: I need a map that have this structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Map&amp;lt;String, List&amp;lt;String&amp;gt; map;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So whenever we want to add a new key and a value, we usually do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (map.get("my_key") == null) {
    map.get("my_key").add("new_str");
} else {
    // or Arrays.asList("new_str"),
    map.put("my_key", new ArrayList&amp;lt;&amp;gt;());
    map.get("my_key").add("new_str");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use &lt;code&gt;computeIfAbsent&lt;/code&gt; to make it elegant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map.computeIfAbsent("my_key", k -&amp;gt; new ArrayList&amp;lt;&amp;gt;());
map.get("my_key").add("new_str");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>java</category>
      <category>coding</category>
      <category>map</category>
    </item>
    <item>
      <title>How to solve Group Anagrams problem</title>
      <dc:creator>Clark Ngo</dc:creator>
      <pubDate>Tue, 28 Jun 2022 10:27:23 +0000</pubDate>
      <link>https://dev.to/clarkngo/group-anagrams-j91</link>
      <guid>https://dev.to/clarkngo/group-anagrams-j91</guid>
      <description>&lt;h3&gt;
  
  
  Follow Me, Shout Out, or Give Thanks!
&lt;/h3&gt;

&lt;p&gt;Please 💖 this article. a small thing to keep me motivated =)&lt;br&gt;
Twitter: &lt;a href="https://twitter.com/djjasonclark"&gt;@djjasonclark&lt;/a&gt;&lt;br&gt;
Linkedin: &lt;a href="https://www.linkedin.com/in/clarkngo/"&gt;in/clarkngo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.&lt;/p&gt;

&lt;p&gt;Let's work with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Trial 1 - Not efficient:
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;(plus space) copy input
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;["eat","tea","tan","ate","nat","bat"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;(plus time) sort copied input
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;["aet", "aet", "ant", "aet", "ant", "abt"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;(plus space and another space for map/dictionary and plus time) create list and assign same number to same words
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1,1,2,1,2,3]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well... let's just stop there.&lt;/p&gt;

&lt;h1&gt;
  
  
  Trial 2 - Hashing:
&lt;/h1&gt;

&lt;p&gt;Hashing? The process of assigning a unique value to an object or attribute using an algorithm, which enables quicker access, is known as hashing. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;(plus space and time) iterate over each string and each of its character. in every loop, generate a "hash" by increase value at indices representing character (0 -&amp;gt; 'a', 1 -&amp;gt; 'b')&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;once you have a hash, add that a key to a map/dictionary (key-&amp;gt; string, val-&amp;gt; list of strings). then insert word/s.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you reach this.. you already know what to do. =)&lt;/p&gt;

</description>
      <category>java</category>
      <category>coding</category>
      <category>algorithms</category>
      <category>shortread</category>
    </item>
    <item>
      <title>A Minute of Understanding POM</title>
      <dc:creator>Clark Ngo</dc:creator>
      <pubDate>Fri, 10 Jun 2022 08:51:06 +0000</pubDate>
      <link>https://dev.to/clarkngo/a-minute-of-understanding-pom-4abj</link>
      <guid>https://dev.to/clarkngo/a-minute-of-understanding-pom-4abj</guid>
      <description>&lt;h3&gt;
  
  
  Follow Me, Shout Out, or Give Thanks!
&lt;/h3&gt;

&lt;p&gt;Please 💖 this article. a small thing to keep me motivated =)&lt;br&gt;
Twitter: &lt;a href="https://twitter.com/djjasonclark" rel="noopener noreferrer"&gt;@djjasonclark&lt;/a&gt;&lt;br&gt;
Linkedin: &lt;a href="https://www.linkedin.com/in/clarkngo/" rel="noopener noreferrer"&gt;in/clarkngo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you are going to build a project with Java and ended up choosing Maven, you will encounter POM. The &lt;code&gt;pom.xml&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;If you want a sample of a that &lt;code&gt;pom.xml&lt;/code&gt; file, go ahead.&lt;br&gt;
Go to &lt;a href="https://start.spring.io/" rel="noopener noreferrer"&gt;Spring Initializer&lt;/a&gt; site&lt;/p&gt;

&lt;p&gt;Choose the defaults and make sure to select Maven Project.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpbrh6ev4vqe5oc1vr4ne.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpbrh6ev4vqe5oc1vr4ne.png" alt="Image description" width="800" height="937"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;demo
|_ HELP.md
|_ mvnw.xml
|_ mvnw.cmd
|_ pom.xml
|_ src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;pom.xml&lt;/code&gt; file will already contain a pre-configured structure, making it a great starting point for your exploration.&lt;/p&gt;

&lt;p&gt;Breaking Down the pom.xml&lt;br&gt;
There’s a lot to unpack when it comes to the &lt;code&gt;pom.xml&lt;/code&gt;. Here’s a quick overview:&lt;/p&gt;

&lt;p&gt;Project Information:&lt;br&gt;
The &lt;code&gt;&amp;lt;modelVersion&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;groupId&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;artifactId&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;version&amp;gt;&lt;/code&gt; elements define the basic identity of your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;
&amp;lt;groupId&amp;gt;com.example&amp;lt;/groupId&amp;gt;
&amp;lt;artifactId&amp;gt;demo&amp;lt;/artifactId&amp;gt;
&amp;lt;version&amp;gt;0.0.1-SNAPSHOT&amp;lt;/version&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dependencies:&lt;br&gt;
This section lists all external libraries your project requires. Maven handles downloading these libraries for you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependencies&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;spring-boot-starter&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;2.5.2&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;
&amp;lt;/dependencies&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build Plugins:&lt;br&gt;
Plugins extend Maven’s functionality, enabling you to perform tasks like creating JARs, running tests, or integrating with CI/CD pipelines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;build&amp;gt;
    &amp;lt;plugins&amp;gt;
        &amp;lt;plugin&amp;gt;
            &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;3.8.1&amp;lt;/version&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;source&amp;gt;11&amp;lt;/source&amp;gt;
                &amp;lt;target&amp;gt;11&amp;lt;/target&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/plugin&amp;gt;
    &amp;lt;/plugins&amp;gt;
&amp;lt;/build&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why Use Maven and &lt;code&gt;pom.xml&lt;/code&gt;?&lt;br&gt;
Dependency Management: Maven handles downloading and resolving dependencies, saving you from manual efforts.&lt;/p&gt;

&lt;p&gt;Project Consistency: With &lt;code&gt;pom.xml&lt;/code&gt;, your team can maintain a consistent configuration across multiple environments.&lt;br&gt;
Ease of Use: Maven provides commands like &lt;code&gt;mvn clean install&lt;/code&gt; that automatically handle builds, tests, and packaging.&lt;br&gt;
Extensibility: Add plugins to extend functionality, like generating reports or deploying your app to a server.&lt;/p&gt;

&lt;p&gt;What’s Next?&lt;br&gt;
The &lt;code&gt;pom.xml&lt;/code&gt; is much more than a configuration file. In upcoming sections, we’ll cover:&lt;/p&gt;

&lt;p&gt;Customizing dependency scopes (e.g., &lt;code&gt;compile&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt;, &lt;code&gt;runtime&lt;/code&gt;).&lt;br&gt;
Understanding Maven’s build lifecycle (e.g., phases like validate, compile, package).&lt;br&gt;
Adding profiles for environment-specific configurations.&lt;br&gt;
Writing multi-module projects with parent and child &lt;code&gt;pom.xml&lt;/code&gt; files.&lt;br&gt;
Share Your Feedback!&lt;/p&gt;

&lt;p&gt;Let us know your thoughts or topics you’d like to see covered next. From beginner-friendly guides to advanced configurations, we’re here to explore Maven with you.&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Logic Explained: Meeting Scheduler - Leetcode [Java] using Two Pointers</title>
      <dc:creator>Clark Ngo</dc:creator>
      <pubDate>Wed, 14 Apr 2021 01:02:40 +0000</pubDate>
      <link>https://dev.to/clarkngo/logic-explained-meeting-scheduler-leetcode-java-using-two-pointers-4881</link>
      <guid>https://dev.to/clarkngo/logic-explained-meeting-scheduler-leetcode-java-using-two-pointers-4881</guid>
      <description>&lt;h3&gt;
  
  
  Follow Me, Shout Out, or Give Thanks!
&lt;/h3&gt;

&lt;p&gt;Please 💖 this article. a small thing to keep me motivated =)&lt;br&gt;
Twitter: &lt;a href="https://twitter.com/djjasonclark"&gt;@djjasonclark&lt;/a&gt;&lt;br&gt;
Linkedin: &lt;a href="https://www.linkedin.com/in/clarkngo/"&gt;in/clarkngo&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Description
&lt;/h4&gt;

&lt;p&gt;Given the availability time slots arrays &lt;code&gt;slots1&lt;/code&gt; and &lt;code&gt;slots2&lt;/code&gt; of two people and a meeting duration, return the earliest time slot that works for both of them and is of duration.&lt;/p&gt;

&lt;p&gt;If there is no common time slot that satisfies the requirements, return an empty array.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 1
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8
Output: [60,68]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example 2
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12
Output: []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Scenario
&lt;/h3&gt;

&lt;p&gt;Today, your two coworkers need to meet for a specific time duration at the earliest available time. Both of them gave you a list of open slots in their day. You are tasked to find overlapping slots (open slot of co-worker &lt;strong&gt;A&lt;/strong&gt; and open slot co-worker &lt;strong&gt;B&lt;/strong&gt;) the would allow them to have a meeting given the time duration of the meeting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Logic
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Look at co-worker &lt;strong&gt;A&lt;/strong&gt; available slot &lt;strong&gt;AND&lt;/strong&gt; compare it with co-worker &lt;strong&gt;B&lt;/strong&gt; available slot.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the available slot range is not within the meeting time duration, look for the next available slot of &lt;strong&gt;a co-worker&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Question: Which co-worker's next available slot should we look at first to compare with the other co-worker's current available slot?&lt;/p&gt;

&lt;p&gt;Answer: The co-worker, with the lower end time for its current available slot compared to the other co-worker's end time for its current available slot, is the one we should check for the next available slot.&lt;/p&gt;

&lt;h3&gt;
  
  
  Algorithm: Two Pointer Technique
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use of two pointers in a loop.&lt;/li&gt;
&lt;li&gt;Helps reduce the time complexity of O(n&lt;sup&gt;3&lt;/sup&gt;) or O(n&lt;sup&gt;2&lt;/sup&gt;) to O(n) with just one loop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Pseudocode
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Sort the &lt;code&gt;slots1&lt;/code&gt; and &lt;code&gt;slots2&lt;/code&gt; array in ascending order of the starting time. &lt;em&gt;Use Arrays.sort() with &lt;code&gt;Comparator&lt;/code&gt; in the 2nd parameter&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialize two pointers at index 0.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;While&lt;/strong&gt; pointer for the length of &lt;code&gt;slots1&lt;/code&gt; is less than the length of &lt;code&gt;slots1&lt;/code&gt; and pointer for the length of &lt;code&gt;slots2&lt;/code&gt; is less than the length of &lt;code&gt;slots2&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
a. Initialize/reinitialize two arrays to hold the current slot for each co-worker.&lt;br&gt;&lt;br&gt;
b. Initialize/reinitialize two integers: 1) to store the max start time between two co-worker's current available slots. 2) to store the minimum end time between two co-worker's current available slots.&lt;br&gt;&lt;br&gt;
c. &lt;strong&gt;If&lt;/strong&gt; duration is within the range of max start time and min end time, then return start time and start time + duration.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Else if&lt;/strong&gt; end time of co-worker &lt;strong&gt;A&lt;/strong&gt; less than the end time of co-worker &lt;strong&gt;B&lt;/strong&gt;, then increment co-worker &lt;strong&gt;A&lt;/strong&gt;'s pointer.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Else if&lt;/strong&gt; end time of co-worker &lt;strong&gt;B&lt;/strong&gt; less than the end time of co-worker &lt;strong&gt;A&lt;/strong&gt;, then increment co-worker &lt;strong&gt;B&lt;/strong&gt;'s pointer.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Else&lt;/strong&gt; increment both co-workers &lt;strong&gt;A&lt;/strong&gt; and &lt;strong&gt;B&lt;/strong&gt;'s pointers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return empty array. &lt;em&gt;No overlapping slots the would allow the co-workers to have a meeting given the time duration of the meeting&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Scenarios
&lt;/h3&gt;

&lt;h5&gt;
  
  
  Scenario 1: the end time of Co-worker A’s end time overlaps Co-worker B’s start time.
&lt;/h5&gt;

&lt;p&gt;HOWEVER, overlap is NOT sufficient to cover meeting duration.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_z9ObVre--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztztdmsldwpvqxaj52xo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_z9ObVre--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztztdmsldwpvqxaj52xo.png" alt="image" width="682" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Scenario 2: the end time of Co-worker B’s end time overlaps Co-worker A’s start time.
&lt;/h5&gt;

&lt;p&gt;HOWEVER, overlap is NOT sufficient to cover meeting duration.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X8WnSATt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iulry90d8eatwec2oojs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X8WnSATt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iulry90d8eatwec2oojs.png" alt="image" width="682" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Scenario 3: the end time of Co-worker B’s end time overlaps Co-worker A’s start time (or vice-versa).
&lt;/h5&gt;

&lt;p&gt;AND, overlap is sufficient to cover meeting duration.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6jMutbGa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szaf9dbicr8zgm41ueyz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6jMutbGa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szaf9dbicr8zgm41ueyz.png" alt="image" width="723" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public List&amp;lt;Integer&amp;gt; minAvailableDuration(int[][] slots1, int[][] slots2, int duration) {
        Arrays.sort(slots1, (a,b)-&amp;gt; a[0]-b[0]);
        Arrays.sort(slots2, (a,b)-&amp;gt; a[0]-b[0]);

        int p1 = 0;
        int p2 = 0;

        while (p1 &amp;lt; slots1.length &amp;amp;&amp;amp; p2 &amp;lt; slots2.length) {
            int[] curr1 = slots1[p1];
            int[] curr2 = slots2[p2];

            int start = Math.max(curr1[0], curr2[0]);
            int end = Math.min(curr1[1], curr2[1]);

            if (end - start &amp;gt;= duration) 
                return Arrays.asList(start,start+duration);
            else if (curr1[1] &amp;lt; curr2[1]) p1++;
            else if (curr2[1] &amp;lt; curr1[1]) p2++;
            else {
                p1++;
                p2++;
            }

        }
        return new ArrayList&amp;lt;&amp;gt;();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>java</category>
      <category>coding</category>
      <category>leetcode</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Logic Explained: Meeting Scheduler - Leetcode [Java] using Priority Queue</title>
      <dc:creator>Clark Ngo</dc:creator>
      <pubDate>Tue, 13 Apr 2021 11:34:43 +0000</pubDate>
      <link>https://dev.to/clarkngo/logic-explained-meeting-room-ii-leetcode-java-1gh5</link>
      <guid>https://dev.to/clarkngo/logic-explained-meeting-room-ii-leetcode-java-1gh5</guid>
      <description>&lt;h3&gt;
  
  
  Follow Me, Shout Out, or Give Thanks!
&lt;/h3&gt;

&lt;p&gt;Please 💖 this article. a small thing to keep me motivated =)&lt;br&gt;
Twitter: &lt;a href="https://twitter.com/djjasonclark" rel="noopener noreferrer"&gt;@djjasonclark&lt;/a&gt;&lt;br&gt;
Linkedin: &lt;a href="https://www.linkedin.com/in/clarkngo/" rel="noopener noreferrer"&gt;in/clarkngo&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Description
&lt;/h4&gt;

&lt;p&gt;Given an array of meeting time &lt;code&gt;intervals&lt;/code&gt; where &lt;code&gt;intervals[i] = [start&lt;/code&gt;i&lt;code&gt;, end&lt;/code&gt;i&lt;code&gt;]&lt;/code&gt;, return the minimum number of conference rooms required.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example 1
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: intervals = [[0,30],[5,10],[15,20]]
Output: 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Example 2
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: intervals = [[7,10],[2,4]]
Output: 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Example 3:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: intervals = [[0,30],[5,10],[10,15],[15,20],[30,50],[30,70]]
Output: 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Scenario
&lt;/h3&gt;

&lt;p&gt;Today, your co-workers from different teams have given you a list of meeting start times and meeting end times. Setting up new rooms for a meeting is a pain so you'd want to &lt;strong&gt;reuse rooms&lt;/strong&gt; that have been freed up by a previous meeting. You are tasked to find out &lt;strong&gt;how many rooms&lt;/strong&gt; will be used.&lt;/p&gt;
&lt;h3&gt;
  
  
  Logic
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Initially no rooms are occupied, so we insert the first earliest start time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For subsequent meetings, check existing rooms are freed up, if yes, reuse the rooms. If not, then open up a new room.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Data Structure: Priority Queue
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;head&lt;/strong&gt; of the priority queue is the &lt;strong&gt;least&lt;/strong&gt; element based on the natural ordering or comparator based ordering. When we poll the queue, it returns the head object from the queue.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Pseudocode
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Sort the &lt;code&gt;intervals&lt;/code&gt; array in ascending order of the starting time. &lt;em&gt;Use Arrays.sort() with &lt;code&gt;Comparator&lt;/code&gt; in the 2nd parameter&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a Priority Queue. We will use this to store ending times of each interval. &lt;em&gt;Use &lt;code&gt;PriorityQueue&lt;/code&gt; data structure. Why Priority Queue? To make sure that when we check the head of the queue, we see the earliest end time at the head of the queue. This makes it efficient to check if we can reuse the room.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the end of time of the first sorted interval array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate over interval array starting at index 1.&lt;br&gt;&lt;br&gt;
a. Check if &lt;strong&gt;starting time in i-th interval array&lt;/strong&gt; is equal or greater than &lt;strong&gt;the end time at the head of the queue&lt;/strong&gt; &lt;em&gt;&lt;code&gt;queue.peek()&lt;/code&gt;&lt;/em&gt;, then remove the end time the head of the queue &lt;em&gt;&lt;code&gt;queue.poll()&lt;/code&gt;&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
b. Add the end of time of the i-th sorted interval array. &lt;em&gt;&lt;code&gt;queue.offer()&lt;/code&gt;. Note: in Priority Queue, we insert a new element at an index of the queue based on natural order&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return the size of queue.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Scenarios
&lt;/h3&gt;
&lt;h5&gt;
  
  
  Scenario 1: the earliest end time in the queue is NOT greater than or equal to new meeting start time.
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Furilyvu02jpjzp5wo2eu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Furilyvu02jpjzp5wo2eu.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Scenario 2: the earliest end time in the queue is greater than or equal to new meeting start time.
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcxrqrioick8wauwq1hc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcxrqrioick8wauwq1hc.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Code
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/meeting-rooms-ii/discuss/1151560/Simple-Java-NlogN-solution" rel="noopener noreferrer"&gt;Solution&lt;/a&gt; from leetcode username: &lt;em&gt;titasdatta93&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Time Complexity: O(nlogn) Space Complexity: O(n)

class Solution {
    public int minMeetingRooms(int[][] intervals) {
        //First sort the intervals in asc. order of starting time

        //TC: Of the below step : O(nlogn)
        Arrays.sort(
            intervals, 
            (Comparator&amp;lt;int[]&amp;gt;) (o1, o2) -&amp;gt; (o1[0] - o2[0])
        );

        //Create priority queue to store ending times of each interval
        PriorityQueue&amp;lt;Integer&amp;gt; queue = new PriorityQueue&amp;lt;&amp;gt;();

        //Add the ending time of first sorted interval
        queue.offer(intervals[0][1]);

        for(int i=1; i&amp;lt;intervals.length; i++) {
            if(intervals[i][0] &amp;gt;= queue.peek()) {
                queue.poll(); //Poll from min heap happens in O(n) time
            }

            queue.offer(intervals[i][1]);
        }     //hence total time complexity here is O(logn) 

        return queue.size();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>java</category>
      <category>coding</category>
      <category>leetcode</category>
      <category>datastructure</category>
    </item>
  </channel>
</rss>
