Day 3/366
vishal.codes
Posted on April 3, 2024
π Today's Learning:
π DSA
- Finding All Duplicates (Unsorted array) - Leetcode 442
- Maximum Subarray - Leetcode 53
π Dev
- Why should you use border:transparent instead of border:none.
- How to check which HTML version are you using.
- Difference between HTML4 and HTML5.
- When to use Tailwind, CSS, SCSS and difference among them.
- What are pseudo classes.
π Some Key Highlights:
DSA
Finding All Duplicates (Unsorted array) - Leetcode 442
Brute force
Approach 1 β Iterate through each element β search for its duplicate in rest of the elements to the right β if found push in ans
array.
(T.C. - O(n^2) | S.C. - O(1))
Approach 2 β Make a hash table of n elements β Iterate through nums and fill the hashtable with counts of each element β Iterate through hash table and if count > 1 push to ans
array.
(T.C. O(n) | S.C. O(n))
Optimized Approach - (T.C. O(n) | S.C. O(1))
β Iterate through nums array β for each element calculate index = abs(nums[i]) -1
(subtracting 1 coz range of element start from 1 so this will always give a valid index) β make nums[index] negative, if already negative it means there was a duplicate who earlier made this number negative, so push this element to ans
array.
Maximum Subarray - Leetcode 53
Brute force
Iterate over all subarrays using 2 nested loops to find the maximum sum among all of them.
(T.C. O(n^2))
Optimized Approach - (T.C. O(n) | S.C. O(1))
β Use Kadaneβs algorithm - we carry a subarray sum as long as it gives a positive sum.
β Take currentSum (for calculating the sum of current subarray) and maxSum (for storing the maximum sum so far). If in any iteration, we find currentSum as negative we reset currentSum to 0.
DEV
-
Border Styles: Use
border: transparent
to hide a border while preserving layout, andborder: none
to completely remove it. -
HTML Version Check: Look at the
<!DOCTYPE>
declaration to determine if it's HTML5 or HTML4. - HTML4 vs. HTML5: HTML5 introduced semantic elements, multimedia support, enhanced forms, and graphics capabilities.
-
Styling Tools:
- CSS: Basic styling language.
- SCSS: Enhanced CSS with variables and mixins.
- Tailwind CSS: Utility-first framework for rapid UI development.
- Pseudo-classes: Keywords for styling based on user interaction or document structure.
Posted on April 3, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.