<?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: Ankan Bhattacharya</title>
    <description>The latest articles on DEV Community by Ankan Bhattacharya (@ankan_2025).</description>
    <link>https://dev.to/ankan_2025</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%2F730507%2Fe374ffcb-5e1e-4b29-979f-1e3e8e111708.jpeg</url>
      <title>DEV Community: Ankan Bhattacharya</title>
      <link>https://dev.to/ankan_2025</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ankan_2025"/>
    <language>en</language>
    <item>
      <title>Backend As A Service: A Beginner's Guide</title>
      <dc:creator>Ankan Bhattacharya</dc:creator>
      <pubDate>Fri, 26 May 2023 03:26:24 +0000</pubDate>
      <link>https://dev.to/ankan_2025/backend-as-a-service-a-beginners-guide-34dh</link>
      <guid>https://dev.to/ankan_2025/backend-as-a-service-a-beginners-guide-34dh</guid>
      <description>&lt;p&gt;After hearing the BaaS or Backend As A Service, the first thing that might come to your mind is "Leave BaaS, what the hack is even a backend?".&lt;/p&gt;

&lt;p&gt;So, actually to answer your question &amp;amp; keep you away from the complexities of &lt;code&gt;What is a backend?&lt;/code&gt;, actually this BaaS thing was developed. But to understand that, let's get a more in-depth look at &lt;code&gt;What is a Backend?&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Backend
&lt;/h3&gt;

&lt;p&gt;Going by the text-book backend is the place where data is processed and sanitised for a particular software. But in reality, it's much more. It contains authentication, payment systems &amp;amp; verification, image uploading, data accessing, etc. In short whenever you login to Google or search for something or maybe post an image on Instagram once you click the action button an HTTP request is sent over to a computer popularly known as cloud computer or cloud server where it processes some data and maybe stores something on the database and sends some data back that is showed to you. That might be an OK message or acknowledgement of something, etc. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5CcsVcXv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4dmbtn2h9zyyaeya1ige.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5CcsVcXv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4dmbtn2h9zyyaeya1ige.png" alt="This is the simplest representation of how a very simple app works" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
This is the simplest representation of how a very simple app architecture works.&lt;/p&gt;

&lt;h3&gt;
  
  
  What was the problem?
&lt;/h3&gt;

&lt;p&gt;Building a backend server on your own is quite a tough job because it needs features like authentication, efficient database interaction, and proper sanitised data processing and responses. Now, you can learn it and then implement it but it is always not very feasible especially if you are in a hurry of building a product or maybe you are simply a frontend developer and is much interested in the backend of things.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's the solution?
&lt;/h3&gt;

&lt;p&gt;The very simple solution can is if somebody can provide us with a service that would host the backend, databases, data processing, authentication, image buckets, rate limiting, etc that a robust and bulletproof backend should have. And simply the service that provides all these features is called a Backend As A Service (BaaS).&lt;/p&gt;

&lt;p&gt;A BaaS can integrate with any type of app like a web app or mobile app &amp;amp; provide you SDKs or APIs to communicate and interact with them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Main Features:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Seamless Integration.&lt;/li&gt;
&lt;li&gt;No proper Backend experience is required.&lt;/li&gt;
&lt;li&gt;Low Cost of maintenance.&lt;/li&gt;
&lt;li&gt;Very Efficient.&lt;/li&gt;
&lt;li&gt;Cross Platform Support.&lt;/li&gt;
&lt;li&gt;A good-looking Admin Panel.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Benefits:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Now every frontend devs can be full-stack guys who can integrate the backend right out of the box.&lt;/li&gt;
&lt;li&gt;Companies do not need to hire a dedicated backend dev for small apps or just prototypes.&lt;/li&gt;
&lt;li&gt;Highly cost-efficient as you mostly pay for what you use.&lt;/li&gt;
&lt;li&gt;Also you need not maintain your own infrastructure.&lt;/li&gt;
&lt;li&gt;The code that runs behind these services is highly efficient, reliable and secure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Some downsides:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Not very good for very complex projects where you have a ton of Microservices along with some messaging queues and various databases.&lt;/li&gt;
&lt;li&gt;Some BaaS also have a vendor lock-in system i.e., once you start using it you cannot move out &amp;amp; for complex use cases they can be really expensive. If you wanna know more about vendor lock-in you can comment down below.&lt;/li&gt;
&lt;li&gt;Database relationships like relational queries can be difficult at times.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Some very popular BaaS:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Firebase&lt;/li&gt;
&lt;li&gt;AWS Amplify&lt;/li&gt;
&lt;li&gt;Appwrite (Kinda Open Source Source alternative to Firebase but also has a hosted version currently in Beta)&lt;/li&gt;
&lt;li&gt;Supabase&lt;/li&gt;
&lt;li&gt;Pocketbase (Open Source alternative to Firebase written in Golang and powered by SQLite database).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  BONUS:
&lt;/h3&gt;

&lt;p&gt;Appwrite is organising a Hackathon. Visit &lt;a href="https://hashnode.com/hackathons/appwrite"&gt;here&lt;/a&gt; to know more. Also, I might bring some tutorials on how to use BaaS in your projects if you ask for them in the comment section.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you found something useful make sure to drop a ❤️. And 👋 for now...😃😃&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>backend</category>
      <category>baas</category>
      <category>firebase</category>
    </item>
    <item>
      <title>Majority Element (Leetcode)</title>
      <dc:creator>Ankan Bhattacharya</dc:creator>
      <pubDate>Wed, 26 Oct 2022 06:01:16 +0000</pubDate>
      <link>https://dev.to/ankan_2025/majority-element-leetcode-3g50</link>
      <guid>https://dev.to/ankan_2025/majority-element-leetcode-3g50</guid>
      <description>&lt;h3&gt;
  
  
  Problem Statement
&lt;/h3&gt;

&lt;p&gt;Given an array &lt;code&gt;nums&lt;/code&gt; of size &lt;code&gt;n&lt;/code&gt;, return the majority element.&lt;/p&gt;

&lt;p&gt;The majority element is the element that appears more than &lt;code&gt;⌊n / 2⌋&lt;/code&gt; times. You may assume that the majority element always exists in the array.&lt;/p&gt;

&lt;h3&gt;
  
  
  Approach
&lt;/h3&gt;

&lt;p&gt;The problem statement states that we need to find the majority element or the element that has the highest frequency in the array. But also the frequency of that element needs to be more than the half of the length of the array.&lt;/p&gt;

&lt;p&gt;Here one of the naive approaches can be using a hashmap. Just store the frequencies in a key value pair format, and then loop over the hash map &amp;amp; detect the most frequent element. This approach would give a time complexity of &lt;code&gt;O(n)&lt;/code&gt; and a space complexity of &lt;code&gt;O(n)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here kicks in a better algorithm popularly known as &lt;code&gt;Boyre-Moore's Voting Algorithm&lt;/code&gt;. The algorithm states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First take a candidate element and initiate a count as well.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now the next step is to loop over the array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;While looping if the element is equal to the candidate, we increment the count by one, else we decrement the count by one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And if at any point the count reaches 0, then we update the candidate with the current element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally at the end if we want to verify, then we can count the frequency of the final candidate and check if its frequency is more than the 1/2 the length of the array.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Time Complexity of this approach is &lt;code&gt;O(n)&lt;/code&gt; but the space complexity is &lt;code&gt;O(1)&lt;/code&gt; which is quite an improvement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Intuition
&lt;/h3&gt;

&lt;p&gt;First let's consider an array:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[3, 3, 3, 2, 2]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now if we start counting the elements then at the end we would be having candidate as 3 and the count as 1. This proves that if there is a majority element then at the end one element with count at least one would definitely remain as the final result as the number of that majority element is greater than half the length of the array.&lt;/p&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;majorityElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;[]):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;candidate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;currentCount&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="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&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="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

        &lt;span class="c1"&gt;// * According to moore's algorithm if value at current position is equivalent to candidate, we increment the currentCount&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;candidate&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]){&lt;/span&gt;
            &lt;span class="nx"&gt;currentCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="c1"&gt;//  * According to moore's algorithm if value at current position is not equivalent to candidate, we decrement the currentCount&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;currentCount&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// * If the currentCount is equal to 0 we update the candidate as the number at current position also we increment the currentCount&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentCount&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="nx"&gt;candidate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
            &lt;span class="nx"&gt;currentCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// * NOTE: According to Moore's algo, if the currentCount is less than or equal to zero, we can conclude that no majority element exists in the array.&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;candidateCount&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="c1"&gt;// * We just verify here that the count of the selected candidate is actually greater than half of length of the array.&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;candidateCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;candidateCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&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;return&lt;/span&gt; &lt;span class="nx"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Result
&lt;/h3&gt;

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

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;If you have gained or learned anything from the above given explanation do not forget to give a like ❤️ to the post. Follow me for more such posts and also my social handles are given in my profile, reach me out there.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>dsa</category>
      <category>typescript</category>
      <category>coding</category>
    </item>
    <item>
      <title>Square Root of A Non-Negative Integer (Leetcode)</title>
      <dc:creator>Ankan Bhattacharya</dc:creator>
      <pubDate>Wed, 26 Oct 2022 04:48:30 +0000</pubDate>
      <link>https://dev.to/ankan_2025/square-root-of-a-non-negative-integer-leetcode-196o</link>
      <guid>https://dev.to/ankan_2025/square-root-of-a-non-negative-integer-leetcode-196o</guid>
      <description>&lt;h3&gt;
  
  
  Problem Statement
&lt;/h3&gt;

&lt;p&gt;Given a non-negative integer x, compute and return the square root of x.&lt;/p&gt;

&lt;p&gt;Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Note: You are not allowed to use any built-in exponent function or operator, such as pow(x, 0.5) or x ** 0.5.&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Approach
&lt;/h3&gt;

&lt;p&gt;First of all the problem statement says we need to find the square root of a number in an integer format without using a built in function like &lt;code&gt;sqrt()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So, if we think a bit intuitively, we can deduce that square of a number cannot be more than half of that integer. &lt;/p&gt;

&lt;p&gt;Now as we know the above given fact, one of the approaches would be iterating over each and every number from 1 till &lt;code&gt;ceil(number / 2)&lt;/code&gt;. And finding out the num whose square is nearest, yet not more than the given number. This approach would have a time complexity of &lt;code&gt;O(n)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But we might just have a better approach than this using an algorithm popularly known as binary search.&lt;/p&gt;

&lt;p&gt;Steps of solving the problem using binary search:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First of all if the passed number is lower than 0 then return -1, else if its less than or equal to 1 then return the number itself.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now take a lower bound of 1 and upper bound as 2 is the number is 2 else &lt;code&gt;ceil(number / 2)&lt;/code&gt;. Also initiate a sqrt variable with -1 that will keep the track of nearest possible square root.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After this run a util &lt;code&gt;lower bound &amp;lt;= upper bound&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now find the mid value by using a formula &lt;code&gt;mid = lb + floor((ub - lb) / 2)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Check if mid * mid == number and if so set sqrt to mid and break the loop.&lt;/li&gt;
&lt;li&gt;If the mid * mid &amp;lt; number, we can say that it might be the number that we were searching for so we will set sqrt to mid but we also know that we might find a bigger number whose square could be equal or closer to the given number. So we will set the &lt;code&gt;lb = mid + 1&lt;/code&gt; hence reducing our search area.&lt;/li&gt;
&lt;li&gt;Else we know that we need to find a smaller number than this and hence we make &lt;code&gt;ub = mid - 1&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Finally return the sqrt as the square root of the number.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Time complexity of the above given approach is &lt;code&gt;O(log n)&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;Here we have Typescript to implement the above given approach. But you can obviously use your own favourite language.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mySqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&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="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&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;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&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;return&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;ub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sqrt&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="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lb&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;ub&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lb&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;ub&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;lb&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;sqrt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;sqrt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;lb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nx"&gt;ub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Result
&lt;/h3&gt;

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

&lt;p&gt;If you have gained or learned anything from the above given explanation do not forget to give a like ❤️ to the post. Follow me for more such posts and also my social handles are given in my profile, reach me out there.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>dsa</category>
      <category>typescript</category>
      <category>coding</category>
    </item>
    <item>
      <title>Single Number</title>
      <dc:creator>Ankan Bhattacharya</dc:creator>
      <pubDate>Tue, 15 Feb 2022 09:46:06 +0000</pubDate>
      <link>https://dev.to/ankan_2025/single-number-5991</link>
      <guid>https://dev.to/ankan_2025/single-number-5991</guid>
      <description>&lt;p&gt;&lt;strong&gt;Problem Statement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.&lt;/p&gt;

&lt;p&gt;You must implement a solution with a linear runtime complexity and use only constant extra space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First if there are no elements in the list return None.&lt;/li&gt;
&lt;li&gt;Keep track of numbers occurring once in singleSet and multiple times in multipleSet.&lt;/li&gt;
&lt;li&gt;Now go over each element in singleSet, and return the first element in singleSet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Algorithm&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Code&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;class Solution:
    def singleNumber(self, nums: list[int]) -&amp;gt; int:
        if len(nums) &amp;lt; 1: return None

        singleSet: set = set()
        multipleSet: set = set()

        startingPoint: int = 0
        endingPoint: int = len(nums) - 1

        while startingPoint &amp;lt;= endingPoint:
            if nums[startingPoint] in singleSet:
                singleSet.remove(nums[startingPoint])
                multipleSet.add(nums[startingPoint])

            elif nums[startingPoint] not in multipleSet:
                singleSet.add(nums[startingPoint])

            if startingPoint == endingPoint:
                startingPoint += 1
                endingPoint -= 1
                continue

            if nums[endingPoint] in singleSet:
                singleSet.remove(nums[endingPoint])
                multipleSet.add(nums[endingPoint])

            elif nums[endingPoint] not in multipleSet:
                singleSet.add(nums[endingPoint])

            startingPoint += 1
            endingPoint -= 1

        for num in singleSet:
            return num

        return None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Leetcode Result&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;So that's it... make sure if you liked the post and got to learn something, like the post and follow us. If you want me to improve at some point... leave that in the comment...&lt;/p&gt;

</description>
      <category>python</category>
      <category>dsa</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Happy Number</title>
      <dc:creator>Ankan Bhattacharya</dc:creator>
      <pubDate>Thu, 10 Feb 2022 18:48:42 +0000</pubDate>
      <link>https://dev.to/ankan_2025/happy-number-5d5n</link>
      <guid>https://dev.to/ankan_2025/happy-number-5d5n</guid>
      <description>&lt;p&gt;&lt;strong&gt;Problem Statement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Write an algorithm to determine if a number n is happy.&lt;/p&gt;

&lt;p&gt;A happy number is a number defined by the following process:&lt;/p&gt;

&lt;p&gt;Starting with any positive integer, replace the number by the sum of the squares of its digits.&lt;br&gt;
Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.&lt;br&gt;
Those numbers for which this process ends in 1 are happy.&lt;br&gt;
Return true if n is a happy number, and false if not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First of all we need to check if the number is already 1. If it is so, return True.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now if it is not so we dedicate a list of numbers to keep the track of the numbers that we already visited. If we visit them again, naturally we are in a loop and we cannot visit 1. Hence return False.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Else its obvious we will visit 1 and one we hit 1 return True.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Algorithm&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Code&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;class Solution:
    def isHappy(self, n: int) -&amp;gt; bool: 
        #Check if the number is already 1 
        if n == 1: return True

        numArray: list[int] = []

        #Now loop through until the number becomes 1 or it is in numArray
        while n not in numArray:
            numArray.append(n)
            tempNum: int = 0

            while n &amp;gt; 0:
                tempNum += ((n%10) * (n%10))
                n //= 10

            if tempNum == 1: return True

            n = tempNum

        #If this statement hits, then it's a false
        return False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Leetcode Result&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;So that's it... make sure if you liked the post and got to learn something, like the post and follow us. If you want me to improve at some point... leave that in the comment...&lt;/p&gt;

</description>
      <category>python</category>
      <category>dsa</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Max Level Sum of A Binary Tree</title>
      <dc:creator>Ankan Bhattacharya</dc:creator>
      <pubDate>Sat, 05 Feb 2022 10:31:33 +0000</pubDate>
      <link>https://dev.to/ankan_2025/max-level-sum-of-a-binary-tree-5e64</link>
      <guid>https://dev.to/ankan_2025/max-level-sum-of-a-binary-tree-5e64</guid>
      <description>&lt;p&gt;&lt;strong&gt;Problem Statement:&lt;/strong&gt; &lt;br&gt;
Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.&lt;/p&gt;

&lt;p&gt;Return the smallest level x such that the sum of all the values of nodes at level x is maximal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This was a problem which had some quite interesting solving... In this approach I used a BFS. I took one row at a time found its sum and compared it with the previous sum. If its greater than the previous one then I replaced the max Level with the current Level. Finally at the end of the looping I returned the max Level.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algo Images&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x08O4ydB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5i1e0jdo9lwjivk753el.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x08O4ydB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5i1e0jdo9lwjivk753el.jpg" alt="Image description" width="880" height="1137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q5dPvPER--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45d1titpprexbfxsrkre.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q5dPvPER--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45d1titpprexbfxsrkre.jpg" alt="Image description" width="880" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code&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;class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

class Solution:
    def maxLevelSum(self, root: TreeNode) -&amp;gt; int:
        if root == None: return None

        currentLevel: int = 1
        maxLevel: int = None
        maxSum: int = None

        BFSQueue: list[TreeNode] = [root]

        while len(BFSQueue) &amp;gt; 0:
            currentLength: int = len(BFSQueue)
            currentSum: int = 0

            for i in range(currentLength):
                currentNode: TreeNode = BFSQueue.pop(0)
                currentSum += currentNode.val

                if currentNode.left != None: BFSQueue.append(currentNode.left)
                if currentNode.right != None: BFSQueue.append(currentNode.right)

            if (maxSum == None) or (maxSum &amp;lt; currentSum):
                maxSum = currentSum
                maxLevel = currentLevel

            currentLevel += 1

        return maxLevel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result Image&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4lfahA0S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/44g24xu0tqc9s130b2px.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4lfahA0S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/44g24xu0tqc9s130b2px.png" alt="Image description" width="880" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you got to learn something from this post make sure you like the post and click on the follow button for more such content. &lt;br&gt;
Also if you have some suggestions and want to improve it make sure you comment down below...&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>computerscience</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
