Posts

Showing posts from February, 2025

CSS Secrets: Underrated Tricks for Stunning UI

Image
CSS Secrets: Underrated Tricks for Stunning UI CSS Secrets: Underrated Tricks for Stunning UI CSS is a powerful tool for creating stunning user interfaces, but some of its most impressive features are often overlooked. In this blog post, I’ll share **5 underrated CSS tricks** that can take your UI design to the next level. Each trick comes with a live example and code snippet so you can easily implement it in your projects. 1. Gradient Text Add a gradient effect to your text for a modern and eye-catching look. Live Example: Gradient Text CSS Code: .gradient-text { background: linear-gradient(45deg, #ff6f61, #3498db); -webkit-background-clip: text; background-clip: text; color: transparent; font-size: 2.5rem; font-weight: bold; } 2. Custom Checkbox Replace the default checkbox with a custom-designed one. Live Example: CSS Code: .custom-checkbox { display: none; ...

6 Unique and Attractive CSS Loaders for Your Website

6 Unique and Attractive CSS Loaders 6 Unique and Attractive CSS Loaders for Your Website Are you looking to add some eye-catching loading animations to your website? Loaders are a great way to keep users engaged while content is being loaded. In this blog post, I’ll show you 6 unique and attractive CSS loaders that you can easily integrate into your website. Each loader comes with its own HTML and CSS code, and I’ve included a live preview so you can see them in action! 1. Rotating Circle with Gradient This loader features a simple rotating circle with a gradient border. HTML Code: <div class="loader-1"></div> CSS Code: .loader-1 { width: 50px; height: 50px; border: 5px solid #f3f4f6; border-top: 5px solid #3498db; border-radius: 50%; animation: spin 1s linear infinite; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } 2. Bouncing Dots ...

LeetCode 15: 3Sum Explained

LeetCode 15: 3Sum Explained LeetCode 15: 3Sum Explained The "3Sum" problem is a classic LeetCode challenge that asks you to find all unique triplets in an array that add up to zero. In this post, I'll provide a detailed explanation and Python solution. Problem Overview Given an array `nums` of *n* integers, find all unique triplets (a, b, c) in `nums` such that a + b + c = 0. Notice that the solution set must not contain duplicate triplets. Solution Here's an efficient Python function to solve the 3Sum problem: def three_sum(nums): result = [] nums.sort() # Important: Sort the array for i in range(len(nums) - 2): if i > 0 and nums[i] == nums[i - 1]: # Skip duplicate elements continue left = i + 1 right = len(nums) - 1 while left This solution first sorts the input array, which is crucial for efficiency and for hand...

LeetCode 14: Longest Common Prefix Explained

LeetCode 14: Longest Common Prefix Explained LeetCode 14: Longest Common Prefix Explained The "Longest Common Prefix" problem is a common LeetCode challenge that asks you to find the longest common prefix string amongst an array of strings. In this post, I'll explain how to solve this problem efficiently in Python. Problem Overview Given an array of strings `strs`, find the longest common prefix string amongst all strings in the array. If there is no common prefix, return an empty string "". Solution Here's a Python function to find the longest common prefix: def longest_common_prefix(strs): if not strs: return "" prefix = strs[0] for i in range(1, len(strs)): while strs[i].find(prefix) != 0: prefix = prefix[:-1] if not prefix: return "" return prefix This function works by fi...

LeetCode 13: Roman to Integer Explained

LeetCode 13: Roman to Integer Explained LeetCode 13: Roman to Integer Explained The problem "Roman to Integer" is a classic LeetCode challenge that tests your understanding of Roman numerals. In this post, I will provide a step-by-step explanation of how to solve this problem in Python. Problem Overview Roman numerals are a system of numerical notation that uses letters to represent numbers. The letters I, V, X, L, C, D, and M represent the numbers 1, 5, 10, 50, 100, 500, and 1000, respectively. To convert a Roman numeral to an integer, you simply add up the values of the letters. However, there are a few exceptions to this rule. For example, the Roman numeral IV represents the number 4, not 6. This is because when a smaller value letter is placed before a larger value letter, it is subtracted from the larger value. Solution Here is a Python function that converts a Roman numeral to an integer: d...

LeetCode Problem #12: Integer to Roman - Explanation and Solutions in Python and JavaScript

LeetCode Problem #12: Integer to Roman - Explanation and Solutions in Python and JavaScript LeetCode Problem #12: Integer to Roman - Explanation and Solutions in Python and JavaScript Introduction The Integer to Roman problem is a classic problem that tests your understanding of number manipulation and string building. It is frequently asked in coding interviews to assess your problem-solving skills. In this post, we'll break down the problem, explain the optimal approach, and provide solutions in both Python and JavaScript. Problem Statement Given an integer num , convert it to a Roman numeral. Example: Input: num = 1994 Output: "MCMXCIV" Explanation: M = 1000, CM = 900, XC = 90, IV = 4. Approach The problem can be solved efficiently using a **greedy algorithm**. Here's the step-by-step approach: Create two lists: ...

LeetCode Problem #11: Container With Most Water - Explanation and Solutions in Python and JavaScript

LeetCode Problem #11: Container With Most Water - Explanation and Solutions in Python and JavaScript LeetCode Problem #11: Container With Most Water - Explanation and Solutions in Python and JavaScript Introduction The Container With Most Water problem is a classic problem that tests your understanding of the two-pointer technique and array manipulation. It is frequently asked in coding interviews to assess your problem-solving skills. In this post, we'll break down the problem, explain the optimal approach, and provide solutions in both Python and JavaScript. Problem Statement Given an array of integers height of length n , where each element represents a vertical line at position i with height height[i] , find two lines that together with the x-axis form a container that holds the most water. Return the maximum amount of water a container can store. Example: ...

LeetCode Problem #10: Regular Expression Matching - Explanation and Solutions in Python and JavaScript

LeetCode Problem #10: Regular Expression Matching - Explanation and Solutions in Python and JavaScript LeetCode Problem #10: Regular Expression Matching - Explanation and Solutions in Python and JavaScript Introduction The Regular Expression Matching problem is a challenging problem that tests your understanding of dynamic programming and string manipulation. It is frequently asked in coding interviews to assess your problem-solving skills. In this post, we'll break down the problem, explain the optimal approach, and provide solutions in both Python and JavaScript. Problem Statement Given an input string s and a pattern p , implement regular expression matching with support for '.' and '*' where: '.' matches any single character. '*' matches zero or more of the preceding element. The matching should cover the en...

LeetCode Problem #9: Palindrome Number - Explanation and Solutions in Python and JavaScript

LeetCode Problem #9: Palindrome Number - Explanation and Solutions in Python and JavaScript LeetCode Problem #9: Palindrome Number - Explanation and Solutions in Python and JavaScript Introduction The Palindrome Number problem is a classic problem that tests your understanding of number manipulation and basic algorithms. It is frequently asked in coding interviews to assess your problem-solving skills. In this post, we'll break down the problem, explain the optimal approach, and provide solutions in both Python and JavaScript. Problem Statement Given an integer x , return true if x is a palindrome, and false otherwise. Example: Input: x = 121 Output: true Explanation: 121 reads the same from left to right and right to left. Approach A palindrome number reads the same backward as forward. Here's the step-by-step approach to solve the problem...

LeetCode 8: String to Integer (atoi) – Python & JavaScript Solutions Explained

LeetCode 8: String to Integer (atoi) - Python & JavaScript Solutions String to Integer (atoi) - LeetCode Problem 8 Difficulty: Medium Problem Statement Implement the atoi function, which converts a string into an integer. Approach & Explanation Remove leading whitespace. Check for a sign (+ or -). Extract numerical digits. Clamp to 32-bit integer limits. Python Solution: import re def myAtoi(s: str) -> int: match = re.match(r'^[\+\-]?\d+', s.lstrip()) if not match: return 0 num = int(match.group()) return max(min(num, 2**31 - 1), -2**31) JavaScript Solution: function myAtoi(s) { let num = parseInt(s.trim(), 10); if (isNaN(num)) return 0; return Math.max(Math.min(num, 2**31 - 1), -(2**31)); } Time Complexity O(n) because we parse each character.

LeetCode 7: Reverse Integer – Python & JavaScript Solutions with Explanation

LeetCode 7: Reverse Integer - Python & JavaScript Solutions Reverse Integer - LeetCode Problem 7 Difficulty: Medium Problem Statement Given a signed 32-bit integer x , return x with its digits reversed. Example Input: x = 123 Output: 321 Approach & Explanation To reverse an integer, we can: Convert it to a string, reverse it, and convert it back. Handle negative numbers by keeping track of the sign. Check for **integer overflow** (if the result exceeds 32-bit limits). Python Solution: def reverse(x: int) -> int: sign = -1 if x JavaScript Solution: function reverse(x) { let sign = x = -(2**31) && rev Edge Cases Large numbers : Reverse must stay within 32-bit range. Negative numbers : Should maintain the sign. Trailing zeros : 120 → 21. Time Complexity O(log n) bec...

LeetCode 6: Zigzag Conversion – Python & JavaScript Solutions Explained

Zigzag Conversion - Python & JavaScript Solutions Zigzag Conversion - LeetCode Problem 6 Difficulty: Medium Problem Statement The string "PAYPALISHIRING" is written in a zigzag pattern with a given number of rows. The characters are then read row by row. Example Input: s = "PAYPALISHIRING", numRows = 3 Output: "PAHNAPLSIIGYIR" Explanation: P A H N A P L S I I G Y I R Approach: Simulating Zigzag Rows (O(n) Complexity) Instead of creating a 2D matrix, we store characters in different row lists and concatenate them. Python Solution: def convert(s: str, numRows: int) -> str: if numRows == 1 or numRows >= len(s): return s rows = [""] * numRows index, step = 0, 1 for char in s: rows[index] += char if index == 0: step = 1 elif index == numRows - 1: ...

LeetCode 5: Longest Palindromic Substring | Optimal Solutions in Python & JS

Longest Palindromic Substring - Python & JavaScript Solutions Longest Palindromic Substring - LeetCode Problem 5 Difficulty: Medium Problem Statement Given a string s , return the longest palindromic substring in s . Example Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer. Approach 1: Expand Around Center (Optimal - O(n²) Complexity) Since a palindrome mirrors around its center, we can expand around each character (odd-length) and each pair (even-length). Python Solution: def longest_palindrome(s: str) -> str: if not s: return "" start, max_length = 0, 0 def expand_around_center(left, right): nonlocal start, max_length while left >= 0 and right max_length: start, max_length = left, right - left + 1 left -= 1 right += 1 ...

LeetCode Problem #4: Median of Two Sorted Arrays - Explanation and Solutions in Python and JavaScript

LeetCode Problem #4: Median of Two Sorted Arrays - Explanation and Solutions in Python and JavaScript LeetCode Problem #4: Median of Two Sorted Arrays - Explanation and Solutions in Python and JavaScript Introduction The Median of Two Sorted Arrays problem is a challenging algorithmic problem frequently asked in coding interviews. It tests your understanding of binary search, arrays, and divide-and-conquer techniques. In this post, we'll break down the problem, explain the optimal approach, and provide solutions in both Python and JavaScript. Problem Statement Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. Example: Input: nums1 = [1, 3], nums2 = [2] Output: 2.0 Explanation: The merged array is [1, 2, 3], and the median is 2.0. Approach The problem can be solved efficiently usin...

LeetCode Problem #3: Longest Substring Without Repeating Characters - Explanation and Solutions in Python and JavaScript

LeetCode Problem #3: Longest Substring Without Repeating Characters - Explanation and Solutions in Python and JavaScript LeetCode Problem #3: Longest Substring Without Repeating Characters - Explanation and Solutions in Python and JavaScript Introduction The Longest Substring Without Repeating Characters problem is a classic string manipulation problem frequently asked in coding interviews. It tests your understanding of sliding windows, hash maps, and string traversal. In this post, we'll break down the problem, explain the optimal approach, and provide solutions in both Python and JavaScript. Problem Statement Given a string s , find the length of the longest substring without repeating characters. Example: Input: s = "abcabcbb" Output: 3 Explanation: The longest substring without repeating characters is "abc", which has a length of 3. App...

LeetCode Problem #2: Add Two Numbers - Explanation and Solutions in Python and JavaScript

LeetCode Problem #2: Add Two Numbers - Explanation and Solutions in Python and JavaScript LeetCode Problem #2: Add Two Numbers - Explanation and Solutions in Python and JavaScript Introduction The Add Two Numbers problem is a classic linked list problem frequently asked in coding interviews. It tests your understanding of linked lists, pointer manipulation, and edge cases. In this post, we'll break down the problem, explain the optimal approach, and provide solutions in both Python and JavaScript. Problem Statement You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. Example: Input: l1 = [2, 4, 3], l2 = [5, 6, 4] Output: [7, 0, 8] Explanation: 342 + 465 = 807. Approach The pro...

LeetCode Problem #1: Two Sum - Explanation and Solutions in Python and JavaScript

LeetCode Problem #1: Two Sum - Explanation and Solutions in Python and JavaScript LeetCode Problem #1: Two Sum - Explanation and Solutions in Python and JavaScript Introduction The Two Sum problem is one of the most popular coding interview questions and is often used to test a candidate's problem-solving and coding skills. In this post, we'll break down the problem, explain the optimal approach, and provide solutions in both Python and JavaScript. Problem Statement Given an array of integers nums and an integer target , return the indices of the two numbers such that they add up to target . You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Input: nums = [2, 7, 11, 15], target = 9 Output: [0, 1] Explanation: nums[0] + nums[1] = 2 + 7 = 9. Approach The brute force approach invo...