🧠 Day 40 / 100 – DSA Practice Solved String to Integer (atoi) on LeetCode 🔢➡️🧮✅ 🔹 Problem: Convert a string into a 32-bit signed integer while handling whitespace, signs, non-digit characters, and overflow conditions. 🔹 Approach: Followed a step-by-step simulation: Ignore leading whitespaces Handle optional + / - sign Convert digits while checking for overflow Stop at first non-digit character 🔍 Key Insight: Careful handling of edge cases like overflow and invalid input is crucial in this problem 🔹 Complexity: ⏱ Time → O(n) 📦 Space → O(1) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 1 ms (Beats 100%) One of the best problems to master string parsing & edge case handling 🚀 #Day40 #100DaysOfCode #LeetCode #Java #DSA #Strings #Algorithms #CodingJourney
LeetCode DSA Practice: String to Integer Conversion
More Relevant Posts
-
🧠 Day 37 / 100 – DSA Practice Solved Multiply Strings on LeetCode ✖️🔢✅ 🔹 Problem: Multiply two non-negative numbers given as strings without using built-in big integer libraries. 🔹 Approach: Simulated the manual multiplication method: Multiply each digit of num1 with each digit of num2 Store results in an array Handle carry properly Build final string while skipping leading zeros 🔍 Key Insight: Using an array of size m + n helps manage positions just like pen-and-paper multiplication 🔹 Complexity: ⏱ Time → O(m × n) 📦 Space → O(m + n) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 3 ms (Beats 85%) Loved implementing this classic math-based approach without using built-in shortcuts 🚀 #Day37 #100DaysOfCode #LeetCode #Java #DSA #Strings #Algorithms #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🧠 Day 41 / 100 – DSA Practice Solved Count and Say on LeetCode 🔢🗣️✅ 🔹 Problem: Generate the nth term of the count-and-say sequence, where each term is derived by describing the previous term. 🔹 Approach: Used an iterative + string building approach: Start with base case "1" For each iteration, read the previous string Count consecutive characters Append count + character to form next term 🔍 Key Insight: This problem is essentially Run-Length Encoding (RLE) applied repeatedly on strings 🔹 Complexity: ⏱ Time → O(n × m) (m = length of generated string) 📦 Space → O(m) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 8 ms (Beats 62%) Great problem to improve string manipulation & pattern recognition 🚀 #Day41 #100DaysOfCode #LeetCode #Java #DSA #Strings #RLE #Algorithms #CodingJourney
To view or add a comment, sign in
-
-
Day 48 of Daily DSA 🚀 Solved LeetCode 48: Rotate Image ✅ Problem: Given an n x n matrix, rotate the image by 90° clockwise — in-place (without using extra space). Approach: Used a two-step transformation: Transpose the matrix Reverse each row Steps: Traverse upper triangle and swap → matrix[i][j] ↔ matrix[j][i] For each row: Use two pointers (left, right) Swap elements to reverse the row Matrix gets rotated in-place ⏱ Complexity: • Time: O(n²) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.56 MB In-place transformations are powerful — no extra space, just smart manipulation 💡 #DSA #LeetCode #Java #Matrix #Arrays #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 45 of Daily DSA 🚀 Solved LeetCode 867: Transpose Matrix ✅ Problem: Given a 2D matrix, return its transpose (rows become columns and columns become rows). Approach: Created a new matrix and swapped indices while traversing. Steps: Get number of rows and columns Create a new matrix of size cols x rows Traverse original matrix Assign: trans[j][i] = matrix[i][j] Return the new matrix ⏱ Complexity: • Time: O(n × m) • Space: O(n × m) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 46.46 MB Simple transformations like transpose build strong fundamentals for matrix-based problems 💡 #DSA #LeetCode #Java #Arrays #Matrix #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🔥 Day 364 – Daily DSA Challenge! 🔥 Problem: 🎯 Find K Closest Elements Given a sorted array arr, an integer k, and a target x, return the k closest elements to x in ascending order. 💡 Key Insight — Binary Search on Window Instead of checking each element, we binary search the starting index of a window of size k. Search space: Possible windows → [0 ... n - k] 🧠 Decision Logic At index mid, compare: Distance of left boundary → x - arr[mid] Distance of right boundary → arr[mid + k] - x We choose direction based on: ⚡ Algorithm Steps ✅ Initialize: left = 0, right = n - k ✅ Binary search: If left side is farther → shift right Else → move left ✅ Final window starts at left ✅ Collect k elements ⚙️ Complexity ✅ Time Complexity: O(log(n - k) + k) (binary search + result building) ✅ Space Complexity: O(k) 💬 Challenge for you 1️⃣ Why do we search on window positions instead of elements? 2️⃣ Can you solve this using a heap approach? 3️⃣ What if array was unsorted? #DSA #Day364 #LeetCode #BinarySearch #SlidingWindow #Arrays #Java #ProblemSolving #KeepCoding
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 136/360 🚀 📌 Topic: Bit Manipulation 🧩 Problem: Number of 1 Bits (Hamming Weight) Problem Statement: Given an integer, return the number of set bits (1’s) present in its binary representation. 🔍 Example: Input: 6 Output: 2 Explanation: Binary of 6 → 110 → 2 set bits 💡 Optimized Approach (Brian Kernighan’s Algorithm): Instead of checking each bit one by one, we use a smart trick: n & (n - 1) removes the rightmost set bit in each iteration This reduces the number of operations to the number of set bits only ⚡ Time Complexity: O(k) (k = number of set bits) ⚡ Space Complexity: O(1) 🚀 Key Takeaway: Using bit manipulation can drastically optimize performance compared to brute force approaches. Always look for patterns in binary operations! #DSA #Coding #Java #BitManipulation #136DaysOfCode #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 56/100 | #100DaysOfDSA 🧠⚡ Today’s problem: String Compression A clean in-place array manipulation problem. Core idea: Compress consecutive repeating characters and store the result in the same array. Approach: • Traverse the array using a pointer • Count consecutive occurrences of each character • Write the character to the array • If count > 1 → write its digits one by one • Move forward and repeat Key insight: We don’t need extra space — just carefully manage read & write pointers. Time Complexity: O(n) Space Complexity: O(1) Big takeaway: In-place algorithms require precise pointer control but give optimal space efficiency. Mastering these improves real-world memory optimization skills. 🔥 Day 56 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Strings #TwoPointers #InPlace #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 35 Today’s focus: Binary Search with index patterns. Problem solved: • Single Element in a Sorted Array (LeetCode 540) Concepts used: • Binary Search • Index parity (even/odd pattern) • Search space reduction Key takeaway: The array is sorted and every element appears twice except one. A key observation: Before the single element, pairs start at even indices After the single element, this pattern breaks. Using binary search: • If mid is even and nums[mid] == nums[mid + 1], the single element lies on the right side • Else, it lies on the left side (including mid) By leveraging this pattern, we can find the answer in O(log n) time and O(1) space. Continuing to strengthen binary search intuition and consistency in problem solving. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
Day 12 of #100DaysOfCode — Sliding Window Today, I worked on the problem “Max Consecutive Ones III” LeetCode. Problem Summary Given a binary array, the goal is to find the maximum number of consecutive 1s if you can flip at most k zeros. Approach At first glance, this problem looks like a brute-force or restart-based problem, but the optimal solution lies in the Sliding Window technique. The key idea is to maintain a window [i, j] such that: The number of zeros in the window does not exceed k Expand the window by moving j Shrink the window by moving i whenever the constraint is violated Instead of restarting the window when the condition breaks, we dynamically adjust it. Key Logic Traverse the array using pointer j Count the number of zeros in the current window If zeros exceed k, move pointer i forward until the window becomes valid again At every step, update the maximum window size Why This Works This approach ensures: Each element is processed at most twice Time Complexity: O(n) Space Complexity: O(1) The most important learning here is understanding how to dynamically adjust the window instead of resetting it, which is a common mistake while applying sliding window techniques. In sliding window problems, always focus on expanding and shrinking the window efficiently rather than restarting the computation. #100DaysOfCode #DSA #SlidingWindow #LeetCode #Java #ProblemSolving #CodingJourney #DataStructures #Algorithms
To view or add a comment, sign in
-
-
**Day 114 of #365DaysOfLeetCode Challenge** Today’s problem: **Keyboard Row (LeetCode 500)** A fun and simple problem focused on **strings + simulation + clean logic**. We need to return words that can be typed using letters from **only one row** of the American keyboard. Rows: * Row 1 → `qwertyuiop` * Row 2 → `asdfghjkl` * Row 3 → `zxcvbnm` 💡 **Core Idea:** For each word: 1️⃣ Convert to lowercase 2️⃣ Identify keyboard row of first character 3️⃣ Check whether every remaining character belongs to same row 📌 **Approach:** * Use strings to represent rows * Use `indexOf()` for membership check * Preserve original word in output ⚡ **Time Complexity:** O(total characters in all words) ⚡ **Space Complexity:** O(result list) **What I learned today:** Even easy problems teach valuable habits: 👉 Clean iteration 👉 Case handling 👉 Efficient validation logic 💭 **Key Takeaway:** Not every challenge needs advanced algorithms. Sometimes simplicity + clean implementation = best solution. #LeetCode #DSA #Strings #Java #CodingChallenge #ProblemSolving #TechJourney #Consistency
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development