<?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: Siddhesh Bhupendra Kuakde</title>
    <description>The latest articles on DEV Community by Siddhesh Bhupendra Kuakde (@siddhyaop).</description>
    <link>https://dev.to/siddhyaop</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%2F618252%2Fa7f064d1-cf9e-4062-a1da-7922fe66e915.jpeg</url>
      <title>DEV Community: Siddhesh Bhupendra Kuakde</title>
      <link>https://dev.to/siddhyaop</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/siddhyaop"/>
    <language>en</language>
    <item>
      <title>1518. Water Bottles || LeetCode || C++</title>
      <dc:creator>Siddhesh Bhupendra Kuakde</dc:creator>
      <pubDate>Wed, 01 Oct 2025 04:25:04 +0000</pubDate>
      <link>https://dev.to/siddhyaop/1518-water-bottles-leetcode-c-2125</link>
      <guid>https://dev.to/siddhyaop/1518-water-bottles-leetcode-c-2125</guid>
      <description>&lt;h1&gt;
  
  
  1518. Water Bottles || LeetCode || C++
&lt;/h1&gt;

&lt;p&gt;Solving LeetCode problem &lt;strong&gt;1518. Water Bottles&lt;/strong&gt; with a simple greedy approach in C++.&lt;/p&gt;




&lt;h2&gt;
  
  
  Intuition
&lt;/h2&gt;

&lt;p&gt;We are given a number of full bottles and a rule that allows exchanging empty bottles for new full ones.  &lt;/p&gt;

&lt;p&gt;At first glance, this is similar to repeatedly trading resources:&lt;br&gt;&lt;br&gt;
every time we have enough empty bottles, we can exchange them for more full bottles.  &lt;/p&gt;

&lt;p&gt;The total number of bottles consumed will be the sum of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initially available bottles&lt;/li&gt;
&lt;li&gt;Plus all future bottles obtained by exchanges.&lt;/li&gt;
&lt;/ul&gt;




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

&lt;ol&gt;
&lt;li&gt;Start with &lt;code&gt;numBottles&lt;/code&gt; full bottles, so the total consumed begins at &lt;code&gt;numBottles&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;After drinking them, we gain the same number of empty bottles.
&lt;/li&gt;
&lt;li&gt;While the number of empty bottles is greater than or equal to &lt;code&gt;numExchange&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;Exchange as many as possible:
&lt;code&gt;t = numBottles / numExchange&lt;/code&gt; (new bottles obtained).
&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;t&lt;/code&gt; to the total consumed count.
&lt;/li&gt;
&lt;li&gt;Compute the remaining bottles after exchange:
&lt;code&gt;rem = numBottles % numExchange&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;The new count of empty bottles becomes &lt;code&gt;t + rem&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Repeat until exchanges are no longer possible.
&lt;/li&gt;
&lt;li&gt;Return the total consumed.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This greedy approach works because each exchange step maximizes the number of bottles we can drink at that stage.&lt;/p&gt;




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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time complexity:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Each loop iteration reduces the number of bottles by at least 1, so the loop runs at most &lt;code&gt;O(numBottles)&lt;/code&gt; times.&lt;br&gt;&lt;br&gt;
Effectively, the complexity is closer to &lt;code&gt;O(log(numBottles))&lt;/code&gt; since bottles shrink quickly with division.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Space complexity:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
We only use a few extra variables (&lt;code&gt;t&lt;/code&gt;, &lt;code&gt;rem&lt;/code&gt;, &lt;code&gt;numOfBottles&lt;/code&gt;), so the space usage is &lt;code&gt;O(1)&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Code (C++)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
cpp
class Solution {
public:
    int numWaterBottles(int numBottles, int numExchange) {
        int numOfBottles = numBottles;

        while (numBottles &amp;gt;= numExchange) {
            int t = numBottles / numExchange; // number of new bottles obtained
            int rem = numBottles % numExchange; // leftover bottles
            numOfBottles += t;
            numBottles = t + rem; // update for next round
        }

        return numOfBottles;
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>algorithms</category>
      <category>cpp</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>Subsets</title>
      <dc:creator>Siddhesh Bhupendra Kuakde</dc:creator>
      <pubDate>Mon, 15 Sep 2025 03:45:22 +0000</pubDate>
      <link>https://dev.to/siddhyaop/subsets-17fc</link>
      <guid>https://dev.to/siddhyaop/subsets-17fc</guid>
      <description>&lt;h1&gt;
  
  
  Iterative:
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
public:
    vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; subsets(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
        int n = nums.size();
        vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; ans;
        ans.push_back({});
        for (int num : nums) {
            int size = ans.size();

            for(int i=0; i&amp;lt;size; i++){ // size 1 so fill all once time
                vector&amp;lt;int&amp;gt; ss = ans[i]; // just take current and more to it as per previous size 
                ss.push_back(num); // 1 -&amp;gt; 1 ,
                for(int i=0; i&amp;lt;ss.size(); i++){
                    cout&amp;lt;&amp;lt;ss[i];
                } 
                cout&amp;lt;&amp;lt;endl; 
                ans.push_back(ss);
            }
        }
// [] [0] [1] [2] [0 ,1] [1,2] [2 ,3] 
// 
        return ans;
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Recursive
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
public:
    void createSubset(vector&amp;lt;int&amp;gt;&amp;amp; nums, int index , vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&amp;amp;res, vector&amp;lt;int&amp;gt;&amp;amp;subset ){
        if(index == nums.size())
        {
            res.push_back(subset);
            return; 
        }
        subset.push_back(nums[index]); // take current 
        createSubset(nums, index+1, res, subset);

        subset.pop_back(); // dont take current 
        createSubset(nums, index+1, res, subset);

    }
    vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; subsets(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
        vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; res; 
        vector&amp;lt;int&amp;gt; subset;
        createSubset(nums, 0 , res, subset);
        return res; 
    }
     vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; subsets2(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
        int n = nums.size();
        vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; ans;
        ans.push_back({});
        for (int num : nums) {
            int size = ans.size();

            for(int i=0; i&amp;lt;size; i++){ // size 1 so fill all once time
                vector&amp;lt;int&amp;gt; ss = ans[i]; // just take current and more to it as per previous size 
                ss.push_back(num); // 1 -&amp;gt; 1 ,
                for(int i=0; i&amp;lt;ss.size(); i++){
                    cout&amp;lt;&amp;lt;ss[i];
                } 
                cout&amp;lt;&amp;lt;endl; 
                ans.push_back(ss);
            }
        }
// [] [0] [1] [2] [0 ,1] [1,2] [2 ,3] 
// 
        return ans;
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>1935. Maximum Number of Words You Can Type |</title>
      <dc:creator>Siddhesh Bhupendra Kuakde</dc:creator>
      <pubDate>Mon, 15 Sep 2025 03:08:49 +0000</pubDate>
      <link>https://dev.to/siddhyaop/1935-maximum-number-of-words-you-can-type--24md</link>
      <guid>https://dev.to/siddhyaop/1935-maximum-number-of-words-you-can-type--24md</guid>
      <description>&lt;h1&gt;
  
  
  Intuition
&lt;/h1&gt;

&lt;p&gt;Given string some char broken they cant be used to make that word. return the miniumum number of words that we can form with this. &lt;/p&gt;

&lt;h1&gt;
  
  
  Approach
&lt;/h1&gt;

&lt;p&gt;just check and reduce the count if the chars are found &lt;/p&gt;

&lt;h1&gt;
  
  
  Complexity
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Time complexity:&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;O arr size and O borken letter size &lt;/p&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Space complexity:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;On for array &lt;/p&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Code
&lt;/h1&gt;



&lt;p&gt;```cpp []&lt;br&gt;
class Solution {&lt;br&gt;
public:&lt;br&gt;
    int canBeTypedWords(string text, string brokenLetters) {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // Hello world ad  
    stringstream ss(text);
    vector&amp;lt;string&amp;gt; arr; 
    string word;    
    while(ss &amp;gt;&amp;gt; word){
        arr.push_back(word);
    }
    int ans = arr.size(); 
    for(string  s: arr){

        for(int i=0; i&amp;lt;brokenLetters.size(); i++){
            if(s.contains(brokenLetters[i])){ 
               --ans; break;
            }
        }

    }
    return ans; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};&lt;/p&gt;

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

&lt;/div&gt;

</description>
    </item>
  </channel>
</rss>
