<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: TUSHAR</title>
    <description>The latest articles on DEV Community by TUSHAR (@teezzzz).</description>
    <link>https://dev.to/teezzzz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3773772%2F3457c530-cb2b-4ff3-906d-0bbea1303660.png</url>
      <title>DEV Community: TUSHAR</title>
      <link>https://dev.to/teezzzz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/teezzzz"/>
    <language>en</language>
    <item>
      <title>Did LeetCode 238 no google no ai</title>
      <dc:creator>TUSHAR</dc:creator>
      <pubDate>Sun, 15 Feb 2026 09:38:09 +0000</pubDate>
      <link>https://dev.to/teezzzz/did-leetcode-238-no-google-no-ai-41l9</link>
      <guid>https://dev.to/teezzzz/did-leetcode-238-no-google-no-ai-41l9</guid>
      <description>&lt;p&gt;*&lt;em&gt;&lt;em&gt;Correct me if i am wrong :)&lt;/em&gt;&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
**&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;**&lt;br&gt;
We are given an array with integer elements , We need to result an array wher ith element is product of all the elements of orignal array but not self hence problem is Product of array expect self&lt;/p&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;h2&gt;
  
  
  First Thoughts
&lt;/h2&gt;

&lt;p&gt;**Take two nested for loops , for each element iterate the whole array using inner loop make a product. Time Complexity - O(n^2)&lt;br&gt;
Use a for loop to get a product of all the elements of the array..then divide product with each element which will give you the product expect self for each element.&lt;/p&gt;

&lt;p&gt;Both of them are correct approach but given the problem constraints it is specified that You must write an algorithm that runs in O(n) time and without using the division operation.Where as the first approach gives time complexity of O(n^2) and second approach uses division operator(/) both of them are not allowed.&lt;/p&gt;

&lt;p&gt;**&lt;/p&gt;

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

&lt;p&gt;**The correct approach here is to use the Prefix Product and Suffix Product.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is prefix product?&lt;br&gt;
**The word **Prefix&lt;/strong&gt; mean &lt;strong&gt;before&lt;/strong&gt; i.e &lt;strong&gt;Those who come before&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;example - &lt;strong&gt;ABCD&lt;/strong&gt; is given String or a word, so the prefix values of &lt;strong&gt;D&lt;/strong&gt; are &lt;strong&gt;ABC&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In our case &lt;strong&gt;prefix product&lt;/strong&gt; for each element will be product of that element and all the elements that has appeared before that element.&lt;/p&gt;

&lt;p&gt;product of that element and all the elements that has appeared before that element&lt;br&gt;
&lt;strong&gt;What is suffix product?&lt;br&gt;
**The word **Suffix&lt;/strong&gt; means &lt;strong&gt;after&lt;/strong&gt; i.e &lt;strong&gt;Those who come after&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;example - &lt;strong&gt;ABCD&lt;/strong&gt; is given String or a word, so the suffix values of &lt;strong&gt;A&lt;/strong&gt; are &lt;strong&gt;BCD&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In our case &lt;strong&gt;suffix product&lt;/strong&gt; for each element will be &lt;strong&gt;product of that element and all the elements that has appeared after that element&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Key Insight &lt;br&gt;
For ans element at i nums[i] = prefix[i-1] * suffix[i+1]&lt;/p&gt;

&lt;p&gt;Edge case&lt;br&gt;
Since At position 0 and last(nums.length - 1) their will be no before or after product so ,&lt;/p&gt;

&lt;p&gt;prefix[0] = nums[0]&lt;/p&gt;

&lt;p&gt;suffix[nums.length-1] = nums[nums.length - 1]&lt;/p&gt;

&lt;p&gt;therfore answer for,&lt;/p&gt;

&lt;p&gt;nums[i] = suffix[i+1] {if i == 0}&lt;/p&gt;

&lt;p&gt;nums[nums.length - 1] = prefix[nums.length - 2] {if i == nums.length}&lt;/p&gt;

</description>
      <category>code</category>
      <category>leetcode</category>
      <category>100daysofcode</category>
    </item>
  </channel>
</rss>
