<?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[Stories by Harshit Raj on Medium]]></title>
        <description><![CDATA[Stories by Harshit Raj on Medium]]></description>
        <link>https://medium.com/@Harshit_Raj_14?source=rss-785d0962c550------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3CUCvj1HL-OsSqoPfvBXAQ.png</url>
            <title>Stories by Harshit Raj on Medium</title>
            <link>https://medium.com/@Harshit_Raj_14?source=rss-785d0962c550------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 26 Jun 2026 07:05:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Harshit_Raj_14/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[134. Gas Station — LeetCode Medium Problem — Full Solution and approach explained]]></title>
            <link>https://medium.com/@Harshit_Raj_14/134-gas-station-leetcode-medium-problem-full-solution-and-approach-explained-daddfb4ab123?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/daddfb4ab123</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[google-interview-question]]></category>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[leetcode-medium]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Mon, 30 Dec 2024 21:20:11 GMT</pubDate>
            <atom:updated>2024-12-30T21:20:11.045Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://leetcode.com/problems/gas-station/">134. Gas Station</a> — LeetCode Medium Problem — Full Solution and approach explained</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*xl3knYqddu5hBafSYvHGCg.png" /><figcaption>134. Gas Station</figcaption></figure><h3>Problem Statement</h3><p>There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].</p><p>You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations.</p><p>Given two integer arrays gas and cost, return <em>the starting gas station&#39;s index if you can travel around the circuit once in the clockwise direction, otherwise return</em> -1. If there exists a solution, it is <strong>guaranteed</strong> to be <strong>unique</strong>.</p><p><strong>Example 1:</strong></p><pre>Input: gas = [1,2,3,4,5], cost = [3,4,5,1,2]<br>Output: 3<br>Explanation:<br>Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4<br>Travel to station 4. Your tank = 4 - 1 + 5 = 8<br>Travel to station 0. Your tank = 8 - 2 + 1 = 7<br>Travel to station 1. Your tank = 7 - 3 + 2 = 6<br>Travel to station 2. Your tank = 6 - 4 + 3 = 5<br>Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.<br>Therefore, return 3 as the starting index.</pre><p><strong>Example 2:</strong></p><pre>Input: gas = [2,3,4], cost = [3,4,3]<br>Output: -1<br>Explanation:<br>You can&#39;t start at station 0 or 1, as there is not enough gas to travel to the next station.<br>Let&#39;s start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4<br>Travel to station 0. Your tank = 4 - 3 + 2 = 3<br>Travel to station 1. Your tank = 3 - 3 + 3 = 3<br>You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.<br>Therefore, you can&#39;t travel around the circuit once no matter where you start.</pre><h3>Problem Explanation</h3><p>Breaking the above problem statement we know that we need to find the starting gas station on a circular route where you can complete a full journey with the gas provided, when we deduct the travel costs.</p><p>Then we are asked to return the station’s index if travelling to the same gas station is possible; otherwise, return we return -1 if no solution exists.</p><blockquote><strong>In case you are wondering what’s a circular array?</strong></blockquote><blockquote>Here a circular route implies that we have a circular array. That means when you reach the end of the array(<em>n-1 index</em>) you start back from start(<em>0 index</em>). Just like a circle with no actual start or end.</blockquote><blockquote>In a way you can say that the last element and the first element are neighbors.</blockquote><h4>Ideas:</h4><p>1) The path is circular, i.e., a complete a full circle.</p><p>2) If the gasoline in all gas stations is less than the total fuel consumption of the route, it is impossible to complete the journey.</p><p>3) On the contrary, if the gasoline in all gas stations is greater than or equal to the total fuel consumption of the route, then there must be at least one station where you can start and complete the journey.</p><h3>Examples</h3><p>Let’s consider the following arrays for the dry run:</p><blockquote><strong>gas</strong> = [3, 0, 8, 2, 0, 0, 1]</blockquote><blockquote><strong>cost</strong> = [2, 3, 4, 1, 2, 1, 3]</blockquote><p>We need to find the starting gas station index, where if we start at that index, we can complete the circuit once.</p><h4>Explanation:</h4><h4><strong>Start at station 2:</strong></h4><p>At each station, we can see the following:</p><blockquote><strong>Station 2:</strong> We start with 8 units of gas.</blockquote><blockquote><strong>Station 3:</strong> After traveling, the remaining gas is 4 + 2 (refill) — 1 (travel) = 5.</blockquote><blockquote><strong>Station 4:</strong> After traveling, the remaining gas is 5 + 0 (refill) — 2 (travel) = 3.</blockquote><blockquote><strong>Station 5:</strong> After traveling, the remaining gas is 3 + 0 (refill) — 1 (travel) = 2.</blockquote><blockquote><strong>Station 6:</strong> After traveling, the remaining gas is 2 + 1 (refill) — 3 (travel) = 0.</blockquote><blockquote><strong>Station 0:</strong> After traveling, the remaining gas is 0 + 3 (refill) — 2 (travel) = 1.</blockquote><blockquote><strong>Station 1:</strong> After traveling, the remaining gas is 1 + 0 (refill) — 3 (travel) = -2, which prevents completing the loop.</blockquote><p>We successfully made it back to station 0, so station 2 is a valid starting point.</p><h4>Output : 2</h4><h3>Constraints</h3><p>The given constraints are:</p><ul><li>n == gas.length == cost.length</li><li>1 &lt;= n &lt;=10^5</li><li>0 &lt;= gas[i], cost[i] &lt;= 10^4</li></ul><h4>Observations:</h4><p>The values of gas filled in your car and costs of travelling are all positive and lies in range between 0 and 10000. Makes sense, we can’t have <strong>-ve</strong> petrol being added in your car after all.</p><p>The key observation is in fact the size of array which lies between 0 and 100000. This implies the solution must handle up to 100,000 gas stations efficiently.</p><blockquote>A <strong>naive O(n²)</strong> approach will likely result in <strong>Time Limit Exceeded (TLE)</strong>. A much better solution that can be acceptable might be O(nlogn) or O(n).</blockquote><blockquote>But O(nlogn) -&gt; mostly refers to applying sorting techniques. Which in this case we know is not justifiable since we can’t change the order of gas stations.</blockquote><blockquote>So, the most feasible algorithm time complexity we can think of is O(n). Which generally happens in scenarios of <em>linear search, two pointers, hashing, </em><strong><em>greedy</em></strong><em> or array manipulation techniques.</em></blockquote><p>Hence the idea time complexity for the solution for the problem we will be looking at will be O(n).</p><h3>BRUTE FORCE</h3><p>The first step to solving every coding problem is coming up with a brute force or the most simplest method to solve the problem.</p><h4>Intuition</h4><p>The most basic form of brute force is simulating the process in the problem.</p><p>Our idea is to try starting at every gas station and simulate the journey to check if completing the circuit is possible.</p><p>According to the problem, the formula for calculating the amount of remaining gasoline at each station is: currGas - cost[i] + gas[i+1].</p><blockquote>where,</blockquote><blockquote><em>currGas</em> -&gt; is the current gas available in the car</blockquote><blockquote><em>i</em> -&gt; represents the current gas station our car is on.</blockquote><p>It should be noted that if gas[i+1]the range exceeds the gas length, it needs to start from 0.</p><p>For every gas station we start our journey and check if we can reach back while fulfilling the condition that the gas inside the car never becomes less than 0 while travelling.</p><p>The car will only move forward when: currGas — cost[i] &gt;= 0</p><p>Otherwise, the car can’t reach the next gas station since gas will be over before.</p><h4>Approach</h4><p><strong>Step I: </strong>Start at every gas station index i.</p><p><strong>Step II:</strong> Simulate the journey track the remaining gas as you travel.</p><p><strong>Step III:</strong> Move to the next station, adjusting the remaining gas (currGas += gas[i] - cost[i]).</p><p><strong>Step IV:</strong> Use modulo (%) to handle the circular nature of the problem.</p><p>i.e., if(i&gt;n) i = (i % n)</p><p><strong>Step V:</strong> If at any point the gas becomes negative(i.e., currGas&lt;0), the journey fails for the current starting index.</p><p><strong>Step VI:</strong> If you can complete the circle, return the starting index. If no starting index works, return -1.</p><p>Dry Run</p><h3>Example:</h3><h4>Input:</h4><blockquote>gas = [1, 2, 3, 4, 5]<br>cost = [3, 4, 5, 1, 2]</blockquote><h4>Execution:</h4><p>● Start at station 0:</p><ul><li>Remaining gas after station 0: 1 - 3 = -2 (Fails)</li></ul><p>● Start at station 1:</p><ul><li>Remaining gas after station 1: 2 - 4 = -2 (Fails)</li></ul><p>● Start at station 2:</p><ul><li>Remaining gas after station 2: 3 - 5 = -2 (Fails)</li></ul><p>● Start at station 3:</p><ul><li>Remaining gas after station 3: 4 - 1 = 3</li><li>Remaining gas after station 4: 3 + 5 - 2 = 6</li><li>Remaining gas after station 0: 6 + 1 - 3 = 4</li><li>Remaining gas after station 1: 4 + 2 - 4 = 2</li><li>Remaining gas after station 2: 2 + 3 - 5 = 0 (Completes)</li><li>Success: Return 3.</li></ul><h4>Output : 3</h4><h3>Code : C++</h3><pre>// Approach: Find the starting gas station for a circular route<br>// Language: C++<br><br>#include &lt;iostream&gt;<br>#include &lt;vector&gt;<br>using namespace std;<br><br>// Class to solve the gas station circuit problem<br>class GasStationCircuit {<br><br>public:<br>    // Function to find the starting gas station<br>    int CanCompleteCircuit(vector&lt;int&gt;&amp; gas, vector&lt;int&gt;&amp; cost) {<br>        int n = gas.size();  // Number of stations<br><br>        // Try starting from each gas station<br>        for (int start = 0; start &lt; n; start++) {<br>            int remaining_gas = 0;  <br>            bool completed = true;  <br><br>            // Simulate the journey<br>            for (int i = 0; i &lt; n; i++) {<br>                int current_station = (start + i) % n;<br><br>                remaining_gas += gas[current_station] - cost[current_station];<br><br>                // If remaining gas is negative, this start fails<br>                if (remaining_gas &lt; 0) {<br>                    completed = false;<br>                    break;<br>                }<br>            }<br><br>            // If the circuit is completed, return the start station<br>            if (completed) {<br>                return start;<br>            }<br>        }<br><br>        // If no valid starting station is found, return -1<br>        return -1;<br>    }<br>};<br><br>// Main function<br>int main() {<br>    // Create an instance of the class<br>    GasStationCircuit circuit;<br><br>    // Gas and cost arrays for the circuit<br>    vector&lt;int&gt; gas = {1, 2, 3, 4, 5};<br>    vector&lt;int&gt; cost = {3, 4, 5, 1, 2};<br><br>    // Find and display the starting station<br>    int result = circuit.CanCompleteCircuit(gas, cost);<br>    cout &lt;&lt; &quot;Starting station: &quot; &lt;&lt; result &lt;&lt; endl;<br><br>    return 0;<br>}</pre><h3>Code : Java</h3><pre>// Approach: Find the starting gas station for a circular route<br>// Language: Java<br><br>public class GasStationCircuit {<br><br>    // Method to find the starting gas station<br>    public int canCompleteCircuit(int[] gas, int[] cost) {<br>        // Initialize the number of stations<br>        int n = gas.length;<br><br>        // Try starting from each gas station<br>        for (int start = 0; start &lt; n; start++) {<br>            // Track the remaining gas during the journey<br>            int remainingGas = 0;<br><br>            // Flag to check if the journey is completed<br>            boolean completed = true;<br><br>            // Simulate the journey<br>            for (int i = 0; i &lt; n; i++) {<br>                int currentStation = (start + i) % n;<br><br>                // Update remaining gas after traveling<br>                remainingGas += gas[currentStation] - cost[currentStation];<br><br>                // If remaining gas is negative, this start fails<br>                if (remainingGas &lt; 0) {<br>                    completed = false;<br>                    break;<br>                }<br>            }<br><br>            // If the circuit is completed, return the start station<br>            if (completed) {<br>                return start;<br>            }<br>        }<br><br>        // If no valid starting station is found, return -1<br>        return -1;<br>    }<br><br>    public static void main(String[] args) {<br>        // Create an instance of the class<br>        GasStationCircuit circuit = new GasStationCircuit();<br><br>        // Gas and cost arrays for the circuit<br>        int[] gas = {1, 2, 3, 4, 5};<br>        int[] cost = {3, 4, 5, 1, 2};<br><br>        // Find and display the starting station<br>        int result = circuit.canCompleteCircuit(gas, cost);<br>        System.out.println(&quot;Starting station: &quot; + result);<br>    }<br>}</pre><h3>Code : Python</h3><pre># Approach: Find the starting gas station for a circular route<br># Language: Python<br><br>class GasStationCircuit:<br>    <br>    # Function to find the starting gas station<br>    def can_complete_circuit(self, gas, cost):<br>        n = len(gas)  # Number of stations<br><br>        # Try starting from each gas station<br>        for start in range(n):<br>            remaining_gas = 0  <br>            completed = True  <br><br>            # Simulate the journey<br>            for i in range(n):<br>                current_station = (start + i) % n<br><br>                remaining_gas += gas[current_station] - cost[current_station]<br><br>                # If remaining gas is negative, this start fails<br>                if remaining_gas &lt; 0:<br>                    completed = False<br>                    break<br><br>            # If the circuit is completed, return the start station<br>            if completed:<br>                return start<br><br>        # If no valid starting station is found, return -1<br>        return -1<br><br><br># Main function<br>if __name__ == &quot;__main__&quot;:<br>    # Create an instance of the class<br>    circuit = GasStationCircuit()<br><br>    # Gas and cost arrays for the circuit<br>    gas = [1, 2, 3, 4, 5]<br>    cost = [3, 4, 5, 1, 2]<br><br>    # Find and display the starting station<br>    result = circuit.can_complete_circuit(gas, cost)<br>    print(&quot;Starting station:&quot;, result)</pre><p>Code : JavaScript</p><pre>// Approach: Find the starting gas station for a circular route<br>// Language: JavaScript<br><br>// Class name in PascalCase<br>class GasStationCircuit {<br>    <br>    // Function to find the starting gas station<br>    canCompleteCircuit(gas, cost) {<br>        let n = gas.length; <br><br>        // Try starting from each gas station<br>        for (let start = 0; start &lt; n; start++) {<br>            let remainingGas = 0;  <br>            let completed = true;  <br><br>            // Simulate the journey<br>            for (let i = 0; i &lt; n; i++) {<br>                let currentStation = (start + i) % n;<br><br>                remainingGas += gas[currentStation] - cost[currentStation];<br><br>                // If remaining gas is negative, this start fails<br>                if (remainingGas &lt; 0) {<br>                    completed = false;<br>                    break;<br>                }<br>            }<br><br>            // If the circuit is completed, return the start station<br>            if (completed) {<br>                return start;<br>            }<br>        }<br><br>        // If no valid starting station is found, return -1<br>        return -1;<br>    }<br>}<br><br>// Main function<br>const circuit = new GasStationCircuit();<br><br>// Gas and cost arrays for the circuit<br>const gas = [1, 2, 3, 4, 5];<br>const cost = [3, 4, 5, 1, 2];<br><br>// Find and display the starting station<br>const result = circuit.canCompleteCircuit(gas, cost);<br>console.log(&quot;Starting station:&quot;, result);</pre><h4>Time Complexity: <strong>O(n²)</strong></h4><p>The outer loop iterates over each station (n times). For each station, we traverse through the entire circuit (n stations).</p><p>This gives us two nested loops, resulting in a time complexity of O(n) * O(n) = O(n²).</p><h4>Space Complexity: <strong>O(1)</strong></h4><p>The algorithm uses a constant amount of space. It only requires variables to store the remainingGas and completed status, and no additional data structures are used. Thus, the space complexity is constant.</p><h3>Short Bridge between Brute Force and Optimal Solution</h3><p>On running the above brute force solution you will find that the above code returns a TLE solution. We expected a Time Limit Exceed scenario in our above discussion, given the reason the constraint son the size of array is too high for the code to run in a limited amount of time and is in fact very slow.</p><p>Brute force methods are usually slow because they check all possibilities without skipping any, leading to a lot of repeated calculations.</p><p>The first step to making our code faster is to:</p><h3>1. Avoid Repeated Work</h3><p>Imagine we have two pointers, i and j, both starting at the same position. As j moves forward, we keep checking different positions it reaches:</p><pre>* * * * * *<br>      ^<br>      i<br>      ^<br>      j</pre><p>As j moves ahead:</p><pre>* * * * * *<br>      ^ ^<br>      i j</pre><p>Eventually, j reaches the end and comes back to the beginning. If we&#39;ve already checked a position before, we don&#39;t need to check it again.</p><p>For example, if we’ve already checked that from station 0 we can reach station 2. Then we can say that we can jump directly to station 2 next time, instead of going all the way back through station 0. This saves time by skipping repeated calculations.</p><pre>* * * * * *<br>    ^ ^   <br>    j i</pre><p>By keeping track of how far each position can go and how much “fuel” it has left, we can skip recalculating the same things and make the process much faster.</p><h3>2. Skipping Loops</h3><p>Since we found out that the positions between i and j can form a loop. This means that instead of checking each position one by one, we can skip over them because they would only bring us back to the same places.</p><p>For example, if we know that station i can reach station j and that station (i+1) can also reach j, it means we don’t need to start over from i+1. We can skip directly to the next position and avoid wasting time checking the same things over again.</p><h3>Optimal Solution</h3><h4>Intuition</h4><p>Now from the above discussion we understood that:</p><ul><li>If at any point during the journey, the fuel in the tank becomes negative, it means that starting from the previous station isn’t feasible.</li><li>We need to balance the total gas and total cost across all stations. If the total gas is less than the total cost, the journey isn’t possible, and we should return -1.</li><li>If the journey is possible, the solution will be unique because there is exactly one starting station that allows the circuit to be completed. <em>[Already, given in the problem statement, not something you should worry about]</em></li></ul><h3>Why This is Greedy</h3><p>This approach is greedy because at each station, you make the best choice by moving to the farthest station you can reach, using the available resources efficiently. You don’t reconsider previous decisions, and you don’t waste fuel going back. You’re always making the best local decision (choosing the farthest point) with the hope that it leads to the global optimal solution.</p><p>In simple terms: <strong>Greedy = Always moving forward with the farthest reachable option at each step.</strong></p><h4>Scenario:</h4><p>Imagine you are at <strong>Station A</strong>, and you want to travel to <strong>Station C</strong>, with <strong>Station B</strong> in between. Each station has a certain amount of gas that allows you to reach the next station.</p><p>Let’s represent this as:</p><pre>Station A --&gt; Station B --&gt; Station C</pre><p>Now, you have a certain amount of fuel at <strong>Station A</strong>, and you want to reach <strong>Station C</strong>. The greedy approach works by always choosing the farthest station you can reach at each step, without revisiting any station.</p><ol><li><strong>At Station A</strong>, you start with a certain amount of fuel. You check how far you can go:You can reach <strong>Station B</strong>.</li><li><strong>At Station B</strong>, you look at how far you can go from there: You can reach <strong>Station C</strong>.</li><li>Now, instead of going back and checking <strong>Station A</strong> again (which would waste time), you directly jump from <strong>Station B</strong> to <strong>Station C</strong>, using the remaining fuel.</li></ol><h3>Approach</h3><p><strong>Step I : Check the possibility:</strong></p><ul><li>First, we check if the total amount of gas is enough to cover the total cost. If the total gas is less than the total cost, return -1 immediately because it is impossible to complete the circuit.</li></ul><p><strong>Step I : Simulate the Journey:</strong></p><ul><li>Initialize two variables: total_sum and current_sum.</li></ul><blockquote>total_sum keeps track of the overall difference between total gas and total cost.</blockquote><blockquote>current_sum is used to simulate the journey from a particular start index.</blockquote><ul><li>Traverse each gas station, calculating the difference gas[i] - cost[i]. Add this value to currGas.</li><li>If currGas becomes negative at any station, it means the current starting index is not possible. Hence, we reset currGas and set the new potential starting station to the next station.</li><li>After completing the loop, if totalGas is greater than or equal to 0, the last updated start index will be the valid starting point.</li></ul><h4><strong>Edge Cases:</strong></h4><ul><li>If the total gas is less than total cost, return -1.</li><li>If there is only one station, check if you can complete the circuit directly.</li></ul><h3>Dry Run</h3><p>Let’s dry-run the example:</p><ul><li><strong>Input:</strong> gas = [1, 2, 3, 4, 5], cost = [3, 4, 5, 1, 2]</li></ul><p><strong>Explanation:</strong></p><p>Start by calculating the total sum of gas[i] - cost[i]:</p><ul><li>At index 0: gas[0] - cost[0] = 1 - 3 = -2</li><li>At index 1: gas[1] - cost[1] = 2 - 4 = -2</li><li>At index 2: gas[2] - cost[2] = 3 - 5 = -2</li><li>At index 3: gas[3] - cost[3] = 4 - 1 = 3</li><li>At index 4: gas[4] - cost[4] = 5 - 2 = 3</li></ul><p>The total_sum is 0, which is non-negative, indicating a valid solution exists.</p><p>Now we start from index 3 because we see that the total sum at index 0,1,and 2 are negative. That means they are not feasible points at all.</p><ul><li>Starting at index 3:</li><li>From index 3, fuel is 4 and the cost to move to index 4 is 1, so we have 4 - 1 = 3.</li><li>Moving to index 4, fuel is 3 and the cost to move to index 0 is 2, so we have 3 - 2 = 1.</li><li>Continuing the process we are able to complete the circuit</li></ul><h4>Output: 3</h4><h3>Code : C++</h3><pre>// Approach: Calculate the starting gas station for a circular trip<br>// Language: C++<br><br>#include &lt;iostream&gt;<br>#include &lt;vector&gt;<br>using namespace std;<br><br>// Function to calculate the starting gas station index<br>int CanCompleteCircuit(const vector&lt;int&gt;&amp; gas, <br>                       const vector&lt;int&gt;&amp; cost) {<br><br>    // Initialize total sum and current sum<br>    int total_sum = 0;  <br>    int current_sum = 0;  <br>    int start_index = 0;<br><br>    // Loop through all the gas stations<br>    for (int i = 0; i &lt; gas.size(); i++) {<br><br>        // Calculate the net gain of fuel at each station<br>        total_sum += gas[i] - cost[i];<br>        current_sum += gas[i] - cost[i];<br><br>        // If current sum becomes negative, reset the start index<br>        if (current_sum &lt; 0) {<br>            current_sum = 0;<br>            start_index = i + 1;<br>        }<br>    }<br><br>    // If total sum is non-negative, return the start index, <br>    // else return -1 indicating no valid circuit<br>    if (total_sum &gt;= 0) {<br>        return start_index;<br>    } else {<br>        return -1;<br>    }<br>}<br><br>// Main function<br>int main() {<br>    // Example input for gas and cost<br>    vector&lt;int&gt; gas = {1, 2, 3, 4, 5};<br>    vector&lt;int&gt; cost = {3, 4, 5, 1, 2};<br><br>    // Call the function to find the starting index<br>    int result = CanCompleteCircuit(gas, cost);<br><br>    // Output the result<br>    cout &lt;&lt; &quot;Starting Index: &quot; &lt;&lt; result &lt;&lt; endl;<br><br>    return 0;<br>}</pre><h3>Code : Java</h3><pre>// Approach: Find the starting gas station for a complete<br>// circuit if possible.<br>// Language: Java<br><br>public class GasStationCircuit {<br><br>    // Method to find the starting gas station for a circuit<br>    public int canCompleteCircuit(int[] gas, int[] cost) {<br>        <br>        // Initialize total sum and current sum<br>        int totalSum = 0;<br>        int currentSum = 0;<br>        <br>        // Initialize the starting index<br>        int startIndex = 0;<br><br>        // Iterate through the gas stations<br>        for (int i = 0; i &lt; gas.length; i++) {<br><br>            // Calculate the difference between gas and cost<br>            totalSum += gas[i] - cost[i];<br>            currentSum += gas[i] - cost[i];<br><br>            // If current sum becomes negative, reset start index<br>            if (currentSum &lt; 0) {<br>                currentSum = 0;<br>                startIndex = i + 1;<br>            }<br>        }<br><br>        // Return the start index if the total sum is non-negative<br>        // Else, return -1<br>        return totalSum &gt;= 0 ? startIndex : -1;<br>    }<br>}</pre><h3>Code : Python</h3><pre># Approach: Calculate the starting gas station for a circular trip<br># Language: Python<br><br>def can_complete_circuit(gas, cost):<br>    <br>    # Initialize total sum and current sum<br>    total_sum = 0  <br>    current_sum = 0  <br>    start_index = 0<br><br>    # Loop through all the gas stations<br>    for i in range(len(gas)):<br>        <br>        # Calculate the net gain of fuel at each station<br>        total_sum += gas[i] - cost[i]<br>        current_sum += gas[i] - cost[i]<br><br>        # If current sum becomes negative, reset the start index<br>        if current_sum &lt; 0:<br>            current_sum = 0<br>            start_index = i + 1<br><br>    # If total sum is non-negative, return the start index, <br>    # else return -1 indicating no valid circuit<br>    if total_sum &gt;= 0:<br>        return start_index<br>    else:<br>        return -1<br><br><br># Main execution<br>if __name__ == &quot;__main__&quot;:<br>    <br>    # Example input for gas and cost<br>    gas = [1, 2, 3, 4, 5]<br>    cost = [3, 4, 5, 1, 2]<br><br>    # Call the function to find the starting index<br>    result = can_complete_circuit(gas, cost)<br><br>    # Output the result<br>    print(&quot;Starting Index:&quot;, result)</pre><h3>Code : JavaScript</h3><pre>// Approach: Calculate the starting gas station for a circular trip<br>// Language: JavaScript<br><br>function canCompleteCircuit(gas, cost) {<br>    <br>    // Initialize total sum and current sum<br>    let totalSum = 0;<br>    let currentSum = 0;<br>    let startIndex = 0;<br><br>    // Loop through all the gas stations<br>    for (let i = 0; i &lt; gas.length; i++) {<br>        <br>        // Calculate the net gain of fuel at each station<br>        totalSum += gas[i] - cost[i];<br>        currentSum += gas[i] - cost[i];<br><br>        // If current sum becomes negative, reset the start index<br>        if (currentSum &lt; 0) {<br>            currentSum = 0;<br>            startIndex = i + 1;<br>        }<br>    }<br><br>    // If total sum is non-negative, return the start index, <br>    // else return -1 indicating no valid circuit<br>    if (totalSum &gt;= 0) {<br>        return startIndex;<br>    } else {<br>        return -1;<br>    }<br>}<br><br>// Main execution<br>const gas = [1, 2, 3, 4, 5];<br>const cost = [3, 4, 5, 1, 2];<br><br>// Call the function to find the starting index<br>const result = canCompleteCircuit(gas, cost);<br><br>// Output the result<br>console.log(&quot;Starting Index:&quot;, result);</pre><h3><strong>Time Complexity: O(n)</strong></h3><p>Our code loops through the gas and cost arrays once, making it <strong>O(n)</strong>, where n is the number of gas stations.</p><h3><strong>Space Complexity: O(1)</strong></h3><p>Our code uses only a few variables for tracking the sums and index, making it <strong>O(1)</strong>.</p><h3>DO THIS OR I WILL BE SAD 🥺</h3><p>Solve a similar question to further deepen your understanding with the concepts we have discussed above. I am sure they will come handy in many questions. Here are some questions of similar nature and understanding:</p><p><a href="https://leetcode.com/problems/maximize-the-topmost-element-after-k-moves/">2202. Maximize the Topmost Element After K Moves</a></p><p><a href="https://leetcode.com/problems/assign-cookies/">455. Assign Cookies</a></p><p><a href="https://leetcode.com/problems/candy/">135. Candy</a></p><p><strong>Follow me on medium to get notification for all my amazing LeetCode editorials.</strong></p><p>Find my other leetcode solution on my github — <a href="https://github.com/Harshit-Raj-14/My-Leetcode-Solutions">https://github.com/Harshit-Raj-14/My-Leetcode-Solutions</a> . (Follow me and star mark the repo)</p><p>Best of Luck!</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><blockquote><em>If you got to learn something valuable from this article and clap and follow me if you found it helpful.</em></blockquote><p><strong>Follow me for more such awesome articles that can help you in your interview preparation and studies and learn coding.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, tutorials, Coding Question solutions Editorials, Interview Tips and many more stuff that you are bound to like.</p><p>Also, I write articles for freelancing so you can contact me through the below link.</p><blockquote><em>If you liked this article, do support me in this endeavor by </em><strong><em>following me on medium</em></strong><em> and get latest updates to my amazing and helpful articles.</em></blockquote><blockquote><em>You can encourage me to write more on: </em><a href="https://ko-fi.com/medusaverse"><em>https://ko-fi.com/medusaverse</em></a></blockquote><blockquote><strong><em>I will be happy to Connect with you</em></strong><em> : </em><a href="https://linktr.ee/harshit_raj_14"><em>https://linktr.ee/harshit_raj_14</em></a></blockquote><h3>“This Method Quickly Cured My Procrastination” — The Scientific Trick</h3><p>Checkout the article now — <a href="https://medium.com/@Harshit_Raj_14/this-method-quickly-cured-my-procrastination-the-scientific-trick-8817b5d72618">Click here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daddfb4ab123" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[560. Subarray Sum Equals K — LeetCode Medium Problem — Full Solution and approach explained]]></title>
            <link>https://medium.com/@Harshit_Raj_14/560-subarray-sum-equals-k-leetcode-medium-problem-full-solution-and-approach-explained-d249fb62974f?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/d249fb62974f</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[leetcode-solution]]></category>
            <category><![CDATA[google-interview-question]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Wed, 25 Dec 2024 23:41:43 GMT</pubDate>
            <atom:updated>2024-12-25T23:41:43.457Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://leetcode.com/problems/subarray-sum-equals-k/">560. Subarray Sum Equals K</a> — LeetCode Medium Problem — Full Solution and approach explained</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*DENauUixUf2DS-VfgKCXlA.png" /><figcaption>LeetCode — 560. Subarray Sum Equals K</figcaption></figure><h3>Problem Statement</h3><p>Given an array of integers nums and an integer k, return <em>the total number of subarrays whose sum equals to</em> k.</p><p><strong>Example 1:</strong></p><pre>Input: nums = [1,1,1], k = 2<br>Output: 2<br>Explanation : subarrays [1,1] and [1,1] have sum equal to k = 2.</pre><p><strong>Example 2:</strong></p><pre>Input: nums = [1,2,3], k = 3<br>Output: 2<br>Explanation : subarrays [1,2] and [3] have sum equal to k = 3.</pre><h3>Let’s Understand the Problem</h3><p>As input we have been given an integer array <strong>nums</strong> and a target <strong>k</strong>. Then we are simply asked to find the number of subarrays whose sum will be k.</p><blockquote><strong>In case you do not recall what a subarray is!</strong> 😉</blockquote><blockquote>A <strong>subarray</strong> is a sequence of elements from an array that is continuous, meaning the elements must appear in the same order and without skipping any elements.</blockquote><blockquote>For <strong>example</strong>, if the array is nums = [1, 2, 3, 4], its possible subarrays include:</blockquote><blockquote>Single-element subarrays: [1], [2], [3], [4]</blockquote><blockquote>Two-element subarrays: [1, 2], [2, 3], [3, 4]</blockquote><blockquote>Three-element subarrays: [1, 2, 3], [2, 3, 4]</blockquote><blockquote>The entire array: [1, 2, 3, 4]</blockquote><blockquote>However, [1, 3] or [2, 4] would not be subarrays because they skip elements and break the contiguous sequence.</blockquote><h3><strong>1. A very Brut-ish Approach</strong></h3><p>The devil’s mind is always tempted to take the easy way. Hey why not just find all the subarrays, check their sums. <em>And tada we have our answer.</em></p><h4>The Approach</h4><p>We first use two loops to iterate over the given array to find all subarrays {i, j}, and then accumulate the elements from i to j. Finally maintain a count variable and increment it when the sum of subarray equals k.</p><h4>Implementation Code</h4><pre>class Solution {<br>    public int subarraySum(int[] nums, int k) {<br>        int count = 0;<br>       <br>        // Step I : Find all subarrays by iterating through the array<br>        for (int start = 0; start &lt; nums.length; start++) {<br>            for (int end = start; end &lt; nums.length; end++) {<br>                int sum = 0;<br><br>                // Step II: Calculate the sum of the current subarray<br>                for (int i = start; i &lt;= end; i++) {<br>                    sum += nums[i];<br>                }<br><br>                // Step III: Check if the sum equals k<br>                if (sum == k) {<br>                    count++;<br>                }<br>            }<br>        }<br>        return count;<br>    }<br>}</pre><p>Time Complexity : O(n³)</p><blockquote>Explanation: Three nested loops iterate over all possible subarrays and calculate their sums.</blockquote><p>Space Complexity : O(1)</p><blockquote>Explanation: No extra space is used.</blockquote><h3>2. Optimized Brute Force Method</h3><h4>The Smarter Way</h4><p>One thing we do realize when learning math is that, when adding numbers like 1,2,3,4,….</p><p>We do not add 1+2 =3, then 1+2+3=6 and 1+2+3+4=10</p><p>But we do it on the go to avoid repetition:</p><blockquote>1+2 =3 =&gt; 3+3=6 =&gt; 6+4=10</blockquote><p>And the same applies here as well, instead of starting fresh every time with a new subarray, you just <strong>keep adding numbers</strong> as you go.</p><h4>Approach</h4><p>We calculate the sum of the subarray {0, i} (denoted as sum_i) and the sum of the subarray {0, j} (denoted as sum_j), the sum of the subarray {i, j} can be expressed as:<br><strong>sum of subarray (i, j) = sum_j - sum_i + nums[i]</strong>, where 0 &lt;= i &lt;= j &lt; n.</p><h4><strong>Implementation Code</strong></h4><pre>class Solution {<br>    public int subarraySum(int[] nums, int k) {<br>        int count = 0;<br>        <br>        // Step I: Iterate through the array<br>        for (int start = 0; start &lt; nums.length; start++) {<br>            int sum = 0;<br><br>            // Step II: Accumulate the sum for subarrays starting from &#39;start&#39;<br>            for (int end = start; end &lt; nums.length; end++) {<br>                sum += nums[end];<br>                if (sum == k) {<br>                    count++;<br>                }<br>            }<br>        }<br>        return count;<br>    }<br>}</pre><p>Time Complexity : O(n²)</p><blockquote>Explanation: Two nested loops iterate over all possible subarrays and calculate their sums.</blockquote><p>Space Complexity : O(1)</p><blockquote>Explanation: No extra space is used.</blockquote><h3>Why does TLE occur at this point?</h3><p>Often people have a common question at this point, why my code still gives TLE(Time Limit Exceeded) error, even though I have already optimized my code once.</p><p>If you were to look at the constrains on the size of array for once given in the problem : 1 &lt;= nums.length &lt;= 2 x 10^4 .</p><p>With a constraint of <strong>nums.length &lt;= 20,000</strong>, an <strong>O(n²)</strong> solution, where n is the size of the array) would require up to <strong>400 million</strong> operations in the worst case, which is too slow for modern time limits, typically set to run in under 1–2 seconds.</p><p>This results in <strong>Time Limit Exceeded (TLE)</strong> because the algorithm exceeds the time limits for large inputs.</p><h3>A FAILED STRATEGY — SLIDING WINDOW</h3><p>Its only right we give everyone chance and so I wondered how about using sliding window. And we have all seen the sliding window technique being often used to find contiguous subarrays that satisfy a certain condition. I mean isn’t it quite close to what we want.</p><h3>Why Sliding Window Fails: [ASK YOURSELF 🤔]</h3><p><strong>THE REASON </strong>— In this problem, the sliding window technique <strong>fails</strong> due to the presence of negative numbers in the array.</p><p>Again through the constraints of the problem we know that our given input array might contain negative elements: -1000 &lt;= nums[i] &lt;= 1000</p><p><strong>Explanation : </strong>Consider the array [1, 2, -3, 1, 2, -3] with k = 0.</p><p>The sliding window might identify two subarrays [1, 2, -3] and [1, 2, -3] separately, both summing to 0. However, it will <strong>miss the subarray that spans the entire array</strong>, which also sums to 0.</p><p>This happens because the sliding window technique typically expands the window to the right, but once a negative element is encountered, the window might exclude parts of the array that sum to k.</p><p>Thus, <strong>the sliding window doesn’t work here</strong> because it can’t backtrack or include necessary elements from the left side once it moves forward, making it unsuitable for arrays with negative numbers.</p><h3>A small quiz to you to find the optimal strategy</h3><p>In the above solution we used an expression:</p><p><strong>sum of subarray (i, j) = sum_j — sum_i + nums[i]</strong></p><p>where, sum_j and sum_i are sum of subarray ranging from (0,j) and (0,i).</p><p>In fact they are <strong>prefix sums</strong>.</p><p>And in fact the condition check :</p><blockquote><strong><em>sum of subarray (i,j) = pre[j] — pre[i] == k</em></strong></blockquote><p>Does the expression looks familiar to you : pre[j] — pre[i] == k</p><p>Have you seen it before?</p><p>You guessed it right! It is the first question of LeetCode, the sum of two numbers! (<a href="https://leetcode.com/problems/two-sum/description/"><strong>Two sum problem</strong></a>)</p><p>Recall that the sum of two numbers requires us to find all the cases where nums[i] + nums[j] == k (the logic is the same whether it is addition or subtraction), and the brute force method is the same . What method did we use to optimize it?</p><p><strong>Yes! It is a HashMap!</strong></p><p>That’s our secret ingredient.</p><p>Thinking of this, the optimization logic of this question is actually clear.</p><h3>Optimized Solution 👑</h3><h4>TRUTHS &amp; FACTS</h4><ol><li>) <strong>Prefix Sum Concept</strong> — If the prefix sum at two points(indexes) are same that means the sum lying between those two indexes is zero.</li></ol><p><strong>Example:</strong> Consider an array: [3, -1, 2, -2, 1] We compute the prefix sum for each element:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*nDmeON3Mlae8EiCCL8HYLQ.png" /></figure><p>Now, if we compare prefix sums:</p><ul><li>At index 0: Prefix sum = 3</li><li>At index 3: Prefix sum = 2</li></ul><p>The prefix sum at index 0 and index 3 are <strong>not the same</strong>, but if we check the sum between index 1 and 3</p><blockquote>prefix sum at index 3 - prefix sum at index 1 = 2–2 = 0</blockquote><p>it shows that the sum between these indexes is <strong>zero</strong>.</p><p>2.) <strong>Difference in Prefix Sum Equals k —</strong> If the prefix sum at two indexes(i and j) is at a difference of k. prefixsum[j] — prefixsum[i]=k; That means the sum of elements lying between the two indexes is k.</p><p><strong>Example:</strong> Consider the same array: [3, -1, 2, -2, 1]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*nDmeON3Mlae8EiCCL8HYLQ.png" /></figure><p>Suppose we want to find the sum between index 1 and 4:</p><ul><li>Prefix sum at index 4 = 3</li><li>Prefix sum at index 1 = 2</li></ul><p>The difference between the prefix sums at these two indexes is 3 - 2 = 1, which means the sum of elements between these indexes is <strong>1</strong>.</p><h3>Approach</h3><p>To reach the solution we first need to find all pairs where pre[j] - pre[i] == k (where 0 &lt;= i &lt;= j &lt; n). The brute force approach would check each pair (i, j) in the range 0 &lt;= i &lt;= j &lt; n, which takes O(n^2) time. However, we can improve this by using a <strong>hashmap</strong> to store the values of prefix[i] as we traverse prefix[j]. This allows us to quickly check if pre[j] - k exists in the hashmap or not, reducing the time complexity.</p><p>Further, for every sum encountered, we also determine the number of times the sum sum−k has occurred already, since it will determine the number of times a subarray with sum k has occurred up to the current index.</p><h3>Steps</h3><p><strong>Step 1:</strong> Initialize a HashMap with (0, 1) to handle base cases.<br><strong>Step 2:</strong> Traverse through the array, updating the prefix sum and checking if sum - k exists in the map, adding the count of valid subarrays.<br><strong>Step 3:</strong> Update the map with the current prefix sum&#39;s frequency and return the total count of valid subarrays.</p><pre>class Solution {<br>    public int subarraySum(int[] nums, int k) {<br>        HashMap&lt;Integer, Integer&gt; map = new HashMap&lt;&gt;();<br>        map.put(0, 1);<br>        int count = 0;<br>        int sum = 0;<br>        for (int num : nums) {<br>            // Step I: // Update the prefix sum<br>            sum += num; <br><br>            // Step II: Check if (sum - k) exists in the map<br>            if (map.containsKey(sum - k)) {<br>                count += map.get(sum - k);<br>            }<br><br>            // Step III: Add the current sum to the map (increment the frequency)<br>            map.put(sum, map.getOrDefault(sum, 0) + 1);<br>        }<br>        return count;<br>    }<br>}</pre><p>Time Complexity : O(n)</p><blockquote>Explanation: <em>We iterate through the array once, and each HashMap operation (lookup and update) takes constant time.</em></blockquote><p>Space Complexity : O(n)</p><blockquote>Explanation: <em>The space complexity is determined by the HashMap, which can store up to </em><em>n different prefix sums in the worst case.</em></blockquote><h3>DO THIS OR I WILL BE SAD 🥺</h3><p>Solve a similar question to further deepen your understanding with the concepts we have discussed above. I am sure they will come handy in many questions. Here are some questions of similar nature and understanding:</p><p><a href="https://leetcode.com/problems/continuous-subarray-sum/">523. Continuous Subarray Sum</a></p><p><a href="https://leetcode.com/problems/binary-subarrays-with-sum/">930. Binary Subarrays With Sum</a></p><p>Follow me on medium to get notification for all my amazing LeetCode editorials.</p><p>Find my other leetcode solution on my github — <a href="https://github.com/Harshit-Raj-14/My-Leetcode-Solutions">https://github.com/Harshit-Raj-14/My-Leetcode-Solutions</a> . (Follow me and star mark the repo)</p><p>Best of Luck!</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><blockquote>If you got to learn something valuable from this article and clap and follow me if you found it helpful.</blockquote><p><strong>Follow me for more such awesome articles that can help you in your interview preparation and studies and learn coding.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, tutorials, Coding Question solutions Editorials, Interview Tips and many more stuff that you are bound to like.</p><p>Also, I write articles for freelancing so you can contact me through the below link.</p><blockquote>If you liked this article, do support me in this endeavor by <strong>following me on medium</strong> and get latest updates to my amazing and helpful articles.</blockquote><blockquote>You can encourage me to write more on: <a href="https://ko-fi.com/medusaverse">https://ko-fi.com/medusaverse</a></blockquote><blockquote><strong>I will be happy to Connect with you</strong> : <a href="https://linktr.ee/harshit_raj_14">https://linktr.ee/harshit_raj_14</a></blockquote><h3>“This Method Quickly Cured My Procrastination” — The Scientific Trick</h3><p>Checkout the article now — <a href="https://medium.com/@Harshit_Raj_14/this-method-quickly-cured-my-procrastination-the-scientific-trick-8817b5d72618">Click here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d249fb62974f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[238. Product of Array Except Self — LeetCode Medium Problem — Full Solution and approach explained]]></title>
            <link>https://medium.com/@Harshit_Raj_14/238-product-of-array-except-self-leetcode-medium-problem-full-solution-and-approach-explained-8277e5868f50?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/8277e5868f50</guid>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[leetcode-medium]]></category>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Wed, 14 Feb 2024 05:41:33 GMT</pubDate>
            <atom:updated>2024-02-14T05:41:33.655Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://leetcode.com/problems/product-of-array-except-self/">238. Product of Array Except Self</a> — LeetCode Medium Problem — Full Solution and approach explained</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*DENauUixUf2DS-VfgKCXlA.png" /></figure><h3>In this blog, I would be discussing this question with different approaches which you would come up in an interview in the manner of increasing difficulty. I will be writing this post in such a way as if I were the person being interviewed. So, enjoy 😊</h3><h3>Problem Statement:</h3><p><strong>Interviewer : </strong>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]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in O(n) time and without using the division operation.</p><p>Example 1:</p><p>Input: nums = [1,2,3,4] Output: [24,12,8,6]</p><p>Example 2:</p><p>Input: nums = [-1,1,0,-3,3] Output: [0,0,9,0,0]</p><h4><strong>Brute Force Approach</strong></h4><p><strong>Interviewee:</strong> Absolutely, let’s start with the fundamentals. The brute force approach involves looping through the array, excluding the current element, and multiplying the rest. While simple, its time complexity is O(n²).</p><pre>// Java code for brute force approach<br>class Solution {<br>    public int[] productExceptSelf(int[] nums) {<br>        int n = nums.length;<br>        int ans[] = new int[n];<br>        <br>        for(int i = 0; i &lt; n; i++) {<br>            int pro = 1;<br>            for(int j = 0; j &lt; n; j++) {<br>                if(i == j) continue;<br>                pro *= nums[j];<br>            }<br>            ans[i] = pro;<br>        }<br>        <br>        return ans;<br>    }<br>}</pre><p><strong>Interviewer:</strong> Indeed, an essential starting point. Now, let’s optimize.</p><h4><strong>Dividing the Product of Array with the Number</strong></h4><p>Interviewee: Right, here we calculate the product of all elements and divide by each element to obtain the desired result. However, we face challenges when encountering zeroes in the array due to division by zero.</p><pre>// Java code for dividing the product of array with the number<br>class Solution {<br>    public int[] productExceptSelf(int[] nums) {<br>                int n = nums.length;<br>        int countZeroes = 0;<br>        int indexZero = -1;<br>        int productWithoutZero = 1;<br>        for(int i = 0 ; i &lt; n ; i++) {<br>            if(nums[i] == 0) {<br>                countZeroes++;<br>                indexZero = i;<br>            }<br>            else productWithoutZero *= nums[i];<br>        }    <br>        int [] output = new int [n];<br>        if(countZeroes == 0) {<br>            for(int i = 0 ; i &lt; n ; i++) {<br>                output[i] = productWithoutZero / nums[i];<br>            }<br>        }<br>        else if(countZeroes == 1) {<br>            output[indexZero] = productWithoutZero;<br>        }<br>        return output;<br>    }<br>}</pre><p>LOGIC — -<br>maintain the count of zeroes in the array.<br>1.) If count of zeroes is greater than 1 so the array will be empty<br>2.) If the count of zeroes is 0 then we need to just divide the product of array with every element<br>3.) Lastly if the count of zeroes if 1, then we need to find the index of zero and product of array without zero and then just place the product at index of zero and we are done</p><p>Note — What if there is more than one zero??<br>ans: read point no 1</p><h4><strong>Finding Prefix Product and Suffix Product</strong></h4><p><strong>Interviewee:</strong> Similar to finding prefix sums, we compute prefix and suffix product arrays. Then, the final answer at each index is the product of its prefix and suffix, excluding the element itself. This approach offers a time complexity of O(n) but uses additional space.</p><pre>class Solution {<br>    public int[] productExceptSelf(int[] nums) {<br>        int prefix[] = new int[nums.length];<br>        prefix[0]=1; <br>        for(int i=1;i&lt;nums.length;i++){<br>            prefix[i]=prefix[i-1]*nums[i-1];<br>        }<br>        int suffix[] = new int[nums.length];<br>        suffix[nums.length-1]=1; <br>        for(int i=nums.length-2;i&gt;=0;i--){<br>            suffix[i]=suffix[i+1]*nums[i+1];<br>        }<br>        int ans[] = new int[nums.length];<br>        for(int i=0;i&lt;nums.length;i++) ans[i]=prefix[i]*suffix[i];<br>        return ans;<br>    }<br>}</pre><p>LOGIC — -<br>For any nums[i], calculate its left product and calculate its right product, without including nums[i] as prefix and suffix.<br>Then multiply these left and right product, This will give product of array excluding nums[i].</p><p><strong>Interviewer:</strong> Excellent! Now, let’s optimize space.</p><h4><strong>Directly Store the Product of Prefix and Suffix into the Final Answer Array</strong></h4><p>Interviewee: Precisely, we can perform the same calculations directly onto our final answer array, minimizing auxiliary space to O(1).</p><pre>class Solution {<br>    public int[] productExceptSelf(int[] nums) {<br>        int n = nums.length;<br>        int ans[] = new int[n];<br>        Arrays.fill(ans, 1);<br>        for(int i = 1; i &lt; n; i++) {<br>            ans[i] = ans[i-1] * nums[i-1];<br>        }<br>        int curr = 1;<br>        for(int i = n - 1; i &gt;= 0; i--) {<br>            ans[i] *= curr;<br>            curr *= nums[i];<br>        }<br>        return ans;<br>    }<br>}</pre><p><strong>Interviewer:</strong> Well done! These approaches showcase your problem-solving skills impressively. Thank you for sharing your insights.</p><p><strong>Interviewee:</strong> Thank you for the opportunity. It’s been a pleasure discussing these strategies with you.</p><h3>DO THIS OR I WILL BE SAD 🥺</h3><p>Do ask in comments if you face any problem in the above solutions. If the prefix and suffix part is not clear to you, my suggestion is to revise or learn these topics thoroughly.</p><p>Follow me on medium to get notification for all my amazing LeetCode editorials.</p><p>Find my other leetcode solution on my github — <a href="https://github.com/Harshit-Raj-14/My-Leetcode-Solutions">https://github.com/Harshit-Raj-14/My-Leetcode-Solutions</a> . (Follow me and star mark the repo)</p><p>Best of Luck!</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><blockquote><em>If you got to learn something valuable from this article and clap and follow me if you found it helpful.</em></blockquote><blockquote><strong>You can encourage me to write more such articles on: </strong><a href="https://ko-fi.com/medusaverse">https://ko-fi.com/medusaverse</a></blockquote><p><strong>Follow me for more such awesome articles that can help you in your interview preparation and studies and learn coding.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, tutorials, Coding Question solutions Editorials, Interview Tips and many more stuff that you are bound to like.</p><p>Also, I write articles for freelancing so you can contact me through the below link.</p><blockquote>If you liked this article, do support me in this endeavor by <strong>following me on medium</strong> and get latest updates to my amazing and helpful articles.</blockquote><blockquote>You can encourage me to write more on: <a href="https://ko-fi.com/medusaverse">https://ko-fi.com/medusaverse</a></blockquote><blockquote><strong>I will be happy to Connect with you</strong> : <a href="https://linktr.ee/harshit_raj_14">https://linktr.ee/harshit_raj_14</a></blockquote><h3>“This Method Quickly Cured My Procrastination” — The Scientific Trick</h3><p>Checkout the article now — <a href="https://medium.com/@Harshit_Raj_14/this-method-quickly-cured-my-procrastination-the-scientific-trick-8817b5d72618">Click here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8277e5868f50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Postman API Fundamentals Student Expert — QUIZ Solutions]]></title>
            <link>https://medium.com/@Harshit_Raj_14/postman-api-fundamentals-student-expert-quiz-solutions-2de9808d16dd?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/2de9808d16dd</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[quiz]]></category>
            <category><![CDATA[postmanstudent]]></category>
            <category><![CDATA[postman-testing]]></category>
            <category><![CDATA[postman]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Fri, 22 Dec 2023 20:08:49 GMT</pubDate>
            <atom:updated>2023-12-22T20:08:49.709Z</atom:updated>
            <content:encoded><![CDATA[<h3>Postman API Fundamentals Student Expert — QUIZ Solutions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*Ld4_DbusHq1b7RM-oHq6PA.png" /></figure><h3>Quiz #1: What Are APIs?</h3><h3><strong>Q1) What is an API? Pick the best answer from one of the choices below.</strong></h3><p>(a) A file format for images</p><p>(b) Apple’s new iPhone programming language</p><p>© A contract that allows code to talk to other code.</p><p>(d) A unit used for storage measurement</p><blockquote>Answer : (c) A contract that allows code to talk to other code.</blockquote><h4><strong>Q2) What are some different types of APIs?</strong></h4><p>(1) REST APIs</p><p>(2) GraphQL</p><p>(3) gRPC</p><p>(4) ElectricSockets</p><blockquote>Answer : (1) REST APIs, (2) GraphQL, (3) gRPC</blockquote><h3>Quiz #2 Introducing Postman</h3><h4>Q1) Postman has a vision for an API-First World. In the API-first world:</h4><p>(1) APIs are considered a #1 priority</p><p>(2) APIs will make you famous on TikTok</p><p>(3) APIs are easily consumable</p><p>(4) API stands for Application Postman Interface</p><p>(5) APIs are easily discoverable</p><blockquote>Answer : (1), (3), (5)</blockquote><h3>Quiz #3: Your First API Request</h3><p>Q1) You are given three blocks of text (see image below). Each block is part of a request URL. Which of the answer choices below lists these parts in the correct order?</p><p>https:// library-api.postman.labs.com /books</p><p>(1) path, host, protocol</p><p>(2) protocol, host, proxy</p><p>(3) host, proxy, path</p><p>(4) protocol, host, path</p><blockquote>Answer : (4) protocol, host, path</blockquote><p>Q 2) You are given a table of response status codes (see image below). Using only the code ranges given, choose the answer that lists the correct order of meanings for the codes that are given, starting at &quot;2xx&quot;.</p><p><strong>Code Range</strong> 2xx 3xx 4xx 5xx</p><p>(1) Redirection, Success, Client Error, Redirection, Server Error</p><p>(2) Success, Redirection, Server Error, Client Error</p><p>(3) Server Error, Success, Redirection, Client Error</p><p>(4) Success, Client Error, Redirection, Server Error</p><p>(5) Success, Redirection, Client Error, Server Error</p><blockquote>Answer : (4) protocol, host, path</blockquote><h3>Quiz #4: Query vs. path parameters</h3><p>Q 1) What type of parameter is :id below?</p><p>GET https://api.some-url.com/books/<strong>:id</strong></p><p>(1) query parameter</p><p>(2) path parameter</p><blockquote>Answer : (2) path parameter</blockquote><p>Q 2) How many query parameters are present in this request URL?<br><br>GET https:/library-api.postmanlabs.com/books?genre=fiction&amp;search=borges</p><p>(1) 1</p><p>(2) 0</p><p>(3) 2</p><p>(4) 3</p><blockquote>Answer : (3) 2</blockquote><p>Q3) How many path parameters are in this documented endpoint?</p><p>GET <a href="https://library-api.postmanlabs.com/books">https://library-api.postmanlabs.com/books</a></p><p>(1) 1</p><p>(2) 0</p><blockquote>Answer : (2) 0</blockquote><h3>Quiz #5: Sending Data With Postman</h3><p>Q1) What <strong>could</strong> happen if you don&#39;t include <strong>Authorization</strong> (aka <strong>Auth</strong>) to your API? Select all answers that apply.</p><p>(1) Your computer can explode</p><p>(2) Your API will have completely open endpoints that anyone can access publicly</p><p>(3) Unauthorized people will be able to access data they shouldn&#39;t see</p><p>(4) Bots would be able to flood an API with thousands of calls per second and shut it down.</p><blockquote>Answer : (2), (3), (4)</blockquote><p>Q2)You send this request in Postman and get this response code: 401. What is the error here?</p><pre>{<br>   &quot;title&quot;: &quot;To Kill a Mockingbird&quot;,<br>   &quot;author&quot;: &quot;Harper Lee&quot;,<br>   &quot;genre&quot;: &quot;fiction&quot;,<br>   &quot;yearPublished&quot;: 1960<br>}</pre><p>(1) the path changed</p><p>(2) there is not enough storage space in the server</p><p>(3) there are no issues</p><p>(4) the request needs authorization</p><blockquote>Answer : (4) the request needs authorization</blockquote><h3>Quiz #6: Intro to Variables</h3><p>Q1) Choose all the answers that apply. Postman allows you to save values as variables so that you can:</p><p>(1) Spend more time reading the API-First World!</p><p>(2) Reuse values to keep your work DRY (Don’t Repeat Yourself)</p><p>(3) Cool off your computer</p><p>(4) Hide sensitive values like API keys from being shared publicly</p><blockquote>Answer : (2), (4)</blockquote><h3>DO THIS OR I WILL BE SAD 🥺</h3><p>It would be great if you can also share some good problems in the comments to help others and check your knowledge based on questions asked by others.</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, latest tech news, tutorials, Coding question solutions, Editorials, Interview Tips and many more stuff that you are bound to like.</p><p>Also, I write articles for freelancing so you can contact me through the below link.</p><blockquote>If you liked this article, do support me in this endeavor by <strong>following me on medium</strong> and get latest updates to my amazing and helpful articles.</blockquote><blockquote>You can encourage me to write more on: <a href="https://ko-fi.com/medusaverse">https://ko-fi.com/medusaverse</a></blockquote><blockquote><strong>I will be happy to Connect with you</strong> : <a href="https://linktr.ee/harshit_raj_14">https://linktr.ee/harshit_raj_14</a></blockquote><blockquote><em>Did my articles amaze you? Why not subscribe to my newsletter to get the first update whenever I upload a new one:</em></blockquote><blockquote><a href="https://medium.com/@Harshit_Raj_14/subscribe"><em>https://medium.com/@Harshit_Raj_14/subscribe</em></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2de9808d16dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working in C# quiz]]></title>
            <link>https://medium.com/@Harshit_Raj_14/working-in-c-quiz-539877e995b0?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/539877e995b0</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[quiz]]></category>
            <category><![CDATA[meta]]></category>
            <category><![CDATA[coursera]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Wed, 20 Dec 2023 04:11:18 GMT</pubDate>
            <atom:updated>2023-12-20T04:11:18.197Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMcKZcjsVP7rGuF9IprMCg.png" /></figure><p><strong>Question 1<br> True or false? C# is similar to C, C++, Java and JavaScript. Select the best answer.</strong><br> a) True<br> b) False</p><blockquote><strong>Answer: a) True</strong></blockquote><p><strong>Question 2<br> True or false? Pascal case is used when naming a class, record or struct. Select the best answer.</strong><br> a) True<br> b) False</p><blockquote><strong>Answer: a) True</strong></blockquote><p><strong>Question 3<br> True or false. Coding conventions make developers focus more on layout. Select the best answer.</strong><br> a) True<br> b) False</p><blockquote><strong>Answer: b) False</strong></blockquote><p><strong>Question 4<br> When naming a private or internal field, which naming convention should you use?</strong><br> a) All caps<br> b) Snake case<br> c) Pascal case<br> d) Camel case</p><blockquote><strong>Answer: d) Camel case</strong></blockquote><p><strong>Question 5<br> Which script provides an excellent way of easily managing things that need to happen after a delay or over the course of time? Select the best answer.</strong><br> a) Force<br> b) IF statement<br> c) Torque<br> d) Coroutine</p><blockquote><strong>Answer: d) Coroutine</strong></blockquote><p><strong>Question 6<br> What are some of the useful features in the Unity Manual that you could use? Select all that apply.</strong><br> a) An index that allows you to search by topic<br> b) A button to switch between a specific topic in Unity Manual and Scripting API library<br> c) Sample game design documents that you can use as templates<br> d) Ability to copy code samples</p><blockquote><strong>Answer: a) An index that allows you to search by topic, b) A button to switch between a specific topic in Unity Manual and Scripting API library, d) Ability to copy code samples</strong></blockquote><p><strong>Question 7<br> In which window can you attach a script to a GameObject?</strong><br> a) Hierarchy<br> b) Scene<br> c) Game<br> d) Inspector</p><blockquote><strong>Answer: d) Inspector</strong></blockquote><p><strong>Question 8<br> True or false? The component name, the class and the filename of the script should all have the same name. Select the best answer.</strong><br> a) True<br> b) False</p><blockquote><strong>Answer: a) True</strong></blockquote><p><strong>Question 9<br> How do you enable or disable a component in Unity? Select the best answer.</strong><br> a) Use the enabled flag.<br> b) Use the Remove flag.<br> c) Use the Escape button.<br> d) Use the Destroy function.</p><blockquote><strong>Answer: a) Use the enabled flag.</strong></blockquote><p><strong>Question 10<br> A click on a Collider or a GUI text element is detected by which function?</strong><br> a) OnCollision<br> b) OnClick<br> c) OnDetect<br> d) OnMouseDown</p><blockquote><strong>Answer: d) OnMouseDown</strong></blockquote><h3>DO THIS OR I WILL BE SAD 🥺</h3><p>It would be great if you can also share some good problems in the comments to help others and check your knowledge based on questions asked by others.</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, latest tech news, tutorials, Coding question solutions, Editorials, Interview Tips and many more stuff that you are bound to like.</p><p>Also, I write articles for freelancing so you can contact me through the below link.</p><blockquote><em>If you liked this article, do support me in this endeavor by </em><strong><em>following me on medium</em></strong><em> and get latest updates to my amazing and helpful articles.</em></blockquote><blockquote><em>You can encourage me to write more on: </em><a href="https://ko-fi.com/medusaverse"><em>https://ko-fi.com/medusaverse</em></a></blockquote><blockquote><strong><em>I will be happy to Connect with you</em></strong><em> : </em><a href="https://linktr.ee/harshit_raj_14"><em>https://linktr.ee/harshit_raj_14</em></a></blockquote><blockquote>Did my articles amaze you? Why not subscribe to my newsletter to get the first update whenever I upload a new one:</blockquote><blockquote><a href="https://medium.com/@Harshit_Raj_14/subscribe">https://medium.com/@Harshit_Raj_14/subscribe</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=539877e995b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Assets and player control quiz]]></title>
            <link>https://medium.com/@Harshit_Raj_14/assets-and-player-control-quiz-accb80bdf4e8?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/accb80bdf4e8</guid>
            <category><![CDATA[coursera]]></category>
            <category><![CDATA[quiz]]></category>
            <category><![CDATA[meta]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Wed, 20 Dec 2023 04:04:06 GMT</pubDate>
            <atom:updated>2023-12-20T04:04:06.587Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMcKZcjsVP7rGuF9IprMCg.png" /></figure><p><strong>Question 1: What is the first step in the asset workflow process?</strong></p><blockquote>Answer: Import</blockquote><p><strong>Question 2: Which step in the asset workflow refers to adding assets into the Unity Editor? Select the best answer.</strong></p><p>a. Load</p><p>b. Import</p><p>c. Build</p><p>d. Distribute</p><blockquote>Answer: b. Import</blockquote><p><strong>Question 3: Which step in the asset workflow process involves giving users access to built files?</strong></p><blockquote>Answer: Distribute</blockquote><p><strong>Question 4: Screen size is a type of asset used in Unity.</strong></p><p>a. True</p><p>b. False</p><blockquote>Answer: b. False</blockquote><p><strong>Question 5: When importing assets into Unity, where can you right-click to begin the importing assets process? Select the best answer.</strong></p><p>a. Script</p><p>b. Project window</p><p>c. Update() method field</p><p>d. Vector3 field</p><blockquote>Answer: b. Project window</blockquote><p><strong>Question 6: Which tool in Unity helps you in relocating the position of your camera? Select the best answer.</strong></p><p>a. Hand tool</p><p>b. Move tool</p><p>c. Scale tool</p><p>d. Rect tool</p><blockquote>Answer: b. Move tool</blockquote><p><strong>Question 7: Which axes are used for adjusting the position of your camera in Unity? Select the best answer.</strong></p><p>a. 1st, 2nd, and 3rd axes</p><p>b. A, B, and C axes</p><p>c. Left, right, and center axes</p><p>d. X, Y, and Z axes</p><blockquote>Answer: d. X, Y, and Z axes</blockquote><p><strong>Question 8: What component can you add to 3D objects in Unity to simulate physics?</strong></p><p>a. RigidBody</p><p>b. Collision</p><p>c. ReactionDev</p><p>d. Outer mesh</p><blockquote>Answer: a. RigidBody</blockquote><p><strong>Question 9: Which of the following is the best way to name a script in Unity? Select the best answer.</strong></p><p>a. follow player</p><p>b. followplayer</p><p>c. FollowPlayer</p><p>d. _follow_player</p><blockquote>Answer: c. FollowPlayer</blockquote><p><strong>Question 10: The LateUpdate() method overrides the Update() method.</strong></p><p>a. True</p><p>b. False</p><blockquote>Answer: b. False</blockquote><h3>DO THIS OR I WILL BE SAD 🥺</h3><p>It would be great if you can also share some good problems in the comments to help others and check your knowledge based on questions asked by others.</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, latest tech news, tutorials, Coding question solutions, Editorials, Interview Tips and many more stuff that you are bound to like.</p><p>Also, I write articles for freelancing so you can contact me through the below link.</p><blockquote><em>If you liked this article, do support me in this endeavor by </em><strong><em>following me on medium</em></strong><em> and get latest updates to my amazing and helpful articles.</em></blockquote><blockquote><em>You can encourage me to write more on: </em><a href="https://ko-fi.com/medusaverse"><em>https://ko-fi.com/medusaverse</em></a></blockquote><blockquote><strong><em>I will be happy to Connect with you</em></strong><em> : </em><a href="https://linktr.ee/harshit_raj_14"><em>https://linktr.ee/harshit_raj_14</em></a></blockquote><blockquote>Did my articles amaze you? Why not subscribe to my newsletter to get the first update whenever I upload a new one:</blockquote><blockquote><a href="https://medium.com/@Harshit_Raj_14/subscribe">https://medium.com/@Harshit_Raj_14/subscribe</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=accb80bdf4e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with Unity quiz]]></title>
            <link>https://medium.com/@Harshit_Raj_14/getting-started-with-unity-quiz-be26fd7eeb6e?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/be26fd7eeb6e</guid>
            <category><![CDATA[coursera]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[quiz]]></category>
            <category><![CDATA[meta]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Wed, 20 Dec 2023 03:52:49 GMT</pubDate>
            <atom:updated>2023-12-20T03:52:49.463Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMcKZcjsVP7rGuF9IprMCg.png" /></figure><p><strong>1. True or false: App-based AR provides users with an AR experience that takes advantage of the device’s hardware.</strong></p><p>a) True</p><p>b) False</p><blockquote>Answer: a) True</blockquote><p><strong>2. What is the goal of real-time software? Select the best answer.</strong></p><p>a) To give users ample time to see what they created</p><p>b) To render images so quickly that users won’t notice delays</p><p>c) To limit the number of new ideas</p><p>d) To increase the number of iterations</p><blockquote>Answer: b) To render images so quickly that users won’t notice delays</blockquote><p><strong>3. True or false: Unity has free personal licensing to show content to under 100,000 users.</strong></p><p>a) True</p><p>b) False</p><blockquote>Answer: a) True</blockquote><p><strong>4. True or false: The Scene view in the Unity Editor provides an interactive view into the world you are creating.</strong></p><p>a) True</p><p>b) False</p><blockquote>Answer: a) True</blockquote><p><strong>5. Which type of document in the pre-production phase of the production cycle defines the scope of what you’re going to create? Select the best answer.</strong></p><p>a) Design document</p><p>b) Storyboard</p><p>c) Project plan</p><p>d) Project charter</p><blockquote>Answer: d) Design document</blockquote><p><strong>6. True or false: A project plan is used to manage a project’s progress and schedule.</strong></p><p>a) True</p><p>b) False</p><blockquote>Answer: a) True</blockquote><p><strong>7. What type of questions should you be prepared to answer in an interview?</strong></p><blockquote>Answer:</blockquote><p><strong>8. True or false: You should include narrative introductions to each project in your portfolio.</strong></p><p>a) True</p><p>b) False</p><blockquote>Answer: a) True</blockquote><p><strong>9. What is a tool developers commonly use to showcase their work? Select the best answer.</strong></p><p>a) MicrosoftⓇ OneDrive</p><p>b) Google Drive</p><p>c) GitHub</p><p>d) Dropbox</p><blockquote>Answer: c) GitHub</blockquote><p><strong>10. What is a package in Unity? Select the best answer.</strong></p><p>a) A package in Unity is a tool used for 3D development.</p><p>b) A package in Unity is a grouping of code.</p><p>c) A package in Unity is a collection of platform-specific subsystems.</p><p>d) A package in Unity is a container that stores various types of features or assets.</p><blockquote>Answer: d) A package in Unity is a container that stores various types of features or assets.</blockquote><p><strong>11. What is the difference between app-based AR and web AR? Select the best answer.</strong><br> a. Web AR allows for more complex content and higher definition.<br> b. With app-based AR, the user runs a web-based application in the browser on their mobile device.<br> c. App-based AR provides access to limited hardware, which allows for simpler content and assets.<br> d. App-based AR requires the user to download an app, while web AR runs web-based applications in a browser on their mobile device.</p><blockquote>Answer: App-based AR requires the user to download an app, while web AR runs web-based applications in a browser on their mobile device.</blockquote><p><strong>12. Which type of rendering allows users to interact with a project without any noticeable delay? Select the best answer.</strong><br> a. Interactive<br> b. Real-time<br> c. Non-interactive<br> d. Offline</p><blockquote>Answer: Real-time</blockquote><p><strong>13. Which window in the Unity Editor do you use to view and create your 3D world?</strong><br> a. Hierarchy window<br> b. Project window<br> c. Scene window<br> d. Inspector window</p><blockquote>Answer: Scene window</blockquote><p><strong>14. At which point in a project should design documents be created? Select the best answer.</strong><br> a. During the post-production phase<br> b. During the production phase<br> c. During the client review phase<br> d. During the pre-production phase</p><blockquote>Answer: During the pre-production phase</blockquote><p><strong>15. Which document is used to manage a project’s progress and schedule? Select the best answer.</strong><br> a. Game design document<br> b. Project charter<br> c. Project plan<br> d. Design document</p><blockquote>Answer: Project plan</blockquote><p><strong>16. True or false: Technical questions in an interview may include inquiries into your knowledge of product features such as AR Session, AR Core, AR Kit, and AR Foundation in Unity.</strong><br> a. True<br> b. False</p><blockquote>Answer: True</blockquote><p><strong>17. What elements should be included in a portfolio? Select all that apply.<br></strong> a. A download option for the portfolio items<br> b. An overview of your skills and the projects included in the portfolio<br> c. Narrative introductions to each project<br> d. Date of birth and ethnicity</p><blockquote>Answer: An overview of your skills and the projects included in the portfolio, Narrative introductions to each project.</blockquote><p><strong>18. What does GitHub allow you to do?</strong><br> a. Manage project progress<br> b. Collaborate on software development projects<br> c. Create 3D worlds<br> d. Showcase AR content</p><blockquote>Answer: Collaborate on software development projects</blockquote><h3>DO THIS OR I WILL BE SAD 🥺</h3><p>It would be great if you can also share some good problems in the comments to help others and check your knowledge based on questions asked by others.</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, latest tech news, tutorials, Coding question solutions, Editorials, Interview Tips and many more stuff that you are bound to like.</p><p>Also, I write articles for freelancing so you can contact me through the below link.</p><blockquote>If you liked this article, do support me in this endeavor by <strong>following me on medium</strong> and get latest updates to my amazing and helpful articles.</blockquote><blockquote>You can encourage me to write more on: <a href="https://ko-fi.com/medusaverse">https://ko-fi.com/medusaverse</a></blockquote><blockquote><strong>I will be happy to Connect with you</strong> : <a href="https://linktr.ee/harshit_raj_14">https://linktr.ee/harshit_raj_14</a></blockquote><blockquote><em>Did my articles amaze you? Why not subscribe to my newsletter to get the first update whenever I upload a new one:</em></blockquote><blockquote><a href="https://medium.com/@Harshit_Raj_14/subscribe"><em>https://medium.com/@Harshit_Raj_14/subscribe</em></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be26fd7eeb6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Generative AI: Quiz]]></title>
            <link>https://medium.com/@Harshit_Raj_14/introduction-to-generative-ai-quiz-a0d8ada5327f?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0d8ada5327f</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ai-quiz]]></category>
            <category><![CDATA[quiz]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Thu, 07 Dec 2023 13:53:43 GMT</pubDate>
            <atom:updated>2023-12-07T13:53:43.759Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*2Xq14Cx2KmApc08Ehxci2A.png" /><figcaption>Introduction to Generative AI</figcaption></figure><h3>Q1) What is an example of both a generative AI model and a discriminative AI model?</h3><blockquote>(a) A generative AI model could be trained on a dataset of images of cats and then used to classify new images of cats. A discriminative AI model could be trained on a dataset of images of cats and dogs and then used to predict new images as either cats or dogs.</blockquote><blockquote>(b) A generative AI model does not need to be trained on a dataset of images of cats and then used to generate new images of cats, because the images were already generated by using AI. A discriminative AI model could be trained on a dataset of images of cats and dogs and then used to classify new images as either cats or dogs.</blockquote><blockquote>(c) A generative AI model could be trained on a dataset of images of cats and then used to generate new images of cats. A discriminative AI model could be trained on a dataset of images of cats and dogs and then used to classify new images as either cats or dogs.</blockquote><blockquote>(d) A generative AI model could be trained on a dataset of images of cats and then used to cluster images of cats. A discriminative AI model could be trained on a dataset of images of cats and dogs and then used to predict as either cats or dogs.</blockquote><h3><strong>Correct Answer!</strong></h3><p>A generative AI model could be trained on a dataset of images of cats and then used to generate new images of cats. A discriminative AI model could be trained on a dataset of images of cats and dogs and then used to classify new images as either cats or dogs.</p><h3>Q2) What is a prompt?</h3><blockquote>(1) A prompt is a short piece of text that is given to the large language model as input, and it can be used to control the output of the model in many ways.</blockquote><blockquote>(2) A prompt is a short piece of text that is given to the small language model (SLM) as input, and it can be used to control the output of the model in many ways.</blockquote><blockquote>(3) A prompt is a short piece of code that is given to the large language model as input, and it can be used to control the output of the model in many ways.</blockquote><blockquote>(4) A prompt is a long piece of text that is given to the large language model as input, and it cannot be used to control the output of the model.</blockquote><blockquote>(5) A prompt is a short piece of text that is given to the large language model as input, and it can be used to control the input of the model in many ways.</blockquote><h3>Correct Answer</h3><p>A prompt is a short piece of text that is given to the large language model as input, and it can be used to control the output of the model in many ways.</p><h3>Q3. What is Generative AI?</h3><blockquote>Generative AI is a type of artificial intelligence (AI) that can create new content, such as discrete numbers, classes, and probabilities. It does this by learning from existing data and then using that knowledge to generate new and unique outputs.</blockquote><blockquote>Generative AI is a type of artificial intelligence (AI) that can create new content, such as text, images, audio, and video. It does this by learning from existing data and then using that knowledge to generate new and unique outputs.</blockquote><blockquote>Generative AI is a type of artificial intelligence (AI) that can only create new content, such as text, images, audio, and video by learning from new data and then using that knowledge to predict a discrete, supervised learning output.</blockquote><blockquote>Generative AI is a type of artificial intelligence (AI) that can only create new content, such as text, images, audio, and video by learning from new data and then using that knowledge to predict a classification output.</blockquote><h3>Correct Answer</h3><p>Generative AI is a type of artificial intelligence (AI) that can create new content, such as text, images, audio, and video. It does this by learning from existing data and then using that knowledge to generate new and unique outputs.</p><h3>Q4) What are foundation models in Generative AI?</h3><blockquote>A foundation model is a large AI model both post and pre-trained on a vast quantity of data that was “designed to be adapted” (or fine-tuned) to a wide range of downstream tasks, such as sentiment analysis, image captioning, and object recognition.</blockquote><blockquote>A foundation model is a large AI model post-trained on a vast quantity of data that was “designed to be adapted” (or fine-tuned) to a wide range of downstream tasks, such as sentiment analysis, image captioning, and object recognition.</blockquote><blockquote>A foundation model is a large AI model pretrained on a vast quantity of data that was “designed to be adapted” (or fine-tuned) to a wide range of upstream tasks, such as sentiment analysis, image captioning, and object recognition.</blockquote><blockquote>A foundation model is a small AI model pretrained on a small quantity of data that was “designed to be adapted” (or fine-tuned) to a wide range of downstream tasks, such as sentiment analysis, image captioning, and object recognition.</blockquote><blockquote>A foundation model is a large AI model pretrained on a vast quantity of data that was “designed to be adapted” (or fine-tuned) to a wide range of downstream tasks, such as sentiment analysis, image captioning, and object recognition.</blockquote><h3>Correct Answer!</h3><p>A foundation model is a large AI model pre-trained on a vast quantity of data that is “designed to be adapted” (or fine-tuned) to a wide range of downstream tasks, such as sentiment analysis, image captioning, and object recognition.</p><h3>Q5) Hallucinations are words or phrases that are generated by the model that are often nonsensical or grammatically incorrect.</h3><p>What are some factors that can cause hallucinations? Select three options.</p><blockquote>The model is trained on too much data.</blockquote><blockquote>The model is not given enough context.</blockquote><blockquote>The model is not trained on enough data</blockquote><blockquote>The model is trained on noisy or dirty data.</blockquote><h3>Correct Answer</h3><ol><li>The model is not given enough context.</li><li>The model is trained on noisy or dirty data.</li><li>The model is not trained on enough data.</li></ol><h3>DO THIS OR I WILL BE SAD 🥺</h3><p>It would be great if you can also share some good problems in the comments to help others and check your knowledge based on questions asked by others.</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, latest tech news, tutorials, Coding question solutions, Editorials, Interview Tips and many more stuff that you are bound to like.</p><p>Also, I write articles for freelancing so you can contact me through the below link.</p><blockquote><em>If you liked this article, do support me in this endeavor by </em><strong><em>following me on medium</em></strong><em> and get latest updates to my amazing and helpful articles.</em></blockquote><blockquote><em>You can encourage me to write more on: </em><a href="https://ko-fi.com/medusaverse"><em>https://ko-fi.com/medusaverse</em></a></blockquote><blockquote><strong><em>I will be happy to Connect with you</em></strong><em> : </em><a href="https://linktr.ee/harshit_raj_14"><em>https://linktr.ee/harshit_raj_14</em></a></blockquote><blockquote>Did my articles amaze you? Why not subscribe to my newsletter to get the first update whenever I upload a new one:</blockquote><blockquote><a href="https://medium.com/@Harshit_Raj_14/subscribe">https://medium.com/@Harshit_Raj_14/subscribe</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0d8ada5327f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CodeChef Starters 104 Editorial]]></title>
            <link>https://medium.com/@Harshit_Raj_14/starters-104-editorial-07293d259bf4?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/07293d259bf4</guid>
            <category><![CDATA[codechef]]></category>
            <category><![CDATA[competitive-programming]]></category>
            <category><![CDATA[faang-interview]]></category>
            <category><![CDATA[programming-tips]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 11:05:24 GMT</pubDate>
            <atom:updated>2023-10-19T11:09:06.979Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*I8igK-aCaM2i9BTOexA41Q.png" /></figure><p>Welcome to the editorial for <a href="https://www.codechef.com/START104D?order=desc&amp;sortBy=successful_submissions"><strong>Starters 104</strong></a>.</p><h3>Double Rent</h3><pre>import java.util.*;<br>class Codechef{<br> public static void main (String[] args){<br>  Scanner sc = new Scanner(System.in);<br>  int n=sc.nextInt();<br>  System.out.println(2*n);<br> }<br>}</pre><h3>Pizza Cutting</h3><pre>import java.util.*;<br>class Codechef{<br> public static void main (String[] args){<br>  Scanner sc = new Scanner(System.in);<br>  int t=sc.nextInt();<br>  while(t--&gt;0){<br>      int n=sc.nextInt();<br>      int possible=0;<br>      if(n==1 || n%2==0) possible=1;<br>      if(possible==1) System.out.println(&quot;YES&quot;);<br>      else System.out.println(&quot;NO&quot;);<br>  }<br> }<br>}</pre><h3>Santa and Chocolates</h3><pre>import java.util.*;<br>class Codechef{<br> public static void main (String[] args){<br>  Scanner sc = new Scanner(System.in);<br>  int t=sc.nextInt();<br>  while(t--&gt;0){<br>      int n=sc.nextInt(); //no of children<br>      int k=sc.nextInt(); //difference of choclates atmost<br>      int sum=0;<br>      int arr[] = new int[n];<br>      for(int i=0;i&lt;n;i++){<br>          arr[i]=sc.nextInt();<br>          sum+=arr[i];<br>      }<br>      if(n&gt;sum) System.out.println(&quot;NO&quot;);<br>      else if(sum%n==0) System.out.println(&quot;YES&quot;);<br>      else{<br>          int val=0;<br>          //distribute first everyone equal<br>          int left = sum%n;<br>          int equal=sum-left; //let this be groudn state=0;<br>          int ans[] = new int[n];<br>          int index=0;<br>          while(left!=0){<br>              if(index&gt;=n) index=0;<br>              ans[index]++;<br>              index++;<br>              left--;<br>          }<br>          if(ans[0]-ans[n-1]&gt;k) System.out.println(&quot;NO&quot;);<br>          else System.out.println(&quot;YES&quot;);<br>      }<br>  }<br> }<br>}</pre><h4>LOGIC — -</h4><p>Objective : to distribute the candies in such a way that the atmost difference between any two children is k.</p><p>Case I: n&gt;sum =&gt; no of children more than number of candies =&gt; failed<br>As each child need to have atleast one candy</p><p>Case II : sum%n==0 =&gt; each child can have sum/n candies with difference 0</p><p>Case III: sum&gt;n =&gt; A general case<br>First we try to say we distributed equal candies to all that is : equal= sum — (sum%n)<br>So, left candies = sum%n<br>Now we try to distribute these candies in loop<br>The max difference will exist between first element and last element<br>If that difference is greater than k we fail otherwise pass</p><h3>GCD and LCM</h3><h4>Method I : O(k log(n))</h4><pre>import java.util.*;<br>class Codechef{<br> public static void main (String[] args){<br>  Scanner sc = new Scanner(System.in);<br>  int t=sc.nextInt();<br>  while(t--&gt;0){<br>      int x=sc.nextInt(); <br>      int y=sc.nextInt();<br>      int k=sc.nextInt();<br>      int equal=0;<br>      while(k--&gt;0 &amp;&amp; equal==0){<br>          if(x==y){<br>              equal=1;<br>              continue;<br>          }<br>          //first step<br>          int gd=gcd(x,y);<br>          if(x&gt;=y) x=gd;<br>          else y=gd;<br>          //second step<br>          int lc=(x*y)/gd;    //LCM x HCF = one number x other number<br>          if(x&gt;=y) x=lc;<br>          else y=lc;<br>      }<br>      System.out.println(x+y);<br>  }<br> }<br> <br> public static int gcd(int a, int b){<br>     if (b == 0) return a;<br>     if(a==b) return a;<br>        else return gcd(b, a % b);<br>    }   <br>}</pre><h4>LOGIC — -</h4><p>Just do what the question says</p><p>Observations :<br>If x and y are same (x==y) no matter how many operations you apply : final sum = x+y</p><p>Otherwise, perform the steps : <br>Everytime you find gcd or lcm replace it with the largest element<br>Continue to apply operation k times</p><h4>Method II: O(log (n))</h4><pre>import java.util.*;<br>class Codechef{<br> public static void main (String[] args){<br>  Scanner sc = new Scanner(System.in);<br>  int t=sc.nextInt();<br>  while(t--&gt;0){<br>      int x=sc.nextInt(); <br>      int y=sc.nextInt();<br>      int k=sc.nextInt();<br>      int g=gcd(x,y);<br>      int sum=0;<br>      if (k &lt;= 1) sum = g + Math.min(x, y);<br>      else sum=2*g;<br>      System.out.println(sum);<br>  }<br> }<br> <br> public static int gcd(int a, int b){<br>     if (b == 0) return a;<br>     if(a==b) return a;<br>        else return gcd(b, a % b);<br>    }<br>}</pre><h4>LOGIC — -</h4><p>Case I : k=0,1<br>First apply GCD<br>(X,Y) =&gt; (g, y) =&gt; for sure now that g is a factor of y and y&lt;x<br>Now if you apply lcm on (g,y) =&gt; you still get y only because g is a factor of y =&gt; since g&lt;y, let’s make y lcm which is y again<br>sum = g+y = g + min(x,y)</p><p>Case II: k&gt;1<br>In next step we again apply gcd again getting g and this time replacing y with g<br>Now we have x=g, y=g<br>Two equal number meaning<br>lcm = g<br>No matter how many times k you apply =&gt; max sum=2^g</p><h3>Maximise Sum</h3><pre>import java.util.*;<br>class Codechef{<br> public static void main (String[] args){<br>  Scanner sc = new Scanner(System.in);<br>  int t=sc.nextInt();<br>  while(t--&gt;0){<br>      int n=sc.nextInt();<br>      int arr[] = new int[n];<br>      int sorted=1;<br>      int sum=0;<br>      for(int i=0;i&lt;n;i++){<br>          arr[i]=sc.nextInt();<br>          sum+=arr[i];<br>          if(i&gt;0 &amp;&amp; arr[i]&lt;arr[i-1]) sorted=0; <br>      }<br>      if(sorted==1) System.out.println(sum);<br>      else{<br>          int greatL[] = new int[n];<br>          greatL[0]=arr[0];<br>          int greatR[] = new int[n];<br>          greatR[n-1]=arr[n-1];<br>          for(int i=1;i&lt;n;i++){<br>              if(greatL[i-1]&gt;arr[i]) greatL[i]=greatL[i-1];<br>              else greatL[i]=arr[i];<br>          }<br>          for(int i=n-2;i&gt;=0;i--){<br>              if(greatR[i+1]&gt;arr[i]) greatR[i]=greatR[i+1];<br>              else greatR[i]=arr[i];<br>          }<br>          long sum2=arr[0]+arr[n-1];<br>          for(int i=1;i&lt;n-1;i++){<br>              arr[i]=Math.max(arr[i], Math.min(greatL[i], greatR[i]));<br>              sum2+=arr[i];<br>          }<br>          System.out.println(sum2);<br>      }<br>  }<br> }<br>}</pre><h4>LOGIC — -</h4><p>Observation:<br>Case I: sorted<br>If array is sorted or all elements equal =&gt; you shouldn’t apply the operation as it will never help to increase the value.<br>In such case just output their sum.</p><p>Case II: Unsorted<br>We cannot apply operation on first and last element.<br>Calculate for each index in between the max great on their left and max great on their right.<br>This will help to decide to pick which element form left or right if we want an exchange.<br>Now check if element is less than the greatL and greatR. Now pick the smaller of the two and apply the operation.</p><p>Now calculate sum finally.</p><h3>Lexicographically Largest</h3><pre>import java.util.*;<br>class Codechef{<br> public static void main (String[] args){<br>  Scanner sc = new Scanner(System.in);<br>  int t=sc.nextInt();<br>  while(t--&gt;0){<br>      int n=sc.nextInt();<br>      int m=sc.nextInt(); //upperbound<br>      int arr[] = new int[n];<br>      for(int i=0;i&lt;n;i++){<br>          arr[i]=sc.nextInt();<br>      }<br>      int b[] = new int[n];<br>      b[0]=arr[0];<br>      for(int i=1;i&lt;n;i++){<br>          b[i]=solve(arr[i], m, arr[i-1]);<br>      }<br>      for(int i=0;i&lt;n;i++){<br>          System.out.print(b[i]+&quot; &quot;);<br>      }<br>      System.out.println();<br>  }<br> }<br> <br> public static int solve(int gcd, int m, int prevgcd){<br>     int num=m/gcd;<br>     num*=gcd;<br>     for(int i=x;i&gt;=1;i-=gcd){ //we iterate backwards to get the largest value first<br>         if((i%gcd==0)){<br>             if(GCD(prevgcd, i)==gcd) return i;<br>         }<br>     }<br>     return 1;<br> }<br> <br> public static int GCD(int a, int b){<br>     if (b == 0) return a;<br>     if(a==b) return a;<br>        else return GCD(b, a % b);<br>    }<br>}</pre><h4>LOGIC — -</h4><p>Conclusion: a[0] = gcd(b[0]) = b[0]</p><p>How?<br>a[i] = gcd(b[0], b[1],…. b[i])<br>=&gt; a[i] = gcd(gcd(b[0], b[1],…b[i-1]), b[i])<br>=&gt; a[i] = gcd(a[i-1], b[i])<br>Now since we have got an upper bound for b as m<br>We check which is the largest possible element by checking from 1-&gt;m for each b[i] since we already know a’s<br>Now calculate max sum</p><p>If you understood brute force till now,<br>We will add the magic step.</p><p>We need to find the largest number that is num&lt;=m , such that gcd (num ,a[i-1])=a[i]. <br>So we find the maximum number which is &lt;=m and a[i] is a factor.<br>something like num=m/a[i];<br>now even if num is not a multiple of a[i], we just again multiply with a[i] to make it. <br>num*=a[i]<br>Now we iterate from num to 1 and check which value <br>To reduce the number of iterations we know that the next gcd fulfilling value will only exist, when each step is reduced by gcd itself.</p><h3>LINK TO CODES</h3><h4>All the codes are available on my GitHub repo — <a href="https://github.com/Harshit-Raj-14/My-CodeChef-Solutions">repo link</a></h4><h3>DO THIS OR I WILL BE SAD 🥺</h3><p>It would be great if you can also share your explanation with us if you did something different and would consider it worth sharing otherwise best of luck solving these problems.</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, latest tech news, tutorials, Coding question solutions, Editorials, Interview Tips and many more stuff that you are bound to like.</p><p>Also, I write articles for freelancing so you can contact me through the below link.</p><blockquote>If you liked this article, do support me in this endeavor by <strong>following me on medium</strong> and get latest updates to my amazing and helpful articles.</blockquote><blockquote>You can encourage me to write more on: <a href="https://ko-fi.com/medusaverse">https://ko-fi.com/medusaverse</a></blockquote><blockquote><strong>I will be happy to Connect with you</strong> : <a href="https://linktr.ee/harshit_raj_14">https://linktr.ee/harshit_raj_14</a></blockquote><blockquote><em>Did my articles amaze you? Why not subscribe to my newsletter to get the first update whenever I upload a new one:</em></blockquote><blockquote><a href="https://medium.com/@Harshit_Raj_14/subscribe"><em>https://medium.com/@Harshit_Raj_14/subscribe</em></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07293d259bf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Question — Prove To Me That You Are Smart]]></title>
            <link>https://medium.com/@Harshit_Raj_14/interview-question-prove-to-me-that-you-are-smart-271872af5ec4?source=rss-785d0962c550------2</link>
            <guid isPermaLink="false">https://medium.com/p/271872af5ec4</guid>
            <category><![CDATA[interviewing]]></category>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[interview-tips]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Harshit Raj]]></dc:creator>
            <pubDate>Tue, 17 Oct 2023 10:37:08 GMT</pubDate>
            <atom:updated>2023-10-17T10:37:08.818Z</atom:updated>
            <content:encoded><![CDATA[<h3>Interview Question — Prove To Me That You Are Smart</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*STVLlDD0AbFXFPmvvposWw.png" /></figure><p><strong>Interviewer: Prove to me that you’re smart</strong>.</p><p><strong>Candidate:</strong> Oh, that’s quite easy. I can even make you admit I’m smart.</p><p><strong>Interviewer: </strong>How?</p><p><strong>Candidate: </strong>Consider this: There are just the two of us here. One of us must be more intelligent than the other. I’m here to apply for a job, and you’re conducting the interview from across the table. If I were the smarter one, I would be sitting in your chair, and you would be sitting in mine. The fact that you’re interviewing me shows that you’re the <strong>smarter</strong> one. What does that say about me?</p><p><strong>Interviewer: </strong>You’re smart.</p><p><strong>Candidate: 😎.</strong></p><p>Verdict — Selected.</p><h3>Why the interviewer asked this question:</h3><blockquote>The interviewer posed this question to assess the candidate’s intelligence or cleverness. By asking, “<strong>Prove to me that you’re smart</strong>,” the interviewer wanted to gauge the candidate’s ability to think on their feet and display their <strong>problem-solving skills</strong>.</blockquote><blockquote>This question also allowed the interviewer to see how the candidate approached a somewhat tricky situation and presented their thoughts logically.</blockquote><p>The interviewer might have been looking for creativity and confidence in the candidate’s response, as well as the ability to make a convincing argument. Ultimately, this question was a way to evaluate the candidate’s <strong>critical thinking</strong> and <strong>communication skills</strong>, which are often important qualities for the job.</p><p><strong>Hope you enjoyed going through the article. You can follow me to get the latest update when I upload more such amazing article.</strong></p><h3>Who am I?</h3><p>Just someone who is enthusiastic to write what he likes. Tech blogs, latest tech news, tutorials, Coding question solutions, Editorials, Interview Tips and many more stuff that you are bound to like.</p><p><strong>Also, I write articles for freelancing so you can contact me through the below social links.</strong></p><blockquote>If you liked this article, do support me in this endeavor by <strong>following me on medium</strong> and get latest updates to my amazing and helpful articles.</blockquote><blockquote>You can encourage me to write more on: <a href="https://ko-fi.com/medusaverse">https://ko-fi.com/medusaverse</a></blockquote><blockquote><strong>I will be happy to Connect with you</strong> : <a href="https://linktr.ee/harshit_raj_14">https://linktr.ee/harshit_raj_14</a></blockquote><blockquote><em>Did my articles amaze you? Why not subscribe to my newsletter to get the first update whenever I upload a new one:</em></blockquote><blockquote><a href="https://medium.com/@Harshit_Raj_14/subscribe"><em>https://medium.com/@Harshit_Raj_14/subscribe</em></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=271872af5ec4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>