<?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: Abhinav Yadav</title>
    <description>The latest articles on DEV Community by Abhinav Yadav (@abhinav_yadav_554cab962bb).</description>
    <link>https://dev.to/abhinav_yadav_554cab962bb</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%2F1670854%2F7429f3ce-c296-4df5-9122-2d9e2c4d816b.jpeg</url>
      <title>DEV Community: Abhinav Yadav</title>
      <link>https://dev.to/abhinav_yadav_554cab962bb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhinav_yadav_554cab962bb"/>
    <language>en</language>
    <item>
      <title>Building a Personalised AI Chatbot with GPT and Gradio</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Sat, 12 Oct 2024 14:53:58 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/building-a-personalised-ai-chatbot-with-gpt-and-gradioa-45pm</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/building-a-personalised-ai-chatbot-with-gpt-and-gradioa-45pm</guid>
      <description>&lt;p&gt;Have you ever thought about building your own chatbot? One that can respond to whatever you say like Siri or Alexa? Well, today we are going to see how to create a cool AI chatbot using GPT and Gradio and believe me you don't need to be a tech expert to do it!&lt;/p&gt;

&lt;p&gt;By the end of this blog you will have your own chatbot up and running . Let's get started!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What’s GPT?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before we directly dive in building our chatbot we need to know first what is GPT. GPT stands for Generative Pre-trained Transformer. It's a type of AI that can understand human language and respond to it accordingly. Just like a smart robot.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is Gradio?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Gradio is an amazing tool that allows you to create interactive web apps easily. With Gradio, you can easily build apps where you can input texts, images or audio. You can learn more about it in my previous blog, where I have explained it's detailed explanation.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Install the Required Libraries&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now going to our initial step, we will install the libraries that will help us to build our first chatbot. Use these commands to install the libraries:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install openai gradio&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;openai:  This is the library that connects to the GPT models.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;gradio: This creates a web interface for your chatbot.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Set Up Your OpenAI API Key&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You will need an API from OpenAI to use GPT. Go to &lt;a href="https://openai.com/index/openai-api/" rel="noopener noreferrer"&gt;OpenAI API&lt;/a&gt; and sign up if you have not already. Once you are done with this step use the following code:&lt;br&gt;
&lt;/p&gt;

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

openai.api_key = "your-openai-api-key"

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

&lt;/div&gt;



&lt;p&gt;Replace "your-openai-api-key" with your actual key.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Create the Chatbot Logic&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now, the most important part let's create the logic for the chatbot. The bot will take user input and use GPT to generate responses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def gpt_chatbot(user_input):
    response = openai.Completion.create(
        engine="text-davinci-003",  # You can use other engines like "gpt-3.5-turbo"
        prompt=user_input,
        max_tokens=150,
        temperature=0.7
    )
    return response.choices[0].text.strip()

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;engine="text-davinci-003": This tells GPT which version to use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;prompt=user_input: The user’s message is sent to GPT as the prompt.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;max_tokens=150: Limits the response length.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;temperature=0.7: Controls how creative or random the responses are (higher values mean more creative).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Build the Gradio Interface&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now time to make the interface of our chatbot. Let's make it interactive by using Gradio. This part is what makes it fun!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import gradio as gr

# Create Gradio interface
def chatbot_interface(user_input):
    return gpt_chatbot(user_input)

iface = gr.Interface(
    fn=chatbot_interface,  # The function that handles user input
    inputs="text",  # User types text
    outputs="text",  # GPT responds with text
    title="GPT Chatbot",
    description="Ask me anything! I'm your AI assistant."
)

iface.launch()

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;inputs="text": Users will input text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;outputs="text": The chatbot will output text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;title and description: Customize the interface with a friendly title and description.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Run Your Chatbot&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now, run the Python script. Your Gradio app will launch in a new window, and you’ll have your very own personalized chatbot! You can ask it questions, and it will respond intelligently.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 6: Make It Your Own&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once you have the basics set up, you can customize your chatbot to make it more unique:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Adjust the temperature: Want the bot to be more creative? Increase the temperature setting to make it more playful.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add additional prompts: Guide the chatbot’s behavior by giving it specific instructions like “You are a helpful assistant” before each conversation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Building an AI-powered chatbot is easier than ever, thanks to tools like GPT and Gradio. With just a few lines of code, you can create a fully interactive chatbot that’s ready to talk to the world. So go ahead, give it a try, and see how fun it can be!&lt;/p&gt;

&lt;p&gt;Thank You for being till the end of the blog I hope you have learnt something valueable. Do like and share the blog and keep coding.&lt;/p&gt;

&lt;p&gt;Thank You!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>tensorflow</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The Role of AI in Financial Services: Opportunities and Challenges</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Thu, 03 Oct 2024 12:03:08 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/the-role-of-ai-in-financial-services-opportunities-and-challenges-m92</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/the-role-of-ai-in-financial-services-opportunities-and-challenges-m92</guid>
      <description>&lt;p&gt;Hey coders, how you all doing? Today's blog is one of the interesting topics I like to talk on, I am a lot invested into technology but I am also doing my minor degree in financial economics, so today I will write something different. Let's dive in.&lt;/p&gt;

&lt;p&gt;Nowadays Artificial Intelligence is everywhere. From helping you shop online to suggesting your favourite music, AI has become a part of our daily lives. But do you know how AI is changing the banking and finance sector? Let's take a fun and simple look at how AI is shaping the world of finance.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is AI?
&lt;/h2&gt;

&lt;p&gt;Imagine you have a robot friend that can learn things from the internet, understand patterns and help you solve problem quickly! Basically it is a super smart assistant that can help you process huge amount of data and help in make decisions.&lt;/p&gt;

&lt;h2&gt;
  
  
  How AI is Helping Financial Services
&lt;/h2&gt;

&lt;p&gt;AI is making its presence in real world by doing amazing things. Here's how:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Customer Service - Chatbots to the Rescue!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ever chatted with a bank’s website? That’s not a human—it’s a chatbot powered by AI! These can answer your questions, help you with your account information and guide you through policies and help you in taking a loan. They work tirelessly and make customer service more convenient and faster. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Personalised Banking - Tailored Just for You!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI has the power of studying your banking habits and recommend the products that suits you best. Let’s say you often save a bit of money every month. AI might suggest savings accounts or investment options based on your habits, making your banking experience personal and customised.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Fraud Detection - Stopping the Bad Guys!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI is like a superhero that detects suspicious activity on your bank account. It can track if someone tries to steal from your bank account. It identifies by tracking the unusual spending activities on your account. If it detects something unusual, it immediately alert your bank.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Better Decisions - Smarter Loans and Investments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI is very smart bank uses AI to predict whether giving someone loan is good or not. It goes through the past data, AI can help banks figure out if customer is likely to repay a loan or if an investment will be profitable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges: What’s Stopping AI from Being Perfect?
&lt;/h2&gt;

&lt;p&gt;AI is an amazing tool but it comes with some shortcomings. Let's explore the challenges:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Data Privacy - Keeping Your Information Safe&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI works on a large amount of data but in case of banks, they have to handle all the sensitive data. It’s super important for banks to ensure that this data is secure and not misused. Sometimes, there’s a fear that AI systems could be hacked or data could be leaked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Bias in Decision-Making&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI learns from data, but if that data has any biases, the AI system might make unfair decisions. For example, if the data shows a particular group was denied loans more often in the past, the AI might continue that pattern even if it’s wrong or unfair. It’s essential to make AI as unbiased and fair as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Complex Regulations - Rules, Rules, and More Rules!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The financial world is heavily regulated to protect consumers. AI systems need to follow these rules, and sometimes this can slow down progress. Financial institutions must ensure AI is compliant with all regulations, which can be a tricky balancing act.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Future of AI in Finance
&lt;/h2&gt;

&lt;p&gt;The future of AI in financial services is bright! We might see even smarter AI that helps us save money better, offers new investment opportunities, or even makes banking more accessible to everyone around the world.&lt;/p&gt;

&lt;p&gt;But remember, we still have to solve challenges like privacy and fairness to make AI the best tool it can be. With responsible development and careful management, AI can transform financial services for the better, creating a more efficient and inclusive financial system. &lt;/p&gt;

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

&lt;p&gt;AI is like a magic wand for financial services, making everything faster, smarter, and more personal. It helps banks detect fraud, give better financial advice, and provide awesome customer service. But to make the most of AI, banks and financial institutions need to ensure security, fairness, and compliance with rules.&lt;/p&gt;

&lt;p&gt;The world of AI in finance is just beginning, and we’re all part of this exciting journey! &lt;/p&gt;

&lt;p&gt;Feel free to share your thoughts! Would you trust AI to handle your banking needs? Let me know in the comments!&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this blog, if you did don't forget to follow me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-482a4a26b/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt; and &lt;a href="https://github.com/Sensei079" rel="noopener noreferrer"&gt;Github&lt;/a&gt;. Come on I also deserve some fame and if you don't please criticise me in comments.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>learning</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>How to Make a Cool App with Gradio!</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Sat, 28 Sep 2024 18:28:09 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/how-to-make-a-cool-app-with-gradio-3kgl</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/how-to-make-a-cool-app-with-gradio-3kgl</guid>
      <description>&lt;p&gt;Hey there, my coders! I am back with something different from my usual content. Today we gonna learn about Gradio! It's like magic for making apps that help people to talk to computer.&lt;/p&gt;

&lt;p&gt;Now you might be thinking what is this gradio? &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is Gradio?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Imagine gradio as a magic wand for making apps. Imagine having a pet robot, and you want to ask it questions or show it pictures, and it answers you back! Gradio helps you build an interface where you can type things or give pictures, and computer can respond to it.&lt;/p&gt;

&lt;p&gt;You don't need to know a lot about coding to get started. It is very basic and easy to use. Let's see how you can use it!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Setting Up Gradio&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before getting started, we need to tell the computer to install Gradio. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open your terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type this in terminal:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;pip install gradio&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will help you to install gradio and set it up for you.  Now you are all set to create apps!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Creating a Super Simple App&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let's make our very first app! In this app computer will ask for your name, and the computer will says hello to you. Sounds fun, right?&lt;/p&gt;

&lt;p&gt;Write This Code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import gradio as gr&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;def greet(name):&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;return "Hello, " + name + "!"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;iface = gr.Interface(fn=greet, inputs="text", outputs="text")&lt;/code&gt;&lt;br&gt;
&lt;code&gt;iface.launch()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you must be thinking what is happening in this code, Let's break it down:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;import gradio as gr&lt;/code&gt;: This is like saying computer to use gradio to make app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;def greet(name)&lt;/code&gt;: This is the function asking your name and will return you Hello with your name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;iface = gr.Interface(fn=greet, inputs="text", outputs="text")&lt;/code&gt;: This part tells gradio how to build the app. It will take some text as input and return text as output.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;iface.launch()&lt;/code&gt;: This helps us starting the app.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now run your code, you will see a box where you can write your name, and the computer will greet you. Isn't it cool, try typing your name.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Making It More Fun with Pictures!&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let's make the app more cooler by adding pictures! In this, we will show computer some pictures and tell the computer to identify it. &lt;/p&gt;

&lt;p&gt;We’ll use a machine learning model that already knows what many animals look like.&lt;/p&gt;

&lt;p&gt;Write This code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import gradio as gr&lt;/code&gt;&lt;br&gt;
&lt;code&gt;from tensorflow.keras.applications.resnet50 import ResNet50,&lt;/code&gt; &lt;code&gt;decode_predictions, preprocess_input&lt;/code&gt;&lt;br&gt;
&lt;code&gt;from tensorflow.keras.preprocessing import image&lt;/code&gt;&lt;br&gt;
&lt;code&gt;import numpy as np&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;model = ResNet50(weights="imagenet")&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;def classify_image(img):&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;img = image.img_to_array(img)&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;img = np.expand_dims(img, axis=0)&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;img = preprocess_input(img)&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;preds = model.predict(img)&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;return decode_predictions(preds, top=1)[0][0][1]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;iface = gr.Interface(fn=classify_image, inputs="image",&lt;/code&gt; &lt;code&gt;outputs="label")&lt;/code&gt;&lt;br&gt;
&lt;code&gt;iface.launch()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's break down this code, to understand its functionality better:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Loading the model:&lt;/strong&gt; We are uploading ResNet50 as brain of our computer, this helps the computer to guess what's in your picture.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;classify_image:&lt;/strong&gt; This function takes the image and guess what it sees.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;inputs="image":&lt;/strong&gt; Now here instead of text our app is asking for picture as input.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now you can run the code, upload a picture and let computer guess it. You can upload anything in it.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Sharing Your App with Friends!&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now that you have made a cool app, let's now share it with your network and friends. Gradio makes this super easy by giving you a special link you can share with anyone in the world!&lt;/p&gt;

&lt;p&gt;Here's How You Do It:&lt;/p&gt;

&lt;p&gt;Change the last part of your code to this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;iface.launch(share=True)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When you run this code, Gradio will give you a link that you can send to your friends. They can open the link in their browser and play with your app, just like you are!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Adding More Fun Features&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can customise your gradio app the way you want, let's see some ways to make your app more fun:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Change the Title and Description&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can give your app a good title and description to make it more interactive.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;iface = gr.Interface(&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;fn=classify_image,&lt;/code&gt; &lt;br&gt;
    &lt;code&gt;inputs="image",&lt;/code&gt; &lt;br&gt;
    &lt;code&gt;outputs="label",&lt;/code&gt; &lt;br&gt;
    &lt;code&gt;title="Animal Classifier",&lt;/code&gt; &lt;br&gt;
    &lt;code&gt;description="Upload an image, and I'll guess what animal it&lt;/code&gt; &lt;code&gt;is!"&lt;/code&gt;&lt;br&gt;
&lt;code&gt;)&lt;/code&gt;&lt;br&gt;
&lt;code&gt;iface.launch()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now your app looks way more cooler it has a name and a description now which makes it look more professional.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Use More Inputs and Outputs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What if you want to give computer more information? Maybe you want to show it both a picture and type some text, Gradio can handle that too!&lt;/p&gt;

&lt;p&gt;Here’s how you can make an app with both an image and text as input:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;iface = gr.Interface(&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;fn=classify_image,&lt;/code&gt; &lt;br&gt;
    &lt;code&gt;inputs=["image", "text"],&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;outputs="label"&lt;/code&gt;&lt;br&gt;
&lt;code&gt;)&lt;/code&gt;&lt;br&gt;
&lt;code&gt;iface.launch()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now your app will take both an image and some text. It’s like your computer just got smarter! &lt;/p&gt;

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

&lt;p&gt;Wow! You have just learned how to make cool apps using Gradio! You can make a lot of apps using it and it makes coding really fun. You can explore more about it &lt;a href="https://www.gradio.app/docs" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this blog, if you did don't forget to follow me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-482a4a26b/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt; and &lt;a href="https://github.com/Sensei079" rel="noopener noreferrer"&gt;Github&lt;/a&gt;. Come on I also deserve some fame and if you don't please criticise me in comments.&lt;/p&gt;

&lt;p&gt;Happy Coding!!&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>python</category>
    </item>
    <item>
      <title>Leetcode Solution #8</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Mon, 23 Sep 2024 21:04:16 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-8-3875</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-8-3875</guid>
      <description>&lt;h2&gt;
  
  
  1. &lt;a href="https://leetcode.com/problems/minimum-window-substring/description/" rel="noopener noreferrer"&gt;Minimum Window Substring&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Even after less views and no comments I am back coz can't let the culture and streak die hahahaha.....&lt;/p&gt;

&lt;p&gt;Anyways today's question is leetcode hard and took some time to me too solve it but yea did it somehow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's try to understand it's description first,&lt;/p&gt;

&lt;p&gt;Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".&lt;/p&gt;

&lt;p&gt;The testcases will be generated such that the answer is unique.&lt;/p&gt;

&lt;p&gt;Now I will call this description a very poor explanation of the question, basically the question is saying that we have given two strings s and t and length of these strings are m and n respectively, we are asked to return a minimum window substring of s such that every character present in t is included in the window we are returning.&lt;/p&gt;

&lt;p&gt;See these examples to make sense of what I said,&lt;/p&gt;

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

&lt;p&gt;Well question is kind of messed up but not that bad, have confidence you can do it. Let's move to approach.&lt;/p&gt;

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

&lt;p&gt;We will do the same thing which we do when we have two strings to compare, i.e.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Store occurrence of characters of string t.&lt;/li&gt;
&lt;li&gt;Count occurrence of characters of string s.&lt;/li&gt;
&lt;li&gt;If all characters matched, minimise the window.&lt;/li&gt;
&lt;li&gt;Update window size.&lt;/li&gt;
&lt;li&gt;Return substring.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Looks pretty easy isn't it but code looks a little bit scary. But I have tried my best to make it easy in steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution&lt;/strong&gt;&lt;/p&gt;

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

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

&lt;p&gt;So, steps to achieve this crazy code are,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Check if length of t is longer than s if it is return empty string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare two vectors of size 256 initialised to 0.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Populate hashT with counts of character in t using for loop.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare variable start as starting index of current window in s, start_index keeps track of the best starting index for minimum window found, min_len initialises to max possible integer value, count to count how many characters from t we have matched in current window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Loop through each character in s.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Increment the count for character s[j] in hashS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If s[j] is a character in t and the count in hashS for that character does not exceeds that in hashT, we found a match and we increment count.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if all characters are matched.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inner loop shrinks the window from left until we can no longer maintain all characters in t.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calculate current window length.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If this length is less, update the length and set start_index to current start.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Damn such a complex question isn't it that's why only one for today hehe, if you will attempt this you will need time to digest this and don't quit.&lt;/p&gt;

&lt;p&gt;And please please if you are liking this atleast react to it comment on it criticise it if you are not liking come on don't be like this. &lt;/p&gt;

&lt;p&gt;Connect to me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-482a4a26b/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt; and &lt;a href="https://github.com/Sensei079" rel="noopener noreferrer"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Come on man I deserve some fame.&lt;/p&gt;

&lt;p&gt;Thank you if you are following this blog till here, have some confidence you can do it. &lt;/p&gt;

&lt;p&gt;KEEP CODING!!!&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>codenewbie</category>
      <category>coding</category>
      <category>cpp</category>
    </item>
    <item>
      <title>Leetcode Solution #7</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Sun, 22 Sep 2024 19:56:26 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-7-go2</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-7-go2</guid>
      <description>&lt;h2&gt;
  
  
  1. &lt;a href="https://leetcode.com/problems/count-subarrays-with-score-less-than-k/solutions/" rel="noopener noreferrer"&gt;Count Subarrays With Score Less Than K&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Always try making sense out of the description though most the time its just trash but still try, so the description is given as,&lt;/p&gt;

&lt;p&gt;The score of an array is defined as the product of its sum and its length.&lt;/p&gt;

&lt;p&gt;For example, the score of [1, 2, 3, 4, 5] is (1 + 2 + 3 + 4 + 5) * 5 = 75.&lt;/p&gt;

&lt;p&gt;Given a positive integer array nums and an integer k, return the number of non-empty subarrays of nums whose score is strictly less than k.&lt;/p&gt;

&lt;p&gt;A subarray is a contiguous sequence of elements within an array.&lt;/p&gt;

&lt;p&gt;blah blah blah blah......&lt;/p&gt;

&lt;p&gt;So, basically the question is saying that you have to find the score of an array, now the first question should be what is the meaning of score of an array, so well it is defined as the product of the sum of elements given in array and the size of array. &lt;br&gt;
So, in question a positive integer array is given, we have to return the number of non-empty subarrays whose score is strictly less than k, k is a already given integer.&lt;/p&gt;

&lt;p&gt;Look at the examples given below to make sense of the summary I gave above,&lt;/p&gt;

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

&lt;p&gt;Now, here I am assuming that you have understood what I am trying to explain if not try youtube.&lt;/p&gt;

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

&lt;p&gt;Well though this marked as hard level problem on leetcode but the approach does not feels like it because it is pretty basic.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Traverse the array and calculate the cumulative sum (coz subarray duhh!).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calculate the score of the array by calculating it's size and sum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Count the valid subarrays.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return count of subarray.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, I know you have understood nothing till here or even if you have and don't know how to write the code don't worry, I got you and if everything is making sense for you then damn I am getting good at this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;If you have understood nothing till here, try to look at the code and I am writing the steps below try to make sense of it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Declare variable sum, result and start, initialise them with 0, use sum for storing the cumulative sum of array and result to store the valid subarrays and start for pointing beginning of window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traverse the array, add current elements to sum to take cumulative sum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calculate size which is i-start+1 i.e. from start to i.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calculate score by multiplying size with sum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We will use while loop to ensure that k is less than score, if it exceeds we will shrink the window by incrementing start.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each time we shrink window, reduce sum by the element at start.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recalculate the size and score for new window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After adjusting window add the count of valid subarrays.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hope you have understood till here if yes thank you, you people are making this labour worth and if you don't once again try youtube.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://leetcode.com/problems/daily-temperatures/description/" rel="noopener noreferrer"&gt;Daily Temperatures&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well repeat the drill here read the description first.&lt;/p&gt;

&lt;p&gt;Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the i th day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.&lt;/p&gt;

&lt;p&gt;Well if you are able to make sense out of this description well congrats you are better at english than me and if you don't I got you covered again homie.&lt;/p&gt;

&lt;p&gt;Description is basically saying that an array is given and which represents the daily temperatures and we have to return an array answer which will have the number of days we have to wait after the i th day to get a warmer temperature. If there is no future day for this just return 0 on that index.&lt;/p&gt;

&lt;p&gt;Refer to below given examples for a better understanding,&lt;/p&gt;

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

&lt;p&gt;Hope this made sense for you and you are understanding it, if not try youtube.&lt;/p&gt;

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

&lt;p&gt;Like every other question approach is basic for this one too and try to think hard and understand by yourself everything will make sense, so the approach goes like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Use stack (well it is the most optimised approach for this) to store indices of the temperatures array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When a warmer day is found, it pops the stack and calculates number of days until that warmer temperature.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remaining indices in stack will have 0 in result because no warmer day exists for them.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope till here you are getting me, if not lets move towards the solution look at the code and try to form a basic understanding from the steps given below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Is this making sense? No? Try to figure it from the below given steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Declare a stack st to store indices of the temperatures array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare vector answer with size n and all elements set to 0.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traverse the array temperatures.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use while loop to check whether stack is non empty and current day temperature is greater than temperature at top of stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare a integer variable index to store top index from stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove top element when we found warmer temperature for that day.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calculate number of days between.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Push i into stack because we have not found a warmer day yet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return answer.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Was this question easy? Was this approach easy to understand, if yes thank you.&lt;/p&gt;

&lt;p&gt;So, this was it for today, I hope both the questions were easy to understand if yes do not keep this thought to yourself please comment down below, it can motivate me a lot. If you were not able to understand and have a better approach for this comment it down below too. I ain't no celeb I will reply. But do comment it helps. &lt;/p&gt;

&lt;p&gt;Connect to me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-482a4a26b/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt; and &lt;a href="https://github.com/Sensei079" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Come on I deserve some fame.&lt;/p&gt;

&lt;p&gt;Thank you, if you are genuinely reading till here.&lt;/p&gt;

&lt;p&gt;KEEP CODING!!!&lt;/p&gt;

</description>
      <category>coding</category>
      <category>100daysofcode</category>
      <category>programming</category>
    </item>
    <item>
      <title>Leetcode Solution #6</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Mon, 16 Sep 2024 17:06:29 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-6-10ph</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-6-10ph</guid>
      <description>&lt;h2&gt;
  
  
  1. &lt;a href="https://leetcode.com/problems/min-stack/description/" rel="noopener noreferrer"&gt;Min Stack&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by reading the description of the problem,&lt;/p&gt;

&lt;p&gt;Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.&lt;/p&gt;

&lt;p&gt;Implement the MinStack class:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;MinStack() initializes the stack object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;void push(int val) pushes the element val onto the stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;void pop() removes the element on the top of the stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;int top() gets the top element of the stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;int getMin() retrieves the minimum element in the stack.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You must implement a solution with O(1) time complexity for each function.&lt;/p&gt;

&lt;p&gt;It is a leetcode medium question but very easy to attempt. &lt;/p&gt;

&lt;p&gt;Refer the example for better understanding,&lt;/p&gt;

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

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

&lt;p&gt;Our approach for this question is going to be pretty straightforward, we don't need to do anything special in this question we will just apply our basic knowledge of stack and complete the given functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

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

&lt;p&gt;We have implemented the solution in following ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Initialise two stacks s1 and min, s1 will store all values and min stack will have the minimum value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MinStack will be empty as it will not do anything specific here.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In push function, push the value in main stack(s1), check if min stack is empty or value is less than or equal to current minimum value. If condition is true, it means value is new minimum, so it should be added to min stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For pop function ensure that s1 is not empty, check if top value of s1 is equal to top value of min. If so, means that we have to pop top value of min stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pop top value from s1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For top function, return top value of s1 stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For getMin function, return top value of min stack.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://leetcode.com/problems/evaluate-reverse-polish-notation/description/" rel="noopener noreferrer"&gt;Evaluate Reverse Polish Notation&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.&lt;/p&gt;

&lt;p&gt;Evaluate the expression. Return an integer that represents the value of the expression.&lt;/p&gt;

&lt;p&gt;Note that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The valid operators are '+', '-', '*', and '/'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each operand may be an integer or another expression.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The division between two integers always truncates toward zero.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There will not be any division by zero.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The input represents a valid arithmetic expression in a reverse &lt;br&gt;
polish notation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The answer and all the intermediate calculations can be &lt;br&gt;
represented in a 32-bit integer.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This question is also very basic and is rated medium on leetcode, It is very basic question we just have to evaluate postfix notation.&lt;/p&gt;

&lt;p&gt;Refer the examples given below for better understanding&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Approaches&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Iterate over all characters one by one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If character is operand push it in the stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If character is operator pop two elements from start and perform operation.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

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

&lt;p&gt;We have achieved this solution by following ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Initialise a stack to store the result.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate over the tokens vector.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if first character of token is digit, then check if it has atleast 2 characters and negative and second character must be digit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If any of above is true convert string to int and push it in stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Else if the character is an operator, There are two operands at top of stack value 1 and value 2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Since token is an operator now based on operator check the case and push the value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The final result is at top of the stack.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope the solutions I have provided are understandable and explanations are easy to understand.&lt;/p&gt;

&lt;p&gt;Thank You&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-482a4a26b/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>100daysofcode</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>Leetcode Solution #5</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Sat, 14 Sep 2024 19:26:15 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-5-5g45</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-5-5g45</guid>
      <description>&lt;h2&gt;
  
  
  1. &lt;a href="https://leetcode.com/problems/unique-email-addresses/description/" rel="noopener noreferrer"&gt;Unique Email Addresses&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by reading the description of the problem,&lt;/p&gt;

&lt;p&gt;Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.&lt;/p&gt;

&lt;p&gt;For example, in "&lt;a href="mailto:alice@leetcode.com"&gt;alice@leetcode.com&lt;/a&gt;", "alice" is the local name, and "leetcode.com" is the domain name.&lt;br&gt;
If you add periods '.' between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. Note that this rule does not apply to domain names.&lt;/p&gt;

&lt;p&gt;For example, "&lt;a href="mailto:alice.z@leetcode.com"&gt;alice.z@leetcode.com&lt;/a&gt;" and "&lt;a href="mailto:alicez@leetcode.com"&gt;alicez@leetcode.com&lt;/a&gt;" forward to the same email address.&lt;br&gt;
If you add a plus '+' in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered. Note that this rule does not apply to domain names.&lt;/p&gt;

&lt;p&gt;For example, "&lt;a href="mailto:m.y+name@email.com"&gt;m.y+name@email.com&lt;/a&gt;" will be forwarded to "&lt;a href="mailto:my@email.com"&gt;my@email.com&lt;/a&gt;".&lt;br&gt;
It is possible to use both of these rules at the same time.&lt;/p&gt;

&lt;p&gt;Given an array of strings emails where we send one email to each emails[i], return the number of different addresses that actually receive mails.&lt;/p&gt;

&lt;p&gt;The description might look big and scary but believe me question is &lt;br&gt;
not that scary when it comes to the implementation, basically the question is saying&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;An email is divide into two parts the part before @ is called local name, the part after @ is called domain name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the question we have to handle following cases:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Dots (.) in the local name can be ignored.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Everything after the first plus sign (+) in the local name is discarded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The domain name is not altered by dots or plus signs. It is used as is.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3.Two email addresses are considered the same if, after applying the above rules, they are identical.&lt;/p&gt;

&lt;p&gt;4.You need to count how many unique addresses there are after applying these rules.&lt;/p&gt;

&lt;p&gt;Looks easy isn't it.&lt;/p&gt;

&lt;p&gt;Refer the example for better understanding,&lt;/p&gt;

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

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

&lt;p&gt;Our approach for this question is going to be pretty straightforward,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find @ symbol divide the email in local name and domain name.&lt;/li&gt;
&lt;li&gt;Find '+' and '.' sign in local name and process it.&lt;/li&gt;
&lt;li&gt;Merge the local and domain name together and give the answer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;We have achieved this solution by following ways,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Declare an unordered set unique to store the final answer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traverse the string and find the @ symbol.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you find @ divide the part before @ as local name and part after that as domain name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare a variable processedLocal as string datatype.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traverse LocalName, if you find '+' symbol break because we have to ignore the values after + and if you find '.' symbol ignore it and add the rest of string in processedLocal variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare a string final where we give merged email of processedLocal, @ and domain Name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Insert the final into the set unique.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return the size of unique.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://leetcode.com/problems/remove-element/description/" rel="noopener noreferrer"&gt;Remove Element&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by reading the description of problem&lt;/p&gt;

&lt;p&gt;Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.&lt;/p&gt;

&lt;p&gt;Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Change the array nums such that the first k elements of nums contain the elements which are not equal to val. The remaining elements of nums are not important as well as the size of nums.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return k.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Question is pretty straight forward and easy we just have to remove a given element from an array and return the size of the array after removing it, the only catch is that the positions will change.&lt;/p&gt;

&lt;p&gt;Refer the examples for better understanding,&lt;/p&gt;

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

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

&lt;p&gt;The approach to solve this question is short and pretty straight forward,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Iterate the array&lt;/li&gt;
&lt;li&gt;Check and move valid elements&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Steps to achieve this solution is as follows,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Initialise the variable index with 0 to keep track of position where next valid element should be placed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate through the vector.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if current element equal to value if not move it to position indicated by index and then increment the index to update next position.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return index.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  3.&lt;a href="https://leetcode.com/problems/group-anagrams/description/" rel="noopener noreferrer"&gt;Group Anagrams&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by reading the description&lt;/p&gt;

&lt;p&gt;Given an array of strings strs, group the anagrams together. You can return the answer in any order.&lt;/p&gt;

&lt;p&gt;Well, I this time I guess question is understandable by description only.&lt;/p&gt;

&lt;p&gt;Refer to example for better understanding.&lt;/p&gt;

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

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

&lt;ol&gt;
&lt;li&gt;Use hashmap to map each sorted string.&lt;/li&gt;
&lt;li&gt;Sort the string.&lt;/li&gt;
&lt;li&gt;Group by sorted string.&lt;/li&gt;
&lt;li&gt;Add groups to result.&lt;/li&gt;
&lt;li&gt;Return result.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Initialise a result vector this will store final grouped anagram.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialise a hash map to map sorted string to a vector of original strings that are anagrams of that key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Loop through each string in input vector.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sort the strings as it helps in identifying anagrams.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add original string to vector associated with its sorted version in hashmap. This groups all anagrams together under same key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate through hashmap and add each group of anagrams to result vector.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope the solutions I have provided are understandable and explanations are easy to understand.&lt;/p&gt;

&lt;p&gt;Thank You&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-482a4a26b/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>100daysofcode</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>Leetcode Solution #4</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Fri, 13 Sep 2024 11:54:00 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-4-507g</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solution-4-507g</guid>
      <description>&lt;h2&gt;
  
  
  1. &lt;a href="https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/description/" rel="noopener noreferrer"&gt;Replace Elements with Greatest Element on Right Side&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by reading the description of the problem,&lt;/p&gt;

&lt;p&gt;Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.&lt;/p&gt;

&lt;p&gt;After doing so, return the array.&lt;/p&gt;

&lt;p&gt;This is a leetcode easy and pretty basic question as it is written in the question we have to replace every element in the array with greatest element to the right side of those elements and we have to replace the last element with -1.&lt;/p&gt;

&lt;p&gt;Refer the example for better understanding,&lt;/p&gt;

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

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

&lt;p&gt;Our approach for this question is going to be pretty straightforward,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We will initialise last element as maximum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set the last element as -1, because there won't be anything in right of last element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traverse the array from right to left and return the maximum elements.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;We have achieved the solution in following steps,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Initialise max variable to last element of array. This will track for the maximum element when we traverse from right to left.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set last element as -1 as there are no elements right to it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traverse from second last element because last has already been set to -1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Store max into a temporary variable temp because we need to update it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If current element is greater than max update the value to current value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Current element is replaced with temp, which held value of max element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return arr.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://leetcode.com/problems/is-subsequence/description/" rel="noopener noreferrer"&gt;Is Subsequence&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given two strings s and t, return true if s is a subsequence of t, or false otherwise.&lt;/p&gt;

&lt;p&gt;A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).&lt;/p&gt;

&lt;p&gt;This question is also pretty basic and straightforward you have to check if string s is subsequence of t. If it is return true else return false.&lt;/p&gt;

&lt;p&gt;Refer to example for better understanding,&lt;/p&gt;

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

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

&lt;p&gt;The approach for this question is also not that special, we just have to keep check of some base and recursive cases, lets jump to the solution its very easy to understand this question through solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;We approached the solution by following steps,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Declare a helper function subsequence first with parameters string s and t (we have to compare between these strings) and variable m and n as length of these strings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check for base cases if s is traversed completely i.e. m==0, return true because it means we have matched all the characters of s.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If t is completely traversed return false because s still have unmatched characters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If last characters of s and t are equal move both m and n to next character.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If current character mismatch skip current character in t by reducing n and keep m unchanged, checking if s can still be a subsequence of the remaining part of t.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now in main function isSubsequence if length of m&amp;gt;n return false.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Otherwise, call the recursive Subsequence function to determine if s is a subsequence to t.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  3. &lt;a href="https://leetcode.com/problems/length-of-last-word/description/" rel="noopener noreferrer"&gt;Length of Last Word&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given a string s consisting of words and spaces, return the length of the last word in the string.&lt;/p&gt;

&lt;p&gt;A word is a maximal substring consisting of non-space characters only.&lt;/p&gt;

&lt;p&gt;This question is also leetcode easy and pretty basic, all we have to do is just to find the length of last word.&lt;/p&gt;

&lt;p&gt;Refer the example for the better understanding,&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Approach&lt;/strong&gt;&lt;br&gt;
We can approach this question in following way:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Traverse the string from last character.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if the last character is alphabetical or not.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return the length.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;We reached this solution by following steps,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Declare variable count that will hold length of last word.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare a bool flag to track when we start counting characters of last word. It will be initialised as false.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate from right to left.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use if condition to check if current character is alphabet or not.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When we encounter a letter flag turns to true indicating that we are counting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Increment count.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If we encounter space after starting last word it means we have finished counting, return the count.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If no space encountered after last word, return count.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope the solutions I have provided are understandable and explanations are easy to understand.&lt;/p&gt;

&lt;p&gt;Thank You&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-482a4a26b/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>100daysofcode</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>Leetcode Solutions #3</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Thu, 12 Sep 2024 18:44:53 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solutions-3-3d6i</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solutions-3-3d6i</guid>
      <description>&lt;h2&gt;
  
  
  1. &lt;a href="https://leetcode.com/problems/top-k-frequent-elements/description/" rel="noopener noreferrer"&gt;Top K Frequent Elements&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First read the description of problem:&lt;/p&gt;

&lt;p&gt;Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.&lt;/p&gt;

&lt;p&gt;Question is leetcode rating medium but is pretty basic when it comes to implementation.&lt;/p&gt;

&lt;p&gt;Refer to the examples below&lt;/p&gt;

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

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

&lt;p&gt;Approach is also very basic just like the question:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Use map to count the frequency of the elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make a key value pair of elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return the elements according to the question.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;In the solution we have done the following things,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Use an unordered map to count and store frequency of each number.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialise a vector named bucket with n+1 empty vector. This will group elements with their frequency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate over the map and extract elements and their frequency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add elements to this bucket corresponding to its frequency. This groups elements by their frequency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare a vector result to store final list.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterates backward to process bucket with higher frequency first.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check for elements in bucket and iterate over each element in bucket.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add current element in result vector and decrease remaining element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://leetcode.com/problems/product-of-array-except-self/description/" rel="noopener noreferrer"&gt;Product of Array Except Self&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Firstly read the description of problem:&lt;/p&gt;

&lt;p&gt;Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].&lt;/p&gt;

&lt;p&gt;The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.&lt;/p&gt;

&lt;p&gt;You must write an algorithm that runs in O(n) time and without using the division operation.&lt;/p&gt;

&lt;p&gt;Question is pretty understandable from its statement only, we have to multiply the elements of the array except the element itself.&lt;br&gt;
The only catch is we have to do this without doing division and in O(n) time complexity.&lt;/p&gt;

&lt;p&gt;Here is the example for better understanding,&lt;/p&gt;

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

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

&lt;p&gt;Approach is pretty basic here also we just have to make two passes over the array,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Left Pass: In first pass, it multiplies each element by product of all elements to the left of each index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right Pass: In second pass, it multiplies each element by product of all elements to right of the index.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;In this solution we have,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Creates a vector result of size n to store final product.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialises first element of result to 1, because there are no elements to left of first element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start iterating through nums array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For each index is this calculates the product of all elements to left of i and stores it in result[i] is product of result[i-1] and nums[i-1].&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialise a variable right_product to store product of elements to right of each index. Set it to 1 because there are no elements to right of last element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This loop iterates through nums in reverse order.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;At each index i, it multiplies the current value of result[i] by right_product.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update right_product by multiplying it with the current elements nums[i]. This allows right_product to hold the product of all elements to right of next elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope the solutions I have provided are understandable and explanations are easy to understand.&lt;/p&gt;

&lt;p&gt;Thank You&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-7891aby/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>coding</category>
      <category>codenewbie</category>
      <category>codereview</category>
    </item>
    <item>
      <title>Leetcode Solutions #2</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Wed, 11 Sep 2024 17:24:58 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solutions-2-19cp</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solutions-2-19cp</guid>
      <description>&lt;h2&gt;
  
  
  1. &lt;a href="https://leetcode.com/problems/sort-list/description/" rel="noopener noreferrer"&gt;Sort List&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First read the description of problem:&lt;/p&gt;

&lt;p&gt;Given the head of a linked list, return the list after sorting it in ascending order.&lt;/p&gt;

&lt;p&gt;So here, basically we have to return the linked list after sorting it in ascending order.&lt;/p&gt;

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

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

&lt;p&gt;There are a lot of ways to solve this question but one of the easiest and optimal way is to implement the merge sort in this problem. We will follow the following steps to implement the merge sort here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the middle of the list&lt;/li&gt;
&lt;li&gt;Split the list&lt;/li&gt;
&lt;li&gt;Merge it &lt;/li&gt;
&lt;li&gt;Sort and Return the list&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Basically the same procedure which we follow for merge sort.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;In the solution we have done the following things,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We have declared a function to find the middle value of the list, here we are using slow and fast pointer to find it, slow pointer will point to next of head and fast will be ahead of slow, so when fast will exit the list , slow will reach the middle of list.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now declare a merge function to merge the list, create a dummy node to help easily build the merge list, tail is pointer to track end of merge list.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compare l1 and l2 values, the smaller node append to next of tail and move pointer in that list. Move tail to its next.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If one list gets exhausted before the other, append remaining nodes from non empty list to next of tail.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return merged list.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, in sortList function use findMiddle function to get the middle node of list, split the list into two by making next of middle null.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recursively sort both the halves.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Merge the list and return it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://www.geeksforgeeks.org/problems/add-1-to-a-number-represented-as-linked-list/1?utm_source=youtube&amp;amp;utm_medium=collab_striver_ytdescription&amp;amp;utm_campaign=add-1-to-a-number-represented-as-linked-list" rel="noopener noreferrer"&gt;Add 1 to a Linked List Number&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Firstly read the description of problem:&lt;/p&gt;

&lt;p&gt;You are given a linked list where each element in the list is a node and have an integer data. You need to add 1 to the number formed by concatinating all the list node numbers together and return the head of the modified linked list. &lt;/p&gt;

&lt;p&gt;So, in this question we have to take the nodes of a linked list together as a number and add 1 to it. &lt;/p&gt;

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

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

&lt;p&gt;For adding 1 to given number we have to keep in mind that we have to handle the carry also so for that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Recursively traverse to the end of LL, accumulating carry.&lt;/li&gt;
&lt;li&gt;Handle the carry recursively.&lt;/li&gt;
&lt;li&gt;Add carry to current node value and update it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;In this solution we have,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Declare a function addWithCarry which handles the carry that results from addition.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add data of current node to carry returned from recursive call on next node. This give total sum with carry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update current node data to last digit of result, handling the carry for current node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return carry for next node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In addOne function call addWithCarry to add one to the number and handle any carry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If there is a carry left after processing all nodes, create a new node with carry value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set this new node's next to current head and return new node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If there is no carry left return original head.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope the solutions I have provided are understandable and explanations are easy to understand.&lt;/p&gt;

&lt;p&gt;Thank You&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-7891aby/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>coding</category>
      <category>codenewbie</category>
      <category>codereview</category>
    </item>
    <item>
      <title>Leetcode Solutions #1</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Tue, 10 Sep 2024 18:39:45 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solutions-1-1b4f</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/leetcode-solutions-1-1b4f</guid>
      <description>&lt;h2&gt;
  
  
  &lt;a href="https://leetcode.com/problems/longest-common-prefix/description/" rel="noopener noreferrer"&gt;1. Longest Common Prefix&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's read the description first:&lt;/p&gt;

&lt;p&gt;Write a function to find the longest common prefix string amongst an array of strings.&lt;br&gt;
If there is no common prefix, return an empty string "".&lt;/p&gt;

&lt;p&gt;Question is not that hard to understand from the description in this question you have to check for the longest common prefix among a given array of string. If there is no common prefix just simply return "".&lt;/p&gt;

&lt;p&gt;Refer to the examples given below:&lt;/p&gt;

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

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

&lt;p&gt;Basic approach here should be that when we have to find something common among a set of items, we compare the first item with others. Similarly here we will use the same kind of approach in following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set the first string as the prefix.&lt;/li&gt;
&lt;li&gt;Compare the first string with all other given strings.&lt;/li&gt;
&lt;li&gt;Keep reducing the length of string to find the common prefix.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;In the solution,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set the first string of the vector strs as the prefix.&lt;/li&gt;
&lt;li&gt;Iterate through the remaining string using for loop.&lt;/li&gt;
&lt;li&gt;While loop checks if the current string starts with the current prefix. If not the loop will run.&lt;/li&gt;
&lt;li&gt;If prefix is not found &lt;code&gt;prefix.substr(0, prefix.length()-1)&lt;/code&gt; this will trim one character from the end and creates a new string from starting to second last character of prefix.&lt;/li&gt;
&lt;li&gt;If prefix not found even after trimming return "".&lt;/li&gt;
&lt;li&gt;Else return prefix.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://leetcode.com/problems/sort-characters-by-frequency/description/" rel="noopener noreferrer"&gt;2. Sort Characters By Frequency&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's Read the description first:&lt;/p&gt;

&lt;p&gt;Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.&lt;/p&gt;

&lt;p&gt;Return the sorted string. If there are multiple answers, return any of them.&lt;/p&gt;

&lt;p&gt;The description is pretty basic and understandable about what we need to achieve in this question.&lt;/p&gt;

&lt;p&gt;Refer to the examples given below:&lt;/p&gt;

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

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

&lt;p&gt;This question is pretty basic approach wise, we can do this in the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an unordered map to record the frequencies of characters.&lt;/li&gt;
&lt;li&gt;Make character frequency pair of every character appearing in the string.&lt;/li&gt;
&lt;li&gt;Sort the string and return the result.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;In the solution,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I have declared an unordered map frq that will store characters as key and their frequencies as values.&lt;/li&gt;
&lt;li&gt;Use for loop to iterate over each character in the given string and record their frequencies.&lt;/li&gt;
&lt;li&gt;A vector of pairs freqpair is created using the elements from the frq map. Each element in the freqpair vector contains a character and its frequency as a pair. The map is transformed into a vector to allow sorting based on the frequency.&lt;/li&gt;
&lt;li&gt;I have used basic bubble sort for the sorting purpose.&lt;/li&gt;
&lt;li&gt;Declare a for loop that goes through the sorted freqpair vector. For each pair p, it appends the character to the result string, repeated p.second times.&lt;/li&gt;
&lt;li&gt;Return result.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://leetcode.com/problems/string-to-integer-atoi/description/" rel="noopener noreferrer"&gt;String to Integer (atoi)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's Read the description first:&lt;/p&gt;

&lt;p&gt;Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer.&lt;/p&gt;

&lt;p&gt;The algorithm for myAtoi(string s) is as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Whitespace: Ignore any leading whitespace (" ").&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Signedness: Determine the sign by checking if the next character is '-' or '+', assuming positivity is neither present.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Conversion: Read the integer by skipping leading zeros until a non-digit character is encountered or the end of the string is reached. If no digits were read, then the result is 0.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rounding: If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then round the integer to remain in the range. Specifically, integers less than -231 should be rounded to -231, and integers greater than 231 - 1 should be rounded to 231 - 1.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Return the integer as the final result.&lt;/p&gt;

&lt;p&gt;In my opinion, this question just looks scary but is very easy to deal with just ignore the description and focus on the part that you have to convert a string to integer with some conditions like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There should not be any leading whitespaces.&lt;/li&gt;
&lt;li&gt;Check for the signs that the character is '-' or '+'.&lt;/li&gt;
&lt;li&gt;Check for the non digit characters, if you encounter non digit character you have to stop reading.&lt;/li&gt;
&lt;li&gt;Handle the integer overflow.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Refer to the examples below:&lt;/p&gt;

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

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

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

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

&lt;p&gt;There is nothing special going to be with the approach you just have to look out for the conditions mentioned in the description and convert the string to int. Let's go to the solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

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

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

&lt;p&gt;In the solution,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Declare and initialize three variable index(to traverse string s), num(to store the resultant integer), negative(to check whether number is negative or not). &lt;/li&gt;
&lt;li&gt;Use while loop to check for any leading whitespace, the function isspace checks if the current character is whitespace. Loop will continue until a non whitespace character is found.&lt;/li&gt;
&lt;li&gt;Now, we will check for the sign if the current character is '-' or '+' sign. If character is '-' sign the negative is set to be true and index is incremented to move past the sign.&lt;/li&gt;
&lt;li&gt;Here, this while loop continues until it encounters a non-digit character. &lt;code&gt;int digit = s[index] - '0'&lt;/code&gt; converts the character at a particular index from its ASCII value to numeric value.&lt;/li&gt;
&lt;li&gt;This if statement checks for overflow. If adding the next digit would cause num to exceed the 32-bit signed integer limit (INT_MAX), the function returns the appropriate value.&lt;/li&gt;
&lt;li&gt;If there is no overflow, current digit is added to num. The number is updated by multiplying num by 10 and adding the value of the current digit. The index is then incremented to move to the next character.&lt;/li&gt;
&lt;li&gt;After processing all digits if negative is true, num is made negative by multiplying by -1.&lt;/li&gt;
&lt;li&gt;Now return num.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope the solutions I have provided are understandable and explanations are easy to understand.&lt;/p&gt;

&lt;p&gt;Thank You&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://www.linkedin.com/in/abhinav-yadav-482a4a26b/" rel="noopener noreferrer"&gt;linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>coding</category>
      <category>codenewbie</category>
      <category>codereview</category>
    </item>
    <item>
      <title>Blockchain Beyond Crypto: Real-World Applications</title>
      <dc:creator>Abhinav Yadav</dc:creator>
      <pubDate>Wed, 07 Aug 2024 15:27:58 +0000</pubDate>
      <link>https://dev.to/abhinav_yadav_554cab962bb/blockchain-beyond-crypto-real-world-applications-26ga</link>
      <guid>https://dev.to/abhinav_yadav_554cab962bb/blockchain-beyond-crypto-real-world-applications-26ga</guid>
      <description>&lt;p&gt;Usually when people hear the term "blockchain", they usually get the thought of cryptocurrencies like Bitcoin and Ethereum. However, blockchain extends beyond digital currencies. Its unique features—decentralisation, transparency, and immutability—are driving innovation across various industries. In this blog, we'll explore some fascinating real-world applications of blockchain that might surprise you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Content
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is Blockchain?&lt;/li&gt;
&lt;li&gt;Supply Chain Management&lt;/li&gt;
&lt;li&gt;Healthcare&lt;/li&gt;
&lt;li&gt;Voting Systems&lt;/li&gt;
&lt;li&gt;Real Estate&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Blockchain?
&lt;/h2&gt;

&lt;p&gt;Before going straight towards the application of blockchain, let's briefly explain what blockchain is. Imagine a digital ledger that records transactions across many computers in a way that ensures the data's integrity and security. Each "block" of data is linked to the previous one, forming a "chain"—hence the name blockchain. This technology eliminates the need for intermediaries, reduces fraud, and increases transparency.&lt;/p&gt;

&lt;h2&gt;
  
  
  Supply Chain Management
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How Does It Work?
&lt;/h3&gt;

&lt;p&gt;Blockchain is capable of tracking the journey of products from its origin to final destination. Each step in the supply chain is recorded on the blockchain, creating an immutable record.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Is It Important?
&lt;/h3&gt;

&lt;p&gt;Transparency about the origin of product is the priority for consumer. Blockchain helps verify the authenticity of goods, such as organic food or luxury items, by providing an unalterable record of their journey.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interactive Element:&lt;/strong&gt; Imagine you're buying a diamond ring. With blockchain, you can scan a QR code to see the diamond's entire history—from the mine to your finger. Wouldn't that make your purchase feel more secure and trustworthy?&lt;/p&gt;

&lt;h2&gt;
  
  
  Healthcare
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How Does It Work?
&lt;/h3&gt;

&lt;p&gt;Blockchain can store patient records securely, ensuring that they are accessible only to authorised parties. Each update to a patient's record can be logged in the blockchain, providing a complete history. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why Is It Important?
&lt;/h3&gt;

&lt;p&gt;In emergencies, quick access to accurate medical records can save lives. Blockchain ensures that records are up-to-date and tamper-proof, reducing the risk of errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interactive Element:&lt;/strong&gt; Think about a world where you control your medical data. You could grant temporary access to your records to a new doctor with just a few clicks. How would this change your experience with healthcare?&lt;/p&gt;

&lt;h2&gt;
  
  
  Voting Systems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How Does It Work?
&lt;/h3&gt;

&lt;p&gt;Blockchain-based voting systems allow citizens to cast their votes digitally. Each vote is recorded on the blockchain, making it nearly impossible to alter or delete.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Is It Important?
&lt;/h3&gt;

&lt;p&gt;Election integrity is a global concern. Blockchain can make elections more secure, transparent, and accessible, increasing trust in democratic processes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interactive Element:&lt;/strong&gt; Picture participating in an election where you can vote from the comfort of your home, and instantly verify that your vote has been counted correctly. How might this increase voter turnout and trust in the system?&lt;/p&gt;

&lt;h2&gt;
  
  
  Real Estate
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How Does It Work?
&lt;/h3&gt;

&lt;p&gt;Property transactions can be recorded on the blockchain, simplifying the process of buying and selling real estate. Smart contracts can automate and enforce the terms of agreements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Is It Important?
&lt;/h3&gt;

&lt;p&gt;Buying a house typically involves a lot of paperwork and intermediaries. Blockchain can streamline the process, reduce costs, and ensure that records are accurate and easily accessible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interactive Element:&lt;/strong&gt; Imagine being able to buy or sell property without the need for endless paperwork and multiple intermediaries. How would this change your experience with real estate transactions?&lt;/p&gt;

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

&lt;p&gt;Blockchain technology is revolutionizing various sectors by providing security, transparency, and efficiency. Its applications extend far beyond cryptocurrencies, offering solutions to some of the world's most pressing problems. From enhancing supply chain transparency to securing election integrity, blockchain is paving the way for a more reliable and efficient future.&lt;/p&gt;

&lt;p&gt;Happy Learning !&lt;/p&gt;

&lt;p&gt;Please do comment below if you like the content or not&lt;/p&gt;

&lt;p&gt;Have any questions or ideas or want to collaborate on a project, here is my &lt;a href="https://www.linkedin.com/in/abhinav-yadav-7891aby/" rel="noopener noreferrer"&gt;linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>cryptocurrency</category>
      <category>ethereum</category>
      <category>bitcoin</category>
    </item>
  </channel>
</rss>
