<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[ChatGPT &amp; Me - Medium]]></title>
        <description><![CDATA[Publication dedicated to - Medium]]></description>
        <link>https://medium.com/chatgpt-me?source=rss----6bdcf3535108---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>ChatGPT &amp;amp; Me - Medium</title>
            <link>https://medium.com/chatgpt-me?source=rss----6bdcf3535108---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:40:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/chatgpt-me" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ChatGPT & Me — Part 2: Learning a new concept from scratch using ChatGPT in 1 hour & applying it]]></title>
            <link>https://medium.com/chatgpt-me/chatgpt-me-part-2-learning-a-new-concept-from-scratch-using-chatgpt-in-1-hour-applying-it-9354e328a28e?source=rss----6bdcf3535108---4</link>
            <guid isPermaLink="false">https://medium.com/p/9354e328a28e</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ab-testing]]></category>
            <category><![CDATA[ab-test]]></category>
            <dc:creator><![CDATA[Daniel Riad]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 00:36:55 GMT</pubDate>
            <atom:updated>2023-04-04T16:33:14.468Z</atom:updated>
            <content:encoded><![CDATA[<h3>ChatGPT &amp; Me — Part 2: Learning a new concept from scratch using ChatGPT in 1 hour &amp; applying it</h3><p>Learning the basics of A/B Testing from scratch</p><h3>Motivation</h3><p>As a Data Scientist by profession, I have to keep my knowledge sharp on new and various topics all the time, and I am always on the lookout for making this process more efficient.</p><p>One topic that I’ve only heard about very often, but do not have any pre-existing knowledge on is A/B Testing, and that’s just due to the fact that I have not needed it so far in any of my work, as it’s more popular for “product data scientists” and data scientists working in Marketing &amp; Advertising in general. Nevertheless, I’ve never gotten around to dig deeper into it. Today, I will be attempting and logging a live experiment here, where I’ll attempt to learn as much as I can (from absolute scratch) about A/B testing, relying solely on ChatGPT, in less than an hour. I’ll put my knowledge to the test afterwards, and apply it practically.</p><p>Regardless of the outcome, I think this would give us a better insight on how effective ChatGPT could be in education, up-skilling, and learning new topics &amp; skills from scratch.</p><p><strong>TL;DR</strong>: I attempt to ask ChatGPT as many questions as possible about A/B testing starting from scratch in 1 hour, and I attempt to analyze the results of an A/B test conducted on a game, which is available on <a href="https://www.kaggle.com/datasets/yufengsui/mobile-games-ab-testing">Kaggle</a>, I managed to grasp the basic concepts of A/B testing and apply it successfully to a dataset.</p><p>Here’s a documentation of my 1 Hour learning session with ChatGPT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*wEcOmTUNSbMVsgQP.gif" /></figure><p>Q1: Please explain in the most basic terms what A/B Testing is</p><blockquote>A/B testing, in the most basic terms, is a way to compare two different versions of something to find out which one works better. You show version A to one group of people and version B to another group, then measure how well each version achieves a specific goal, like getting more people to click a button or buy a product. Based on the results, you can decide which version is more effective and use that one moving forward.</blockquote><p>Q2: What are the typical use cases for A/B testing?</p><blockquote>A/B testing is typically used to optimize and improve various aspects of digital products, marketing campaigns, and user experiences. Here are some common use cases for A/B testing:</blockquote><blockquote>Website design: Testing different layouts, colors, fonts, or navigation elements to improve user experience and increase engagement or conversions.</blockquote><blockquote>Landing pages: Comparing different headlines, images, copy, or call-to-action buttons to optimize conversion rates for sign-ups, purchases, or other desired actions.</blockquote><blockquote>Email marketing: Testing various subject lines, email content, images, or send times to enhance open rates, click-through rates, and overall campaign effectiveness.</blockquote><blockquote>Mobile app interfaces: Evaluating different designs, navigation structures, or features to improve user satisfaction, engagement, and retention.</blockquote><blockquote>Advertising: Comparing ad creatives, headlines, images, or targeting options to optimize ad performance, click-through rates, and return on ad spend.</blockquote><blockquote>Pricing strategies: Testing different pricing plans, promotional offers, or discount structures to maximize revenue and customer acquisition.</blockquote><blockquote>Product features: Assessing the impact of new features, functionality, or design changes on user engagement, satisfaction, and retention.</blockquote><blockquote>These use cases highlight how A/B testing can be employed across various domains to make data-driven decisions, optimize resources, and enhance overall performance.</blockquote><p>Q3: What skills do I need to have to be able to design A/B experiments?</p><blockquote>Understanding of the scientific method: A strong grasp of the scientific method and experimental design principles is essential to create controlled experiments, form hypotheses, and draw meaningful conclusions.</blockquote><blockquote>Statistical knowledge: Familiarity with basic statistical concepts such as significance levels, sample sizes, confidence intervals, and hypothesis testing helps you analyze results and make data-driven decisions.</blockquote><blockquote>Data analysis: Proficiency in analyzing data using tools like Excel, Google Sheets, or programming languages like Python or R is crucial for processing and interpreting experiment results.</blockquote><blockquote>Web analytics: Knowledge of web analytics tools like Google Analytics or Adobe Analytics is essential for tracking user behavior and measuring the impact of your A/B tests.</blockquote><blockquote>Technical skills: Basic HTML, CSS, and JavaScript skills can be useful for implementing and troubleshooting A/B tests, particularly if you’re working with web pages or applications.</blockquote><blockquote>Familiarity with testing tools: Experience with A/B testing tools such as Optimizely, VWO, or Google Optimize helps you design, execute, and analyze experiments more efficiently.</blockquote><blockquote>Problem-solving: The ability to identify issues, generate hypotheses, and devise creative solutions is vital for designing effective A/B tests.</blockquote><blockquote>Attention to detail: Meticulousness in designing, implementing, and analyzing experiments ensures accurate results and reduces the likelihood of errors.</blockquote><blockquote>Communication skills: Clear and concise communication is essential when sharing experiment goals, hypotheses, results, and recommendations with stakeholders.</blockquote><blockquote>Curiosity and adaptability: A curious mindset and willingness to learn and adapt to new tools, techniques, and best practices contribute to successful A/B testing.</blockquote><blockquote>Having these skills will enable you to design and conduct A/B experiments effectively, leading to data-driven insights and improved decision-making.</blockquote><p>Q4:Can you give me an example problem where A/B testing would be useful, and how you as a “Data Scientist” would solve it?</p><blockquote>Problem: An e-commerce company wants to increase the conversion rate on its product pages. They believe that changing the “Add to Cart” button’s color might have an impact on the number of users who click the button and make a purchase.</blockquote><blockquote>As a data scientist, here’s how I would approach solving this problem using A/B testing:</blockquote><blockquote>Define the objective: The primary goal is to increase the conversion rate, which is the percentage of users who click the “Add to Cart” button and make a purchase.</blockquote><blockquote>Form a hypothesis: For example, the hypothesis could be that changing the “Add to Cart” button color from green to red will result in a higher conversion rate.</blockquote><blockquote>Select key performance indicators (KPIs): The main KPI in this case is the conversion rate, but you might also track other metrics such as click-through rate or average order value to gain additional insights.</blockquote><blockquote>Choose the control and variant groups: The control group will see the existing green “Add to Cart” button, while the variant group will see the red “Add to Cart” button.</blockquote><blockquote>Calculate the required sample size: Determine the appropriate sample size for each group based on your desired statistical significance, power, and minimum detectable effect.</blockquote><blockquote>Randomly assign users: Randomly assign an equal number of users to the control and variant groups to ensure unbiased results.</blockquote><blockquote>Conduct the experiment: Run the A/B test for a predetermined period or until you’ve reached the required sample size. Make sure to avoid any changes to the website during the testing period to prevent confounding factors.</blockquote><blockquote>Analyze the results: Compare the conversion rates between the control and variant groups using statistical tests, such as a t-test or chi-square test, to determine if there’s a significant difference.</blockquote><blockquote>Draw conclusions: If the red “Add to Cart” button results in a significantly higher conversion rate, you might conclude that the hypothesis is supported and consider implementing the change on the website. If there’s no significant difference or the green button performs better, you might reconsider the hypothesis or test other factors that could impact the conversion rate.</blockquote><blockquote>Share findings and recommendations: Communicate the results of the A/B test to stakeholders and provide actionable insights and recommendations based on the findings.</blockquote><blockquote>Remember that A/B testing is an iterative process, and you might need to conduct multiple tests to optimize the conversion rate effectively. This example demonstrates how a data scientist would approach an A/B testing problem and use the results to inform data-driven decisions.</blockquote><p>Q5: Could you elaborate more on step number 5? how could I decide on the sample size?</p><blockquote>Deciding on the sample size for an A/B test is an essential step to ensure the validity and reliability of your results. To determine the appropriate sample size, you’ll need to consider three primary factors: statistical significance, statistical power, and minimum detectable effect.</blockquote><blockquote>Statistical significance: This is the probability of detecting a true difference between the control and variant groups when one actually exists. Commonly used significance levels are 0.05 (5%) or 0.01 (1%), which correspond to a 95% or 99% confidence level, respectively.</blockquote><blockquote>Statistical power: This is the probability of correctly rejecting the null hypothesis when it’s false, or the likelihood of detecting a true effect. A typical value for statistical power is 0.8 (80%), which means there’s an 80% chance of detecting a true difference if it exists.</blockquote><blockquote>Minimum detectable effect (MDE): This represents the smallest effect size (difference between the control and variant groups) you want to be able to detect in your test. The MDE should be meaningful and impactful for your business goals. Smaller MDEs require larger sample sizes to detect, while larger MDEs require smaller sample sizes.</blockquote><blockquote>To calculate the required sample size, you can use a sample size calculator designed for A/B testing, such as those provided by Optimizely, Evan Miller’s calculator, or use statistical software like R or Python libraries (e.g., statsmodels).</blockquote><blockquote>Here’s a general outline of the process:</blockquote><blockquote>Choose the desired statistical significance level (alpha), typically 0.05 or 0.01.</blockquote><blockquote>Select the desired statistical power, commonly 0.8.</blockquote><blockquote>Estimate the baseline conversion rate (current conversion rate) for the control group.</blockquote><blockquote>Define the minimum detectable effect as a percentage of the baseline conversion rate.</blockquote><blockquote>Input these values into a sample size calculator or statistical software to calculate the required sample size per group (control and variant).</blockquote><blockquote>Remember that the calculated sample size is for each group (control and variant), so the total number of users in the experiment will be twice the calculated sample size.</blockquote><blockquote>Keep in mind that larger sample sizes increase the likelihood of detecting smaller effects, but they also require more time and resources to collect. Therefore, it’s essential to strike a balance between the desired sensitivity and the practical constraints of your A/B testing scenario.</blockquote><p>Q6: How can I analyze the results I get from an A/B testing experiment on a specific KPI? to know whether the results are stastically significant?</p><blockquote>To analyze the results of an A/B testing experiment for a specific Key Performance Indicator (KPI) and determine whether the results are statistically significant, you can follow these steps:</blockquote><blockquote>Define the KPI: Clearly define the KPI you want to analyze (e.g., conversion rate, click-through rate, average session duration).</blockquote><blockquote>Choose the appropriate statistical test: Select a statistical test based on the nature of your KPI (categorical or numerical) and the distribution of your data (normal or non-normal).</blockquote><blockquote>For categorical KPIs (e.g., conversion rate): Use the two-proportion z-test or Chi-square test.</blockquote><blockquote>For numerical KPIs (e.g., average session duration) with normal distribution and equal variances: Use the independent two-sample t-test.</blockquote><blockquote>For numerical KPIs with non-normal distribution or unequal variances: Use the Mann-Whitney U test.</blockquote><blockquote>Set a significance level: Choose a significance level (alpha) for your test, which is typically 0.05 or 0.01. This value represents the probability of rejecting the null hypothesis when it is true (Type I error).</blockquote><blockquote>Perform the chosen statistical test: Use a statistical software or programming language (e.g., Python, R) to perform the chosen test on your data. This will provide you with a test statistic and a p-value.</blockquote><blockquote>Interpret the results: Compare the p-value obtained from the test with your chosen significance level (alpha). If the p-value is less than alpha, the difference between the two groups (A and B) is considered statistically significant, meaning that the observed difference in the KPI is not likely due to chance. If the p-value is greater than or equal to alpha, the difference is not statistically significant, and you cannot confidently conclude that one group is better than the other based on the available data.</blockquote><blockquote>Consider practical significance: In addition to statistical significance, it’s essential to evaluate the practical significance of the results. Even if a difference is statistically significant, it may not be practically meaningful if the effect size is very small. Calculate the effect size (e.g., Cohen’s d for the t-test, odds ratio for the Chi-square test) and determine if the observed difference is large enough to justify implementing the change in your product or process.</blockquote><blockquote>Remember to also account for factors like sample size and test duration when interpreting the results of your A/B test, as they can influence the validity of your findings.</blockquote><p>6 Questions &amp; 1 hour later of asking questions &amp; digesting all of the answers, I think that I now have a basic understanding of A/B testing, what the necessary measures are to conduct an A/B test, and how to analyze the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*IMLNDxYKuA5Sw2RK.gif" /></figure><p>In order to test my knowledge, I decided to try to analyze this <a href="https://www.kaggle.com/datasets/yufengsui/mobile-games-ab-testing">dataset</a> that I found on Kaggle which contains the results of an A/B test on users of a mobile game.</p><p>Attributes in the dataset:</p><ul><li>userid (Numeric): unique identifier of the user playing the game</li><li>version (Categorical/Boolean): describes whether the user was shown the “control group” (gate_30, where the user is shown a gate at level_30) version, or whether the user was a part of the test group (gate_40, where the user is shown the gate at level_40).</li><li>sum_gamerounds (Numeric): The number of games played by the player during the first 14 days after installing it.</li><li>retention_1 (Boolean): Did the user re-play the game 1 day after installing it?</li><li>retention_7 (Boolean): Did the user re-play the game 7 days after installing it?</li></ul><p>The three questions that we could potentially answer from this dataset are the following (from my understanding so far):</p><ul><li>Whether <em>changing the gate to be shown at level 40</em> (version=gate_40) in the game has a <strong>statistically significant impact </strong>on<em> the number of game rounds played by the user in the first 14 days </em>after installing it (“sum_gamerounds”)?</li><li>Whether <em>changing the gate to be shown at level 40</em> (version=gate_40) in the game has a <strong>statistically significant impact </strong>on whether or not <em>the user re-plays the game 1 day after installing it </em>(“retention_1”)?</li><li>Whether <em>changing the gate to be shown at level 40</em> (version=gate_40) in the game has a <strong>statistically significant impact </strong>on whether or not the <em>user re-plays the game 7 days after installing it</em> (“retention_7”)?</li></ul><p>I’ll be attempting to answer those questions to the best of my understanding using python.</p><h3><strong>Exploratory Data Analysis (EDA)</strong></h3><p>First of all I will try to understand, if there’s a difference that is “significant” (not necessarily statistical) for each of the KPIs, by plotting the differences in basic graphs, to get a better feeling of the data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nmmTTFTvm89bu4EZSDZ0wQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQkklXWJ-zbBnHi7BBjSCg.png" /><figcaption>Comparison of percentage of users who returned after 1 day of installing the game (left) &amp; 7 days of installing the game (right) for the control group “gate_30” and the test group “gate_40”</figcaption></figure><p>Here are some stats using, pandas “describe” function, to show some basic stats of the column “sum_gamerounds” for the control group (gate_30):</p><pre>count    44700.000000<br>mean        52.456264<br>std        256.716423<br>min          0.000000<br>25%          5.000000<br>50%         17.000000<br>75%         50.000000<br>max      49854.000000<br>Name: sum_gamerounds, dtype: float64</pre><p>Same stats for the “sum_gamerounds” for the test group (gate_40):</p><pre>count    45489.000000<br>mean        51.298776<br>std        103.294416<br>min          0.000000<br>25%          5.000000<br>50%         16.000000<br>75%         52.000000<br>max       2640.000000</pre><p>First guess from EDA (without using any statistics): There does not seem to be much benefit that could potentially be gained by changing the gate from level 30 to level 40 for all three KPIs measured, as the numbers seem to be very similar. My first intuition as a data scientist (with no particular experience in A/B testing) would be that we do not even have to do any statistical tests further, but rather look into either <em>trying out a new hypothesis </em>to retain the user or <em>changing the KPIs.</em></p><p>For the sake of this exercise however, I’ll go about conducting the statistical tests, as recommended by our good friend ChatGPT, and see what the results look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*GRgM8_Hoj_J3bKbw.gif" /><figcaption>My feeling, after analyzing the results…</figcaption></figure><h3><strong>Statistical Significance Tests</strong></h3><p>We’ll start with our 2 categorical KPIs, namely “retention_1” &amp; “retention7”.</p><p>According to ChatGPT’s answer “For categorical KPIs (e.g., conversion rate): Use the two-proportion z-test or Chi-square test.”</p><p>Since I am more familiar with Chi-square test, and how to conduct it in python using scipy, I’ll go ahead &amp; conduct the test for both KPIs:</p><pre>kpi = &quot;retention_1&quot;<br>#creating the contingency table containing the counts of both groups against the True/False Value counts of the KPI<br>contingency_table = df.groupby([&#39;version&#39;, kpi])[&#39;userid&#39;].nunique().unstack()<br>chi2, p_value, _, _ = chi2_contingency(contingency_table)<br>alpha = 0.05  # Set the significance level<br><br>if p_value &lt; alpha:<br>    print(&quot;The difference in proportions of &#39;True&#39; values between the categories is statistically significant (p-value =&quot;, p_value, &quot;)&quot;)<br>else:<br>    print(&quot;The difference in proportions of &#39;True&#39; values between the categories is not statistically significant (p-value =&quot;, p_value, &quot;)&quot;)</pre><p>I ran it once for the KPI “retention_1” and another time for the KPI “retention_7” and p_value threshold = 0.05.</p><p>The results came through as follows:</p><ul><li>The difference for “retention_1” is not statistically significant. This means we cannot reject the null hypothesis, meaning that <strong>we cannot say whether or not there is any impact of the introduction of the gate at level_40.</strong></li><li>The difference for “retention_7” is actually statistically significant. however the percentage of the users that came back after 7 days is more in the control group, rather than the test group. This means that we could confidently say that <strong>it’s better for the users’ retention after 7 days to keep the gate as it is in level 30.</strong></li></ul><p>For the numerical KPI, namely “sum_gamerounds”. Here were ChatGPT’s guidelines:</p><blockquote>For numerical KPIs (e.g., average session duration) with normal distribution and equal variances: Use the independent two-sample t-test.</blockquote><blockquote>For numerical KPIs with non-normal distribution or unequal variances: Use the Mann-Whitney U test.</blockquote><p>I’ve tested for Normality both visually and using the shapiro test for normality, and the values are definitely not normally distributed. So we’ll go with the Mann-Whitney U test. I asked ChatGPT to even write the code this time to conduct this test, and I adjusted it a bit to fit the data.</p><pre>u_stat, p_value_u = stats.mannwhitneyu(df[df[&#39;version&#39;]==&#39;gate_40&#39;][&#39;sum_gamerounds&#39;], df[df[&#39;version&#39;]==&#39;gate_30&#39;][&#39;sum_gamerounds&#39;], alternative=&#39;two-sided&#39;)<br><br># Check for statistical significance<br>if p_value_u &lt; alpha:<br>    print(&quot;Statistically significant&quot;)<br>else:<br>    print(&quot;Not statistically significant&quot;)</pre><p>The results are in: <em>“Not statistically Significant”.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*lCno3IuO4O3Jh3ev.gif" /></figure><h3>Final thoughts &amp; Verdict</h3><p>This was a very efficient learning experience for me, as I feel much more confident to talk about A/B testing to someone, and understand <strong>the basics of what is exactly an A/B test</strong>, when is it <strong>suitable,</strong> <strong>how to design it</strong> and how to <strong>interpret its results</strong>. I got all of this understanding in 1 hour, by asking the exact questions that I wanted to understand, and I also applied this knowledge on a dataset in another hour, and I am not exactly the “fastest learner.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*9q6JSr1L2PVJ2qgp.gif" /></figure><p>I personally see huge potential in how ChatGPT could revolutionize learning &amp; education at all levels. It gives the user the ability to have a customizable learning experience, and could help generate code/instructions for how to conduct a specific task, it even allows the user to ask follow up questions. Imagine how helpful this would be for someone who is more introverted and refrains from asking questions in a formal “classroom” setting. In my opinion, this could even help “democratize” knowledge and education to a great extent, and provide way more resources to the socially disadvantaged</p><p>On the other hand, in its current version, ChatGPT’s knowledge cannot be taken for granted always. As it tends to make some pretty fundamental mistakes every once in a while, and the dangerous part about it is, that it tends to be right about 99% of the time, making it really hard to tell when it is absolutely off. I am quite sure however, that there will be a lot of customized solutions based on GPT-4 &amp; similar models that introduce solutions to similar challenges.</p><p><em>Disclaimer: I attempted to learn the basics of A/B testing from scratch, however given my experience as a data scientist, and having a good feeling for data and statistics definitely gave me a huge edge in picking this up quickly.</em></p><p>If you liked this article, make sure to follow me &amp; this publication, and have a look at my <a href="https://medium.com/chatgpt-me/chatgpt-me-375991351996">previous article</a>, where I attempt to solve programming problems from HackerRank using ChatGPT, and stay tuned for my upcoming ChatGPT experiments!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*z3JICU5Nhw0cft4L.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9354e328a28e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/chatgpt-me/chatgpt-me-part-2-learning-a-new-concept-from-scratch-using-chatgpt-in-1-hour-applying-it-9354e328a28e">ChatGPT &amp; Me — Part 2: Learning a new concept from scratch using ChatGPT in 1 hour &amp; applying it</a> was originally published in <a href="https://medium.com/chatgpt-me">ChatGPT &amp; Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ChatGPT & Me — Part 1: Solving programming problems & Interview Questions]]></title>
            <link>https://medium.com/chatgpt-me/chatgpt-me-375991351996?source=rss----6bdcf3535108---4</link>
            <guid isPermaLink="false">https://medium.com/p/375991351996</guid>
            <category><![CDATA[hackerrank]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[programming-interviews]]></category>
            <dc:creator><![CDATA[Daniel Riad]]></dc:creator>
            <pubDate>Mon, 13 Mar 2023 01:44:49 GMT</pubDate>
            <atom:updated>2023-03-17T21:30:32.811Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Motivation</strong>: Unless you’ve been living under a rock for the last couple of months, you must’ve heard about ChatGPT either from the news, random youtube videos, or from your social circle. You probably heard people describing it as <strong>“scary”</strong>, <strong>“disruptive”</strong> or even straight <strong>“BS”</strong>. In this publication I’ll be documenting my experiments using ChatGPT, trying to push its boundaries, unpacking its capabilities, and looking beyond the hype.</p><p><strong>TL;DR:</strong> I tried using ChatGPT to solve programming problems and typical interview questions with various levels of difficulty, from websites such as HackerRank. The results are mind blowing to say the least especially for easy and medium problems. It also was an eye opener on how much of an impact detailed prompts have on the quality of the output, especially that the description of such problems is formally very well written on websites such as HackerRank and the like.</p><h3><strong>ChatGPT solving software developer interview problems:</strong></h3><h4>Problem 1 :Finding the missing element in an array (Difficulty Level — Easy):</h4><h4><strong>Input Prompt:</strong></h4><blockquote><em>“Given an array of size N-1 such that it only contains distinct integers in the range of 1 to N. Find the missing element.</em></blockquote><blockquote><em>Example 1:</em></blockquote><blockquote>Input:<br>N = 5<br>A[] = {1,2,3,5}<br>Output: 4</blockquote><blockquote><em>Example 2:</em></blockquote><blockquote>Input:<br>N = 10<br>A[] = {6,1,2,8,3,4,7,10,5}<br>Output: 9</blockquote><blockquote><em>Your Task :<br>You don&#39;t need to read input or print anything. Complete the function MissingNumber() that takes array and N as input parameters and returns the value of the missing number.”</em></blockquote><blockquote><strong>Output:</strong></blockquote><blockquote>To solve this problem, we can use the fact that the sum of integers from 1 to N is N*(N+1)/2. If we add up all the elements in the array, we can subtract this sum from the expected sum to find the missing number.</blockquote><blockquote>Algorithm:</blockquote><blockquote>Initialize a variable “expected_sum” to N*(N+1)/2</blockquote><blockquote>Iterate over the elements in the array and add them up to a variable “actual_sum”</blockquote><blockquote>Return the difference between “expected_sum” and “actual_sum”, which is the missing number.</blockquote><blockquote>Here’s the implementation of the algorithm in Python:</blockquote><blockquote>def MissingNumber(array, N):</blockquote><blockquote>expected_sum = N*(N+1)//2</blockquote><blockquote>actual_sum = sum(array) return expected_sum — actual_sum</blockquote><p><strong>Rating: 4.5/5</strong></p><p>The solution generated is great on so many levels. The steps of the algorithm were perfectly explained. It solved it in (according to my knowledge) the most efficient way, it also returned the proper output for the test cases given, and even generated extra test cases (disclaimer: I did not copy this part to avoid making the post extremely long). I gave it only a 4.5, as it outputted the python code, without indenting the lines in the proper way, which is surprising as it usually does it perfectly. Extra: If you ask it to transform the code in another programming language, it does so perfectly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*kpKLXcf4q4Imr7E24BKNzg.gif" /><figcaption>How my fellow developers must be feeling!</figcaption></figure><h3><strong>Problem 2: Lexicographical Order (Difficulty Level — Medium):</strong></h3><p>Disclaimer: This is a problem from the website <a href="https://www.hackerrank.com/challenges/bigger-is-greater/problem?isFullScreen=true">HackerRank</a>. I’ve copied the problem description as an input prompt to hacker rank, as follows:</p><p><strong>Input Prompt:</strong></p><blockquote><em>“Lexicographical order is often known as alphabetical order when dealing with strings. A string is greater than another string if it comes later in a lexicographically sorted list. Given a word, create a new word by swapping some or all of its characters. This new word must meet two criteria: It must be greater than the original word It must be the smallest word that meets the first condition Example w=abcd, The next largest word is abdc. Complete the function biggerIsGreater below to create and return the new string meeting the criteria. If it is not possible, return no answer.</em></blockquote><blockquote><strong><em>Function Description</em></strong></blockquote><blockquote><em>Complete the biggerIsGreater function in the editor below. biggerIsGreater has the following parameter(s):</em></blockquote><blockquote><em>string w: a word</em></blockquote><blockquote><em>Returns — string: the smallest lexicographically higher string possible or no answer</em></blockquote><blockquote><em>Input Format The first line of input contains , the number of test cases. Each of the next lines contains .</em></blockquote><blockquote><em>Constraints will contain only letters in the range ascii[a..z].</em></blockquote><blockquote><strong><em>Sample Input</em></strong><em> 0 5 ab bb hefg dhck dkhc</em></blockquote><blockquote><strong><em>Sample Output </em></strong><em>0 ba no answer hegf dhkc hcdk</em></blockquote><blockquote><em>Explanation</em></blockquote><blockquote><em>Test case 1: ba is the only string which can be made by rearranging ab. It is greater.</em></blockquote><blockquote><em>Test case 2: It is not possible to rearrange bb and get a greater string.</em></blockquote><blockquote><em>Test case 3: hegf is the next string greater than hefg.</em></blockquote><blockquote><em>Test case 4: dhkc is the next string greater than dhck.</em></blockquote><blockquote><em>Test case 5: hcdk is the next string greater than dkhc.</em></blockquote><blockquote><em>Sample Input 1 6 lmno dcba dcbb abdc abcd fedcbabcd</em></blockquote><blockquote><em>Sample Output 1 lmon no answer no answer acbd abdc fedcbabdc”</em></blockquote><p><strong>Output:</strong></p><blockquote>Solution:</blockquote><blockquote>To create a lexicographically larger string from the given string, we need to find the rightmost character which is smaller than its next character. We call the index of this character “pivot.” Then we need to find the smallest character to the right of the pivot, which is greater than the pivot. We call the index of this character “swap.” Then we swap the characters at pivot and swap indices and sort the substring to the right of the pivot index in ascending order. If no such pivot exists, we return “no answer.”</blockquote><blockquote>For example, let’s say we have the string “abcd” and we want to find the next lexicographically larger string. The pivot index is 2 (the character ‘c’) because ‘c’ is smaller than ‘d’ and there is no smaller character to its right. The swap index is 3 (the character ‘d’) because ‘d’ is the smallest character to the right of the pivot that is greater than the pivot. We swap the characters at indices 2 and 3, giving us the string “abdc.” Finally, we sort the substring to the right of the pivot index in ascending order, which gives us the final string “abdc.”</blockquote><blockquote>Implementation:</blockquote><pre>def biggerIsGreater(w):<br>    # Convert the string to a list of characters for easy manipulation<br>    s = list(w)   # Find the pivot index<br>    pivot = -1<br>    for i in range(len(s) - 1):<br>        if s[i] &lt; s[i + 1]:<br>            pivot = i    # If no pivot exists, the string cannot be rearranged<br>    if pivot == -1:<br>        return &quot;no answer&quot;<br># Find the swap index<br>    swap = -1<br>    for j in range(len(s) - 1, pivot, -1):<br>        if s[j] &gt; s[pivot]:<br>            swap = j<br>            break<br>    # Swap the characters at pivot and swap indices<br>    s[pivot], s[swap] = s[swap], s[pivot]<br>    # Reverse the substring to the right of the pivot index<br>    s[pivot + 1:] = reversed(s[pivot + 1:])<br>    # Convert the list back to a string and return it<br>    return &quot;&quot;.join(s)<br># Testing the function with the given sample inputs<br>print(biggerIsGreater(&quot;ab&quot;))  # Expected output: ba<br>print(biggerIsGreater(&quot;bb&quot;))  # Expected output: no answer<br>print(biggerIsGreater(&quot;hefg&quot;))  # Expected output: hegf<br>print(biggerIsGreater(&quot;dhck&quot;))  # Expected output: dhkc<br>print(biggerIsGreater(&quot;dkhc&quot;))  # Expected output: hcdk</pre><p><strong>Rating: 5/5</strong></p><p>It solved the problem PERFECTLY, giving a great explanation of the algorithm, and outputting a python function that does exactly the job, and passes every test on HackerRank with flying colours:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GnvFpGadKiD7Z5JbmgczA.png" /><figcaption>Output after submitting the solution on HackerRank blindly</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*hQWbeb_u_16YRkOeHdbr0Q.gif" /><figcaption>PoV — You’re a developer and it took you sometime to understand the problem.</figcaption></figure><p>Last but not least, I wanted to try out how it would handle a hard problem from HackerRank, which a non-seasoned junior developer would have a really hard time solving — Spoiler Alert: The results are not what you’d expect.</p><h3><strong>Problem 3: String Similarity (Difficulty Level: Hard)</strong></h3><p>Disclaimer: This is another problem from the website <a href="https://www.hackerrank.com/challenges/string-similarity/problem?isFullScreen=true">HackerRank</a>, I’ve copied the problem description as an input prompt to hacker rank, as follows:</p><p><strong>Input Prompt:</strong></p><blockquote>“For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings “abc” and “abd” is 2, while the similarity of strings “aaa” and “aaab” is 3.</blockquote><blockquote>Calculate the sum of similarities of a string S with each of it’s suffixes.</blockquote><blockquote><strong>Input Format</strong></blockquote><blockquote>The first line contains the number of test cases t.<br>Each of the next t lines contains a string to process, .</blockquote><blockquote><strong>Constraints</strong></blockquote><blockquote>is composed of characters in the range ascii[a-z]</blockquote><blockquote><strong>Output Format</strong></blockquote><blockquote>Output t lines, each containing the answer for the corresponding test case.</blockquote><blockquote><strong>Sample Input</strong></blockquote><blockquote>2<br>ababaa <br>aa</blockquote><blockquote><strong>Sample Output</strong></blockquote><blockquote>11 <br>3</blockquote><blockquote><strong>Explanation</strong></blockquote><blockquote>For the first case, the suffixes of the string are “ababaa”, “babaa”, “abaa”, “baa”, “aa” and “a”. The similarities of these strings with the string “ababaa” are 6,0,3,0,1, &amp; 1 respectively. Thus, the answer is 6 + 0 + 3 + 0 + 1 + 1 = 11.</blockquote><blockquote>For the second case, the answer is 2 + 1 = 3.”</blockquote><p>I also copied the sample code and just asked it to complete the respective function.</p><p><strong>Output:</strong></p><pre>def stringSimilarity(s):<br>    n = len(s)<br>    sum_similarity = 0<br>    for i in range(n):<br>        suffix = s[i:]<br>        similarity = 0<br>        for j in range(min(len(suffix), len(s))):<br>            if suffix[j] == s[j]:<br>                similarity += 1<br>            else:<br>                break<br>        sum_similarity += similarity<br>    return sum_similarity</pre><p>Evaluation: 3/5</p><p>It passes the initial sample cases however when I submit the solution, it passes only 5/12 Use Cases, where for the other there is a runtime error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qn6_ajtMoGoNwbF6o9e-ow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*XZsVVEveWcnndKeKDpx2Xw.gif" /><figcaption>PoV: Experienced Developers</figcaption></figure><p>In an unexpected turn of events, a few days after releasing this story, GPT-4 was released, the newer model from OpenAI, so I had to try this problem again, and update the story. Let’s see if anything would change.</p><p>Given the exact same prompt, using ChatGPT with GPT-4, available only using ChatGPT Plus subscription, at the time of writing this story. We get the following <strong>output</strong>:</p><pre>def stringSimilarity(s):<br>    total_similarity = len(s)<br>    <br>    for i in range(1, len(s)):<br>        suffix = s[i:]<br>        j = 0<br>        while j &lt; len(suffix) and s[j] == suffix[j]:<br>            j += 1<br>        total_similarity += j<br>    <br>    return total_similarity</pre><p>When I copy and paste this code to HackerRank, it passes 6/12 Use Cases. It fails the other 6 due to a “TimeOut Error”, probably due to a lack of efficiency of the code.</p><p>I then ask ChatGPT, if it could make the code more efficient, and it most certainly does:</p><p><strong>Input:</strong></p><blockquote>can you make it more efficient? in terms of complexity?</blockquote><p>Output:</p><blockquote>Yes, we can make it more efficient by using Z-algorithm to compute the Z-array, which can be used to find the sum of the similarities more quickly. The Z-algorithm has a linear time complexity of O(n), making it more efficient compared to the previous implementation.</blockquote><blockquote>Here’s the updated code with the Z-algorithm:</blockquote><pre>import math<br>import os<br>import random<br>import re<br>import sys</pre><pre>def z_algorithm(s):<br>    n = len(s)<br>    z = [0] * n<br>    z[0] = n<br>    l, r = 0, 0</pre><pre>    for i in range(1, n):<br>        if i &gt; r:<br>            l, r = i, i<br>            while r &lt; n and s[r - l] == s[r]:<br>                r += 1<br>            z[i] = r - l<br>            r -= 1<br>        else:<br>            k = i - l<br>            if z[k] &lt; r - i + 1:<br>                z[i] = z[k]<br>            else:<br>                l = i<br>                while r &lt; n and s[r - l] == s[r]:<br>                    r += 1<br>                z[i] = r - l<br>                r -= 1<br>    return z</pre><pre>def stringSimilarity(s):<br>    z_values = z_algorithm(s)<br>    return sum(z_values)</pre><p>At this point curiosity killed me, before looking into the code, I copied it and pasted the solution again in HackerRank, and this happened:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1nPxr_TIevPOP-vTz6-igw.png" /><figcaption>GPT-4 resolves the hard problem after a few prompts!</figcaption></figure><p>Devs be like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/0*XbPapLDU5pGCfQCI" /></figure><p>If you’re as lazy as me, and couldn’t be bothered to go through the details of the Z-algorithm, I asked ChatGPT to explain it to us:</p><blockquote>Certainly! The Z-algorithm is a linear time string matching algorithm that efficiently constructs an array of equal length to the input string. This array, called the Z-array, stores the length of the longest common prefix between the input string and each of its suffixes. The primary use case for the Z-algorithm is pattern matching within a larger text.</blockquote><blockquote>Here’s a breakdown of the Z-algorithm:</blockquote><blockquote>Initialize an array z of length n (the length of the input string s), with all elements set to 0. Set z[0] = n because the entire string is always equal to itself.</blockquote><blockquote>Define two pointers, l (left) and r (right), both initialized to 0. These pointers define the current &quot;Z-box&quot; that we are working with: a substring that starts at position l and ends at position r.</blockquote><blockquote>Iterate through the string s from the second character (index 1) to the last character (index n-1). For each index i:</blockquote><blockquote>a. If i &gt; r, it means the current index is outside the Z-box. In this case, set both l and r to i. Then, compare characters starting from the current index i with the corresponding characters from the beginning of the string, and increment r until a mismatch is found. Update z[i] to the length of the matched substring (r - l) and decrement r by 1.</blockquote><blockquote>b. If i &lt;= r, it means the current index is inside the Z-box. Calculate k = i - l. Now, there are two possibilities:</blockquote><blockquote>i. If z[k] &lt; r - i + 1, it means the Z-value at index i is the same as the Z-value at index k. Update z[i] to z[k].</blockquote><blockquote>ii. If z[k] &gt;= r - i + 1, it means we need to perform further comparisons to determine the correct Z-value at index i. Set l to i, and compare characters starting from index r with the corresponding characters from the beginning of the string. Increment r until a mismatch is found, update z[i] to the length of the matched substring (r - l), and decrement r by 1.</blockquote><blockquote>After the loop finishes, the Z-array is complete and can be used for further processing.</blockquote><blockquote>The Z-algorithm’s time complexity is O(n), making it an efficient approach for solving string-related problems, such as pattern matching or calculating string similarities.</blockquote><h3><strong>Reflection</strong></h3><p>ChatGPT has performed significantly well on HackerRank type of problems (With an exception of the few test cases it hasn’t passed in the hard problems). This highlights how much of a role the detail level of the prompts correlate with the quality of the output, especially that the HackerRank problem descriptions are written in a great level of detail, in a highly structured manner and a lot of test case examples. In ChatGPT’s favour, all of the test cases described in the problem were passed in the String Similarity problem above. Most likely with more experience in prompt engineering, and writing better test cases, we could get it to correct the StringSimilarity code to pass all of the test cases.</p><p>To sum up:</p><blockquote>Great results come from great prompts!</blockquote><h3>The Verdict:</h3><p>I don’t think anyone could deny how powerful ChatGPT is in generating code with this quality, given that something like this was quite unthinkable a few months ago (at least for someone not working on cutting edge AI research). I am also sure that common “easier” everyday tasks, such as generating test cases, finding the bug in a code, or optimizing a function should be a walk in the park for GPT models in general. I am also aware that there is currently an extension in VSCode called <a href="https://marketplace.visualstudio.com/items?itemName=timkmecl.codegpt3#:~:text=Using%20the%20Extension,will%20be%20sent%20to%20GPT3.">CodeGPT</a>, which could help achieve such tasks.</p><blockquote>And now to address the elephant in the room:<strong> would this technology make developers’ jobs obsolete?</strong></blockquote><p><strong>In my personal opinion</strong>, no, quite unlikely, at least not in the short-term for most <strong>highly</strong> <strong>skilled</strong> developers. However, if a big chunk of your work has to do with writing simple automation scripts, macros or even slightly more complex functions…..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*uxCaQMdS8kJDm8AIpN-jGg.gif" /></figure><p>On the more optimistic side, I think this will serve as a great motive for developers to up-skill themselves, and will open up new opportunities for “prompt engineering” jobs.</p><p>Make sure you follow this publication and stay tuned for more exciting use cases &amp; experiments using ChatGPT in this publication!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=375991351996" width="1" height="1" alt=""><hr><p><a href="https://medium.com/chatgpt-me/chatgpt-me-375991351996">ChatGPT &amp; Me — Part 1: Solving programming problems &amp; Interview Questions</a> was originally published in <a href="https://medium.com/chatgpt-me">ChatGPT &amp; Me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>