<?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: Mohith</title>
    <description>The latest articles on DEV Community by Mohith (@mohith_001).</description>
    <link>https://dev.to/mohith_001</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%2F3831915%2F09452fc4-bef1-42d4-8012-8f4a5eae098b.jpg</url>
      <title>DEV Community: Mohith</title>
      <link>https://dev.to/mohith_001</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohith_001"/>
    <language>en</language>
    <item>
      <title>Atomicity</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Mon, 30 Mar 2026 01:10:21 +0000</pubDate>
      <link>https://dev.to/mohith_001/atomicity-39cp</link>
      <guid>https://dev.to/mohith_001/atomicity-39cp</guid>
      <description>&lt;p&gt;Atomicity means a transaction is treated as one complete action, not as separate steps. All operations inside the transaction must succeed together. If any step fails, the entire transaction is cancelled, and the database returns to its original state. This prevents partial updates and keeps the data consistent.&lt;/p&gt;

&lt;p&gt;A simple real-world example is a wallet transfer. When I transfer money, I expect it to behave as one single action. Either the full amount is deducted from the sender and added to the receiver, or nothing happens at all. If something fails in the middle, the system rolls everything back so no money is lost and no partial update occurs.&lt;/p&gt;

&lt;p&gt;BEGIN;&lt;/p&gt;

&lt;p&gt;-- Deduct money from Alice&lt;br&gt;
UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;-- Intentional error (Charlie does not exist)&lt;br&gt;
UPDATE accounts&lt;br&gt;
SET balance = balance + 200&lt;br&gt;
WHERE name = 'Charlie';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;In this case, the second update fails because the user Charlie does not exist. Since one step in the transaction fails, the entire transaction is cancelled. The database performs a rollback, and the commit does not take effect.&lt;/p&gt;

&lt;p&gt;ROLLBACK;&lt;/p&gt;

&lt;p&gt;After the rollback, Alice’s balance remains unchanged, and no partial deduction occurs. This behavior demonstrates Atomicity — either all operations succeed, or none of them are applied.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>sql practice — filtering movies</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Sun, 29 Mar 2026 08:38:57 +0000</pubDate>
      <link>https://dev.to/mohith_001/sql-practice-filtering-movies-53mm</link>
      <guid>https://dev.to/mohith_001/sql-practice-filtering-movies-53mm</guid>
      <description>&lt;h3&gt;
  
  
  1. find all movies where special features is null
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;special_features&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. find movies with rental duration more than 7 days
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;rental_duration&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. movies with rental rate 4.99 and replacement cost &amp;gt; 20
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;replacement_cost&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. movies with rental rate 0.99 or rating pg-13
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'pg-13'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. first 5 rows sorted alphabetically by title
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt; &lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. skip first 10 rows and fetch next 3 highest replacement cost
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;replacement_cost&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt; &lt;span class="k"&gt;offset&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7. movies with rating g, pg, pg-13
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'g'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'pg'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'pg-13'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8. movies with rental rate between 2 and 4
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="k"&gt;between&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9. movies with titles starting with "the"
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;like&lt;/span&gt; &lt;span class="s1"&gt;'the%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  10. first 10 movies rate 2.99 or 4.99, rating r, title contains love
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'r'&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ilike&lt;/span&gt; &lt;span class="s1"&gt;'%love%'&lt;/span&gt; &lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  11. movies where title contains % symbol
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;like&lt;/span&gt; &lt;span class="s1"&gt;'%&lt;/span&gt;&lt;span class="se"&gt;\%&lt;/span&gt;&lt;span class="s1"&gt;%'&lt;/span&gt; &lt;span class="k"&gt;escape&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s1"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  12. movies where title contains underscore
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;like&lt;/span&gt; &lt;span class="s1"&gt;'%&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s1"&gt;%'&lt;/span&gt; &lt;span class="k"&gt;escape&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s1"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  13. titles start with a or b and end with s
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;like&lt;/span&gt; &lt;span class="s1"&gt;'a%s'&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;like&lt;/span&gt; &lt;span class="s1"&gt;'b%s'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  14. title contains man, men, or woman
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ilike&lt;/span&gt; &lt;span class="s1"&gt;'%man%'&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ilike&lt;/span&gt; &lt;span class="s1"&gt;'%men%'&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ilike&lt;/span&gt; &lt;span class="s1"&gt;'%woman%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  15. titles containing digits
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="s1"&gt;'[0-9]'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  16. titles containing backslash
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;like&lt;/span&gt; &lt;span class="s1"&gt;'%&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  17. titles contain love or hate
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ilike&lt;/span&gt; &lt;span class="s1"&gt;'%love%'&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ilike&lt;/span&gt; &lt;span class="s1"&gt;'%hate%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  18. first 5 titles ending with er, or, ar
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ilike&lt;/span&gt; &lt;span class="s1"&gt;'%er'&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ilike&lt;/span&gt; &lt;span class="s1"&gt;'%or'&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ilike&lt;/span&gt; &lt;span class="s1"&gt;'%ar'&lt;/span&gt; &lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Launch a Simple EC2 Instance, Run a Web Server &amp; Access It from the Internet - CA28</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Sun, 29 Mar 2026 07:34:43 +0000</pubDate>
      <link>https://dev.to/mohith_001/launch-a-simple-ec2-instance-run-a-web-server-access-it-from-the-internet-ca28-3gaf</link>
      <guid>https://dev.to/mohith_001/launch-a-simple-ec2-instance-run-a-web-server-access-it-from-the-internet-ca28-3gaf</guid>
      <description>&lt;p&gt;one of the first things you should try is launching an EC2 instance and hosting a simple website. In this guide, we'll create an EC2 instance, install a web server, and access it from the public internet.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 1 — Launch EC2 Instance
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Go to AWS Console&lt;/li&gt;
&lt;li&gt;Open &lt;strong&gt;EC2 Dashboard&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Launch Instance&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Configure:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My-Web-Server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AMI&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Amazon Linux 2023
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Instance type&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t2.micro (Free tier)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fbr4l8ffo11dprco81cf5.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%2Fbr4l8ffo11dprco81cf5.png" alt=" " width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 2 — Configure Security Group
&lt;/h1&gt;

&lt;p&gt;Allow SSH and HTTP traffic:&lt;br&gt;
type - ssh &amp;amp; http is in port 22 &amp;amp; 88  sorce is my ip and anywhere &lt;/p&gt;

&lt;p&gt;This allows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SSH login&lt;/li&gt;
&lt;li&gt;Public web access&lt;/li&gt;
&lt;/ul&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%2Fr1cw0v6cag9ixn6dhitc.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%2Fr1cw0v6cag9ixn6dhitc.png" alt=" " width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Step 3 — Connect to EC2
&lt;/h1&gt;

&lt;p&gt;Use EC2 Instance Connect web browser on console :&lt;/p&gt;

&lt;p&gt;throught the above connect option present in it &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%2Fa673gq6wgdp8b9p2059f.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%2Fa673gq6wgdp8b9p2059f.png" alt=" " width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Step 4 — Install Apache Web Server
&lt;/h1&gt;

&lt;p&gt;Update packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;yum update &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install Apache&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;yum &lt;span class="nb"&gt;install &lt;/span&gt;httpd &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start httpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enable auto start&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;httpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fda06r4iduv78qek1p3z7.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%2Fda06r4iduv78qek1p3z7.png" alt=" " width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 5 — Create Simple Website
&lt;/h1&gt;

&lt;p&gt;Create index file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /var/www/html/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter the html code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My EC2 Website&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello from EC2 &lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;My HTML is working!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save and exit.&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%2F4q4lcojt8ecp2q633p1z.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%2F4q4lcojt8ecp2q633p1z.png" alt=" " width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 6 — Access Website from Internet
&lt;/h1&gt;

&lt;p&gt;Copy &lt;strong&gt;Public IPv4 address&lt;/strong&gt;&lt;br&gt;
Open in browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://your-public-ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://13.60.156.82
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello from EC2 
My first AWS hosted website
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fq9wt9kuec4klozwit2a1.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%2Fq9wt9kuec4klozwit2a1.png" alt=" " width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Architecture
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Browser → Internet → EC2 Public IP → Apache → HTML Page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Common Issue (IMPORTANT)
&lt;/h1&gt;

&lt;p&gt;If website not loading:&lt;br&gt;
Check Security Group:&lt;br&gt;
Wrong:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP 80 → 0.0.0.0/32 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP 80 → 0.0.0.0/0 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows internet access.&lt;/p&gt;

&lt;h1&gt;
  
  
  Useful Commands
&lt;/h1&gt;

&lt;p&gt;Check server status&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status httpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart httpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stop server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl stop httpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  What i Learned from this is
&lt;/h1&gt;

&lt;p&gt;✅ Launch EC2 instance&lt;br&gt;
✅ Configure security group&lt;br&gt;
✅ Install Apache web server&lt;br&gt;
✅ Deploy HTML page&lt;br&gt;
✅ Access from internet&lt;/p&gt;

</description>
      <category>aws</category>
      <category>beginners</category>
      <category>cloud</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>CA 31 - Select Queries from DVD Rental database</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Sat, 28 Mar 2026 19:05:21 +0000</pubDate>
      <link>https://dev.to/mohith_001/ca-31-select-queries-from-dvd-rental-database-1a70</link>
      <guid>https://dev.to/mohith_001/ca-31-select-queries-from-dvd-rental-database-1a70</guid>
      <description>&lt;h1&gt;
  
  
  SQL SELECT Practice Queries
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Retrieve film titles and rental rates with aliases
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;"movie title"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;rental_rates&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;"rate"&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. List customer names and email with aliases
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;"first name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;"last name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Films sorted by rental rate desc, then title asc
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="n"&gt;dsc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Actor names sorted by last name then first name
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;actor&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Unique replacement costs
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;distinct&lt;/span&gt; &lt;span class="n"&gt;replacement_cost&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Film title and duration
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;length&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;"duration(min)"&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Customer active status with alias
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;last_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;"is active"&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Film categories alphabetically
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. Films sorted by length descending
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;length&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="k"&gt;length&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  10. Actors sorted by first name descending
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;actor&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  11. Unique ratings
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;distinct&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  12. Unique rental duration
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;distinct&lt;/span&gt; &lt;span class="n"&gt;rental_duration&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  13. Unique customer id based on active status
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;distinct&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  14. Earliest rental date for each customer
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rental_date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;rental_date&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rental&lt;/span&gt; &lt;span class="k"&gt;group&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  15. list 10 shortest films
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;length&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="k"&gt;length&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt; &lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  16. Top 5 customers with highest id
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt; &lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  17. Unique store ids
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;distinct&lt;/span&gt; &lt;span class="n"&gt;store_id&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  18. Unique replacement cost sorted
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;distinct&lt;/span&gt; &lt;span class="n"&gt;replacement_cost&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;replacement_cost&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  19. First rental date for each store
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;store_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rental_date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;rental_date&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rental&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;join&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inventory_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inventory_id&lt;/span&gt; &lt;span class="k"&gt;group&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;store_id&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;store_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  20. Unique ratings sorted
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;distinct&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;filmorder&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  21. Films sorted by rating asc and length desc
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;length&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;length&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  22. Actors sorted by last name asc, first name desc
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;actor&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  23. Films by replacement cost asc and rental rate desc
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;replacement_cost&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;replacement_cost&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  24. Customers sorted by last name asc and first name desc
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  25. Rentals sorted by customer and date
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rental&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rental_date&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  26. Films by rental duration and title
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rental_duration&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;rental_duration&lt;/span&gt; &lt;span class="k"&gt;asc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>CA 30 - Basic Select SQL Querie</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Sat, 28 Mar 2026 18:46:58 +0000</pubDate>
      <link>https://dev.to/mohith_001/ca-30-basic-select-sql-querie-123</link>
      <guid>https://dev.to/mohith_001/ca-30-basic-select-sql-querie-123</guid>
      <description>&lt;h2&gt;
  
  
  basic hackerank problems sql queries
&lt;/h2&gt;

&lt;p&gt;When you're starting with SQL, the &lt;strong&gt;SELECT&lt;/strong&gt; statement is the most important command. It allows you to retrieve data from database tables using different conditions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;FROM&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;WHERE&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;COUNT(column)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;COUNT(DISTINCT column)&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LEFT(column, n)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Query all columns for a city in CITY with the ID 1661
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1661&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Query all American cities with population larger than 100000
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;COUNTRYCODE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'USA'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;POPULATION&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;100000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Query all attributes of every Japanese city
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;COUNTRYCODE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'JPN'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Difference between total CITY entries and distinct CITY entries
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CITY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;DISTINCT&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;STATION&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Query NAME of American cities with population larger than 120000
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;NAME&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;COUNTRYCODE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'USA'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;POPULATION&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;120000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Query names of all Japanese cities
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;NAME&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;COUNTRYCODE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'JPN'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. List CITY names that do not start with vowels (no duplicates)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;DISTINCT&lt;/span&gt; &lt;span class="n"&gt;CITYFROM&lt;/span&gt; &lt;span class="n"&gt;STATION&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;LEFT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CITY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'A'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'E'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'I'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'O'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'U'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Query all columns from CITY table
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. Query CITY and STATE from STATION table
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;STATE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;STATION&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>How a Request Travels from Client to Server</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Sat, 28 Mar 2026 18:35:02 +0000</pubDate>
      <link>https://dev.to/mohith_001/how-a-request-travels-from-client-to-server-2e2a</link>
      <guid>https://dev.to/mohith_001/how-a-request-travels-from-client-to-server-2e2a</guid>
      <description>&lt;h1&gt;
  
  
  my thought process for request travels from the client to server is
&lt;/h1&gt;

&lt;p&gt;We use the internet every day — scrolling, clicking, searching — but we rarely think about what actually happens behind that one simple action. Let’s say you type &lt;strong&gt;google.com&lt;/strong&gt; or click a button on a website. That small action silently starts a full journey across the internet.&lt;/p&gt;

&lt;p&gt;It all begins with your device, also called the &lt;strong&gt;client&lt;/strong&gt;. The moment you enter a URL, your system doesn’t immediately know where to go. Computers don’t understand domain names — they understand &lt;strong&gt;IP addresses&lt;/strong&gt;. So your device reaches out to &lt;strong&gt;DNS (Domain Name System)&lt;/strong&gt; to translate that human-readable name into an IP address. You can think of DNS like a contact list — it converts names into numbers.&lt;/p&gt;

&lt;p&gt;Once the IP address is found, your browser prepares an &lt;strong&gt;HTTP request&lt;/strong&gt;. This request includes things like the method (GET, POST), headers, and some metadata describing what you're asking for. Before sending it, the request goes through the &lt;strong&gt;TCP/IP protocol stack&lt;/strong&gt;, where a connection is established using the &lt;strong&gt;TCP three-way handshake&lt;/strong&gt; to make sure communication is reliable.&lt;/p&gt;

&lt;p&gt;Now the interesting part — the request is broken into smaller pieces called &lt;strong&gt;packets&lt;/strong&gt;. These packets travel across multiple networks, routers, and systems using &lt;strong&gt;IP routing&lt;/strong&gt;. Each router along the way decides the best path for the packets, similar to how maps choose the fastest route.&lt;/p&gt;

&lt;p&gt;these packets reach the &lt;strong&gt;server&lt;/strong&gt;. The server reassembles them, understands the request, and processes it. This may involve fetching data from a database, running backend logic, or simply returning a static webpage.Once the processing is done, the server sends back an &lt;strong&gt;HTTP response&lt;/strong&gt; — again in packets. These packets travel all the way back to your device, where they are reassembled, and your browser finally renders the content on your screen.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>networking</category>
      <category>webdev</category>
    </item>
    <item>
      <title>how DNS resolver is happening - CA27</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Sat, 28 Mar 2026 18:25:30 +0000</pubDate>
      <link>https://dev.to/mohith_001/how-a-request-originates-from-cllient-and-reaches-the-server-ca26-4g1m</link>
      <guid>https://dev.to/mohith_001/how-a-request-originates-from-cllient-and-reaches-the-server-ca26-4g1m</guid>
      <description>&lt;p&gt;actual my thoght process for the how DNS resolver is happening Every time you type something like &lt;strong&gt;google.com&lt;/strong&gt; in your browser, your device has one simple goal — find the IP address of that website so it can connect to the server. This whole process is called &lt;strong&gt;DNS resolution&lt;/strong&gt;, and even though it sounds complicated, it actually happens in milliseconds behind the scenes.&lt;/p&gt;

&lt;p&gt;It starts from your device (the client). Before asking anyone else, your system first checks locally. That means it looks into the &lt;strong&gt;browser cache&lt;/strong&gt;, &lt;strong&gt;operating system cache&lt;/strong&gt;, and sometimes even the &lt;strong&gt;hosts file&lt;/strong&gt; to see if the IP address is already known. If it finds it, then it can directly use it and skip the rest. If not, it sends a request to a &lt;strong&gt;DNS resolver&lt;/strong&gt;, which is usually provided by your ISP or a public DNS service.&lt;/p&gt;

&lt;p&gt;Now the resolver does the main work. It doesn’t directly know the IP address, so it starts asking step by step. First, it contacts a &lt;strong&gt;root name server&lt;/strong&gt;. The root server doesn’t give the IP, but it tells where to find the &lt;strong&gt;TLD server&lt;/strong&gt; (like .com, .org, .net). Then the resolver asks the TLD server. The TLD server responds with the address of the &lt;strong&gt;authoritative DNS server&lt;/strong&gt; for that domain. Finally, the resolver queries the authoritative server, and this server returns the actual IP address of the website.&lt;/p&gt;

&lt;p&gt;Once the resolver gets the IP address, it sends it back to your device and also stores it in cache so next time it’s faster. Now your browser finally has the IP address. Using that, it creates a connection (TCP/IP) and sends an HTTP request to the server to get the website content.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>IP address and Subnet - CA25</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Sat, 28 Mar 2026 18:14:43 +0000</pubDate>
      <link>https://dev.to/mohith_001/ip-address-and-subnet-ca25-3abd</link>
      <guid>https://dev.to/mohith_001/ip-address-and-subnet-ca25-3abd</guid>
      <description>&lt;p&gt;&lt;strong&gt;what i have been understand throught this session&lt;/strong&gt;&lt;br&gt;
When you open a website, your computer communicates with another computer on the internet.&lt;br&gt;
This communication happens using &lt;strong&gt;IP addresses&lt;/strong&gt; and &lt;strong&gt;subnets&lt;/strong&gt;.&lt;br&gt;
what i have been learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is an IP Address&lt;/li&gt;
&lt;li&gt;Types of IP Address&lt;/li&gt;
&lt;li&gt;What is Subnet&lt;/li&gt;
&lt;li&gt;Why Subnet is used
*Real-world example&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  as per mythought process What is an IP Address?
&lt;/h1&gt;

&lt;p&gt;An &lt;strong&gt;IP address&lt;/strong&gt; is a unique identifier assigned to each device on a network.the ip address will be divide into parts 8bits-8bits-8bits-8bits which is totally 32bits.actually every ip is will be in two different types of port which is network port and host port the first 24bits will be network port and last remaining is the host port the cidr will works thought the process of workflow &lt;br&gt;
you can ask what is cidr calculator ?? &lt;br&gt;
which is used to set the count,first usable ip,netmask,cidr base ip,broadcast ip by using this which is used to be calculated  &lt;/p&gt;

&lt;h3&gt;
  
  
  Example IP addresses
&lt;/h3&gt;

&lt;p&gt;Just like our home address helps people find your house,&lt;br&gt;
an IP address helps computers find each other on the internet.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;192.168.1.1&lt;/li&gt;
&lt;li&gt;8.8.8.8&lt;/li&gt;
&lt;li&gt;172.16.0.1&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  There are some Types of IP Address
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Public IP Address
&lt;/h2&gt;

&lt;p&gt;Used on the internet and assigned by ISP(internet acces protocol)&lt;br&gt;
Example:&lt;br&gt;
8.8.8.8&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Private IP Address
&lt;/h2&gt;

&lt;p&gt;Used inside local networks (WiFi, office, home).&lt;br&gt;
Example ranges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;192.168.x.x&lt;/li&gt;
&lt;li&gt;10.x.x.x&lt;/li&gt;
&lt;li&gt;172.16.x.x&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  What is Subnet?
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;Subnet&lt;/strong&gt; means dividing a large network into smaller networks.&lt;br&gt;
Subnet = Sub Network&lt;br&gt;
Subnet helps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduce network traffic&lt;/li&gt;
&lt;li&gt;Improve performance&lt;/li&gt;
&lt;li&gt;Increase security&lt;/li&gt;
&lt;li&gt;Better network &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Example Without Subnet
&lt;/h1&gt;

&lt;p&gt;All devices in one network:&lt;br&gt;
192.168.1.1&lt;br&gt;
192.168.1.2&lt;br&gt;
192.168.1.3&lt;br&gt;
192.168.1.254&lt;/p&gt;

&lt;p&gt;This creates heavy traffic.&lt;/p&gt;

&lt;h1&gt;
  
  
  some Example With Subnet
&lt;/h1&gt;

&lt;p&gt;Subnet 1&lt;br&gt;
192.168.1.1 – 192.168.1.50&lt;br&gt;
Subnet 2&lt;br&gt;
192.168.1.51 – 192.168.1.100&lt;br&gt;
Subnet 3&lt;br&gt;
192.168.1.101 – 192.168.1.150&lt;br&gt;
Now network is faster and organized.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Subnet Mask?
&lt;/h1&gt;

&lt;p&gt;Subnet mask defines network and host portion.&lt;br&gt;
Example:&lt;br&gt;
IP Address: 192.168.1.10&lt;br&gt;
Subnet Mask: 255.255.255.0&lt;br&gt;
Network part → 192.168.1&lt;br&gt;
Host part → 10&lt;/p&gt;

&lt;h1&gt;
  
  
  how in Real World works
&lt;/h1&gt;

&lt;p&gt;Network → Building&lt;br&gt;
Subnet → Floor&lt;br&gt;
IP Address → Room number&lt;br&gt;
Example:&lt;br&gt;
Building A&lt;br&gt;
Floor 1 → Subnet&lt;br&gt;
Room 101 → IP Address&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;IP Address identifies devices&lt;/li&gt;
&lt;li&gt;Subnet divides networks&lt;/li&gt;
&lt;li&gt;Subnet improves performance and security&lt;/li&gt;
&lt;li&gt;Subnet mask defines network range&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>CA 03 - Number Guessing Game</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Sun, 22 Mar 2026 18:58:55 +0000</pubDate>
      <link>https://dev.to/mohith_001/ca-03-number-guessing-game-f6h</link>
      <guid>https://dev.to/mohith_001/ca-03-number-guessing-game-f6h</guid>
      <description>&lt;h1&gt;
  
  
  From Number Guessing Game to System Design Concepts
&lt;/h1&gt;

&lt;p&gt;this session, we started by building a simple &lt;strong&gt;Number Guessing Game&lt;/strong&gt;, but the discussion slowly moved into &lt;strong&gt;system design concepts&lt;/strong&gt; like  locking, database design, randomness, and security. The idea was to not just build a game, but to understand how similar concepts apply in real-world systems.&lt;/p&gt;

&lt;p&gt;Before this, we already discussed a &lt;strong&gt;ticket booking system&lt;/strong&gt;, where multiple users try to book the same seat at the same time. &lt;/p&gt;




&lt;h1&gt;
  
  
  Ticket Booking System Problem
&lt;/h1&gt;

&lt;p&gt;Consider two users trying to book the same seat.&lt;/p&gt;

&lt;p&gt;User A selects seat 1&lt;br&gt;
User B selects seat 1 at the same time&lt;/p&gt;

&lt;p&gt;Both users see the seat as available and both attempt to book it.&lt;br&gt;
This creates a race condition and leads to duplicate booking.&lt;/p&gt;

&lt;p&gt;This happens because there is no locking mechanism.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Locking is Needed
&lt;/h1&gt;

&lt;p&gt;To prevent this issue, we introduce locking.&lt;/p&gt;

&lt;p&gt;When User A selects a seat:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The seat gets locked&lt;/li&gt;
&lt;li&gt;User B cannot access it&lt;/li&gt;
&lt;li&gt;User A proceeds to payment&lt;/li&gt;
&lt;li&gt;If payment completes, seat becomes booked&lt;/li&gt;
&lt;li&gt;If payment times out, lock is released&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This ensures only one user can access the seat at a time and maintains data consistency.&lt;/p&gt;




&lt;h1&gt;
  
  
  Types of Locking
&lt;/h1&gt;

&lt;p&gt;Two types of locking were discussed.&lt;/p&gt;

&lt;p&gt;Optimistic Locking&lt;br&gt;
Assumes conflicts are rare. Multiple users can read data, and conflict is checked only when updating.&lt;/p&gt;

&lt;p&gt;Pessimistic Locking&lt;br&gt;
Locks the resource immediately. Other users cannot access it. This is safer and commonly used in booking systems.&lt;/p&gt;




&lt;h1&gt;
  
  
  Database Tables for Ticket Booking
&lt;/h1&gt;

&lt;p&gt;Two tables are required.&lt;/p&gt;

&lt;p&gt;Movies table stores:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;movie name&lt;/li&gt;
&lt;li&gt;show time&lt;/li&gt;
&lt;li&gt;release date&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Seats table stores:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;movie id&lt;/li&gt;
&lt;li&gt;seat number&lt;/li&gt;
&lt;li&gt;status&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Seat status is "available" by default.&lt;/p&gt;

&lt;p&gt;Before booking begins, movie and seat details are inserted into these tables.&lt;/p&gt;




&lt;h1&gt;
  
  
  Booking Flow with Concurrency
&lt;/h1&gt;

&lt;p&gt;User selects seat&lt;br&gt;
Seat gets temporarily locked&lt;br&gt;
User proceeds to payment&lt;br&gt;
Lock held for limited time (example: 7 minutes)&lt;br&gt;
If payment success → seat booked&lt;br&gt;
If timeout → lock released&lt;/p&gt;

&lt;p&gt;Without locking, multiple users can book the same seat.&lt;/p&gt;

&lt;p&gt;Isolation levels help but do not fully solve concurrency issues.&lt;/p&gt;




&lt;h1&gt;
  
  
  Row Level Locking Example
&lt;/h1&gt;

&lt;p&gt;Seat 1 is available&lt;/p&gt;

&lt;p&gt;User A selects seat 1&lt;br&gt;
Seat 1 becomes locked&lt;/p&gt;

&lt;p&gt;User B tries to select seat 1&lt;br&gt;
User B is blocked&lt;/p&gt;

&lt;p&gt;Only when lock is released, seat becomes available again.&lt;/p&gt;

&lt;p&gt;This demonstrates row level locking.&lt;/p&gt;




&lt;h1&gt;
  
  
  Number Guessing Game Design
&lt;/h1&gt;

&lt;p&gt;After discussing concurrency, we moved to building a &lt;strong&gt;Number Guessing Game&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Two players try to guess a secret number within a range.&lt;br&gt;
The goal is to guess the number with minimum attempts.&lt;/p&gt;

&lt;p&gt;Difficulty levels define:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;range of numbers&lt;/li&gt;
&lt;li&gt;number of attempts&lt;/li&gt;
&lt;li&gt;score&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Easy → 1 to 20&lt;br&gt;
Medium → 1 to 50&lt;br&gt;
Hard → 1 to 100&lt;/p&gt;

&lt;p&gt;Leaderboard stores attempts and scores.&lt;/p&gt;




&lt;h1&gt;
  
  
  Game Flow
&lt;/h1&gt;

&lt;p&gt;Start with greeting message&lt;br&gt;
Show difficulty selection menu&lt;br&gt;
User selects difficulty&lt;br&gt;
Generate random number&lt;br&gt;
User guesses number&lt;br&gt;
System gives hint (higher / lower)&lt;br&gt;
Track attempts&lt;br&gt;
Store score in leaderboard&lt;/p&gt;




&lt;h1&gt;
  
  
  Random Number Generation
&lt;/h1&gt;

&lt;p&gt;Computers do not generate truly random numbers.&lt;br&gt;
They generate pseudo-random numbers using algorithms.&lt;/p&gt;

&lt;p&gt;Random numbers depend on a seed value.&lt;br&gt;
If the seed is same, the sequence will also be same.&lt;br&gt;
Usually, system time is used as seed.&lt;/p&gt;

&lt;p&gt;Different systems may produce different sequences.&lt;/p&gt;

&lt;p&gt;So randomness is algorithm-based, not truly random.&lt;/p&gt;




&lt;h1&gt;
  
  
  Handling User Input
&lt;/h1&gt;

&lt;p&gt;User input must be validated properly.&lt;/p&gt;

&lt;p&gt;Difficulty input may come as string&lt;br&gt;
Convert string to integer&lt;br&gt;
Validate range&lt;br&gt;
Handle invalid input&lt;/p&gt;

&lt;p&gt;Functions return:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;int&lt;/li&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;boolean&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Proper type conversion avoids runtime errors.&lt;/p&gt;




&lt;h1&gt;
  
  
  Leaderboard Design
&lt;/h1&gt;

&lt;p&gt;Leaderboard data stored in database.&lt;/p&gt;

&lt;p&gt;It contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;username&lt;/li&gt;
&lt;li&gt;difficulty&lt;/li&gt;
&lt;li&gt;attempts&lt;/li&gt;
&lt;li&gt;score&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Operations include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;inserting score&lt;/li&gt;
&lt;li&gt;fetching leaderboard&lt;/li&gt;
&lt;li&gt;sorting by attempts&lt;/li&gt;
&lt;li&gt;filtering by difficulty&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Efficient queries and indexing improve performance.&lt;/p&gt;




&lt;h1&gt;
  
  
  System Design Takeaways
&lt;/h1&gt;

&lt;p&gt;Concurrency handling is important&lt;br&gt;
Locking prevents race conditions&lt;br&gt;
Row level locking improves safety&lt;br&gt;
Timeout based locking avoids deadlocks&lt;br&gt;
Leaderboard stored in database&lt;br&gt;
Efficient queries reduce load&lt;br&gt;
Indexing improves performance&lt;/p&gt;

&lt;p&gt;These concepts apply to real systems like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ticket booking&lt;/li&gt;
&lt;li&gt;ride booking&lt;/li&gt;
&lt;li&gt;hotel booking&lt;/li&gt;
&lt;li&gt;food delivery&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Security and Network
&lt;/h1&gt;

&lt;p&gt;Communication happens over HTTPS.&lt;/p&gt;

&lt;p&gt;Security includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TLS encryption&lt;/li&gt;
&lt;li&gt;public/private key pairs&lt;/li&gt;
&lt;li&gt;encrypted data transfer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This prevents middleman attacks and ensures secure communication.&lt;/p&gt;

&lt;p&gt;This is important for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;payments&lt;/li&gt;
&lt;li&gt;authentication&lt;/li&gt;
&lt;li&gt;booking systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;In this session, we learned:&lt;/p&gt;

&lt;p&gt;Concurrency issues in booking systems&lt;br&gt;
Optimistic vs pessimistic locking&lt;br&gt;
Database table design&lt;br&gt;
Row level locking&lt;br&gt;
Number guessing game design&lt;br&gt;
Random number generation&lt;br&gt;
Input validation and type casting&lt;br&gt;
Leaderboard system design&lt;br&gt;
Security basics using HTTPS&lt;/p&gt;

&lt;p&gt;This session showed how even a simple &lt;strong&gt;Number Guessing Game&lt;/strong&gt; can help understand &lt;strong&gt;real-world system design concepts&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>database</category>
      <category>programming</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Remove Duplicates from a Sorted Linked List –CA23</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Fri, 20 Mar 2026 18:12:14 +0000</pubDate>
      <link>https://dev.to/mohith_001/remove-duplicates-from-a-sorted-linked-list-ca23-2b37</link>
      <guid>https://dev.to/mohith_001/remove-duplicates-from-a-sorted-linked-list-ca23-2b37</guid>
      <description>&lt;h1&gt;
  
  
  My Thinking and Approach
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this problem, I was given a &lt;strong&gt;sorted linked list&lt;/strong&gt; and asked to remove duplicate elements.&lt;/p&gt;

&lt;p&gt;Since the list is already sorted, duplicates will always appear next to each other. This made the problem easier to approach.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Given a sorted linked list&lt;/li&gt;
&lt;li&gt;Remove duplicate nodes&lt;/li&gt;
&lt;li&gt;Return the updated list&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  My Initial Thought
&lt;/h2&gt;

&lt;p&gt;Initially, I thought:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store elements in a set&lt;/li&gt;
&lt;li&gt;Rebuild the linked list&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But this uses extra space, which is not required here.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Observation
&lt;/h2&gt;

&lt;p&gt;Because the list is &lt;strong&gt;sorted&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Duplicate values are always adjacent&lt;/li&gt;
&lt;li&gt;So I only need to compare current node with the next node&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Optimized Approach
&lt;/h2&gt;

&lt;p&gt;I decided to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Traverse the list once&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If current node value equals next node value:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Skip the next node&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Otherwise:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Move forward&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  My Approach
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Start with &lt;code&gt;curr = head&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Traverse while &lt;code&gt;curr&lt;/code&gt; and &lt;code&gt;curr.next&lt;/code&gt; are not null&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;If &lt;code&gt;curr.data == curr.next.data&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Remove duplicate by skipping node&lt;/li&gt;
&lt;li&gt;&lt;code&gt;curr.next = curr.next.next&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Else:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Move to next node&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Code (Java)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="nf"&gt;removeDuplicates&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;curr&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;data&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;curr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Example Walkthrough
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;2 → 2 → 4 → 5&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Compare 2 and 2 → remove duplicate&lt;/li&gt;
&lt;li&gt;List becomes → &lt;code&gt;2 → 4 → 5&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;2 → 4 → 5&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Complexity Analysis
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space Complexity:&lt;/strong&gt; O(1)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Sorted property simplifies the problem&lt;/li&gt;
&lt;li&gt;No need for extra space&lt;/li&gt;
&lt;li&gt;Pointer manipulation is important in linked lists&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This problem helped me understand how to efficiently handle duplicates in linked lists. It also reinforced the importance of using problem constraints (like sorted order) to simplify the solution.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>computerscience</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Reverse a Linked List – CA22</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Fri, 20 Mar 2026 18:09:49 +0000</pubDate>
      <link>https://dev.to/mohith_001/reverse-a-linked-list-ca22-4d0p</link>
      <guid>https://dev.to/mohith_001/reverse-a-linked-list-ca22-4d0p</guid>
      <description>&lt;h1&gt;
  
  
  My Thinking and Approach
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this problem, I was given the head of a singly linked list and asked to reverse it.&lt;/p&gt;

&lt;p&gt;At first, I thought it might be tricky because linked lists don’t allow direct indexing like arrays. But once I understood how pointers work, the solution became clear.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Given the head of a singly linked list&lt;/li&gt;
&lt;li&gt;Reverse the list&lt;/li&gt;
&lt;li&gt;Return the new head&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  My Initial Thought
&lt;/h2&gt;

&lt;p&gt;Initially, I thought:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store elements in an array&lt;/li&gt;
&lt;li&gt;Reverse the array&lt;/li&gt;
&lt;li&gt;Rebuild the linked list&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But this uses extra space and is not efficient.&lt;/p&gt;

&lt;p&gt;So I tried to solve it directly using pointers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Optimized Approach (Iterative)
&lt;/h2&gt;

&lt;p&gt;I realized that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each node points to the next node&lt;/li&gt;
&lt;li&gt;To reverse, I need to change the direction of these pointers&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  My Approach
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use three pointers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;prev&lt;/code&gt; → previous node&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;curr&lt;/code&gt; → current node&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;next&lt;/code&gt; → next node&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Steps
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Initialize:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;prev = null&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;curr = head&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Traverse the list:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Store next node → &lt;code&gt;next = curr.next&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Reverse pointer → &lt;code&gt;curr.next = prev&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Move &lt;code&gt;prev&lt;/code&gt; forward&lt;/li&gt;
&lt;li&gt;Move &lt;code&gt;curr&lt;/code&gt; forward&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;At the end:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;prev&lt;/code&gt; becomes the new head&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Code (Java)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="nf"&gt;reverseList&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;curr&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;curr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Example Walkthrough
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example 1
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;1 → 2 → 3 → 4&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Reverse 1 → null&lt;/li&gt;
&lt;li&gt;Reverse 2 → 1&lt;/li&gt;
&lt;li&gt;Reverse 3 → 2&lt;/li&gt;
&lt;li&gt;Reverse 4 → 3&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;4 → 3 → 2 → 1&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Example 2
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;2 → 7 → 10 → 9 → 8&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;8 → 9 → 10 → 7 → 2&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Complexity Analysis
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space Complexity:&lt;/strong&gt; O(1)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Linked lists require pointer manipulation&lt;/li&gt;
&lt;li&gt;Always store next node before changing links&lt;/li&gt;
&lt;li&gt;Iterative approach is simple and efficient&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This problem helped me understand how linked lists work internally. It improved my confidence in handling pointer-based problems and showed how simple logic can reverse an entire data structure efficiently.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>computerscience</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Majority Element – CA21</title>
      <dc:creator>Mohith</dc:creator>
      <pubDate>Fri, 20 Mar 2026 18:04:51 +0000</pubDate>
      <link>https://dev.to/mohith_001/majority-element-ca21-2dcd</link>
      <guid>https://dev.to/mohith_001/majority-element-ca21-2dcd</guid>
      <description>&lt;h1&gt;
  
  
  My Thinking and Approach
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this problem, I was given an array and asked to find the &lt;strong&gt;majority element&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A majority element is the one that appears &lt;strong&gt;more than n/2 times&lt;/strong&gt; in the array. If no such element exists, we need to return &lt;code&gt;-1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At first, it looked like a simple counting problem, but I learned that there is a more optimized way to solve it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Given an array &lt;code&gt;arr[]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Find the element that appears &lt;strong&gt;more than n/2 times&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;If no such element exists, return &lt;code&gt;-1&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  My Initial Approach
&lt;/h2&gt;

&lt;p&gt;Initially, I thought of using a frequency count:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a HashMap&lt;/li&gt;
&lt;li&gt;Count occurrences of each element&lt;/li&gt;
&lt;li&gt;Return the element with count &amp;gt; n/2&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Drawback
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Time Complexity: O(n)&lt;/li&gt;
&lt;li&gt;Space Complexity: O(n)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although this works, it is not the most optimal solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  Optimized Approach (Boyer-Moore Voting Algorithm)
&lt;/h2&gt;

&lt;p&gt;To improve efficiency, I used the &lt;strong&gt;Boyer-Moore Voting Algorithm&lt;/strong&gt;, which works in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Time: O(n)&lt;/li&gt;
&lt;li&gt;Space: O(1)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  My Approach
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Find Candidate
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Maintain two variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;candidate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;count&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Traverse the array:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;count == 0&lt;/code&gt;, assign current element as candidate&lt;/li&gt;
&lt;li&gt;If current element equals candidate → increment count&lt;/li&gt;
&lt;li&gt;Else → decrement count&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 2: Verify Candidate
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Count how many times the candidate appears&lt;/li&gt;
&lt;li&gt;If count &amp;gt; n/2 → return candidate&lt;/li&gt;
&lt;li&gt;Else → return &lt;code&gt;-1&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Code (Java)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;majorityElement&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;candidate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;--;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Example Walkthrough
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example 1
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;[1, 1, 2, 1, 3, 5, 1]&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Candidate becomes 1&lt;/li&gt;
&lt;li&gt;It appears more than n/2 times&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;1&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Example 2
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;[2, 13]&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No majority element exists&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;-1&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Complexity Analysis
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space Complexity:&lt;/strong&gt; O(1)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Boyer-Moore algorithm is very efficient&lt;/li&gt;
&lt;li&gt;Always verify the candidate&lt;/li&gt;
&lt;li&gt;Helps reduce space complexity&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This problem helped me understand how to optimize a simple counting problem into a more efficient solution using the Boyer-Moore Voting Algorithm. It is a very useful concept for coding interviews and competitive programming.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>coding</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
