π Today's Learning:
π DSA
- Two Sum - Leetcode 1
- Reverse Linked List - Leetcode 206
π Dev
- Difference between inline and block elements.
- What is difference between display:none and display:hidden.
- Flex and Grid which layout approach should you use and when to use.
- Media Queries.
π Some Key Highlights:
DSA
Two Sum - Leetcode 1
Brute force β Iterate through each element β for each element check for the compliment (target - nums[i]) in rest of the elements β if found push both the current elementβs index and the complementβs index in ans array. (T.C. O(n^2) | S.C. O(1))
Optimized Approach β take an unordered map and fill it with element and index key-value pairs. Iterate through the nums array β for each element find the compliment (target - nums[i]) in map, which takes constant time to search β If compliment found push both current element index and compliment index in ans
array (Note: Also while finding compliment ensure that complimentβs index should not be same as current elementβs index. (T.C. O(n) | S.C. O(n))
Reverse Linked List - Leetcode 206
Approach 1 (Brute Force)
Take an extra auxiliary array β copy all linked list data in this array β reverse travel the array and replace linked list data. (Time: O(n) | Space: O(n) - coz of extra array)
Approach 2 (Optimized for space - In place solution - Reversing links)
Take 3 pointers p, q and r β these are sliding pointers (order: r, q, p) β at each pass slide all three to one step right β use q to reverse the link β do this untill p reaches null β At this time q would be at last node β make head point this last node.
(Time: O(n) | Space: O(1) )
DEV
-
Inline vs. Block Elements:
- Block elements are like big building blocks, stacking on top of each other and taking up the full width.
- Inline elements are smaller and fit within a line of text, like links or emphasis.
-
Background Image with Opacity and Text Overlay:
- Use CSS to set a background image on a container and add text on top of it.
- Apply opacity to the background image without affecting the text by using RGBA colors or the opacity property.
-
Display:none vs. Display:hidden:
-
display:none
completely removes an element from the layout. -
display:hidden
hides an element from view but still occupies space in the layout.
-
-
Flexbox vs. CSS Grid Layout:
- Flexbox is great for simpler, one-dimensional layouts like navigation menus.
- CSS Grid is perfect for more complex, two-dimensional layouts with rows and columns.
-
Media Queries:
- Media queries allow you to adapt your website's layout and styles based on different devices and screen sizes.
- They help ensure your website looks fantastic across various devices, from laptops to smartphones.
Top comments (0)