#100DaysOfCode – Day 68 String Manipulation Problem 1:- Largest Odd Number in String Task:- Given a numeric string, return the largest-valued odd number (as a substring) or an empty string if none exists. Example: Input: num = "35427" → Output: "35427" My Approach: Started scanning the string from right to left. The first odd digit encountered marks the end of the required substring. Returned the substring from start to that index. Time Complexity:- O(N) Space Complexity:- O(1) Sometimes, it’s not about complex algorithms just a small logical observation can lead to an efficient solution. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #CodeNewbie #StringManipulation #LogicBuilding #CleanCode
#100DaysOfCode: Finding Largest Odd Number in String
More Relevant Posts
-
#Day-70) LeetCode #3234 – Count Substrings With Dominant Ones Just solved an interesting binary string problem where a substring is considered dominant if the number of 1s is greater than or equal to the square of the number of 0s. 🔍 Challenge: Efficiently count all such substrings in a given binary string. 🧠 My Approach (Java): Used a prefix sum array to track the balance between 1s and 0s Explored substring ranges with a smart condition check Focused on clean logic and edge case handling 📈 Why it matters: This problem blends math with string manipulation and highlights how preprocessing (like prefix sums) can drastically reduce brute-force overhead. 📎 Code snippet attached — open to feedback or alternate strategies! #LeetCode #Java #DSA #BinaryStrings #ProblemSolving #CodingInPublic #TechJourney
To view or add a comment, sign in
-
-
📌 Day 2/100 – Remove Element (LeetCode 27) 🔹 Problem: Given an integer array nums and a value val, remove all instances of that value in-place and return the new length of the array. The order of elements can be changed. 🔹 Approach: Used the two-pointer technique to efficiently modify the array in-place. One pointer iterates through the array, while the other tracks the position to overwrite non-val elements. Returned the position of the second pointer as the new length. 🔹 Key Learning: Strengthened understanding of in-place array manipulation. Improved logic building for pointer movement and conditional overwriting. Learned how to minimize extra space usage while maintaining readability and clarity. Another small yet powerful step toward mastering array-based problems! 💻 🔥 #100DaysOfCode #LeetCode #Java #ProblemSolving #TwoPointers #DSA #CodingJourney
To view or add a comment, sign in
-
-
🌳 Day 60 of #100DaysOfCode 🌳 🔹 Problem: Balanced Binary Tree – LeetCode ✨ Approach: Used a post-order DFS traversal to calculate subtree heights while checking balance at every node. If the height difference of any subtree exceeds 1, return -1 immediately for an early exit — efficient and elegant! ⚡ 📊 Complexity Analysis: Time: O(n) — each node visited once Space: O(h) — recursion stack space, where h is the tree height ✅ Runtime: 0 ms (Beats 100%) ✅ Memory: 44.29 MB 🔑 Key Insight: A balanced tree isn’t just about equal heights — it’s about smart recursion that detects imbalance early, saving both time and memory. 🌿 #LeetCode #100DaysOfCode #Java #DSA #BinaryTree #Recursion #ProblemSolving #AlgorithmDesign #CodeJourney #ProgrammingChallenge
To view or add a comment, sign in
-
-
Day 15 of #251DaysOfDSA Problem: Rotate Image ✨ What I learned: This problem helped me understand how to rotate a matrix in-place using just basic array manipulation. The trick was simple but elegant — first transpose the matrix, then reverse each row. A great example of how breaking down problems into smaller transformations can make them easy to solve. #251DaysOfDSA #LeetCode #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
💡 LeetCode #167 — Two Sum II (Input Array Is Sorted) Today I solved LeetCode Problem 167: Two Sum II — Input Array Is Sorted 🎯 Problem Summary: You are given a sorted array and a target. Return the 1-indexed positions of the two numbers that add up to the target. You must use O(1) extra space. Key Idea: Use the two-pointer technique 👈👉 Start with one pointer at the beginning (left) and one at the end (right). If the sum is too large → move right leftward. If the sum is too small → move left rightward. Stop when you find the pair. This works because the array is already sorted. #LeetCode #Java #DSA #TwoPointers #Algorithms #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
✅Day 43 : Leetcode 540 - Single Element in a Sorted Array #60DayOfLeetcodeChallenge 🧩 Problem Statement You are given a sorted array consisting of integers where every element appears exactly twice, except for one element which appears only once. Your task is to find the single element that appears only once. You must write an algorithm that runs in O(log n) time and uses O(1) space. 💡 My Approach (Using Binary Search) In my approach, I used binary search to efficiently find the single element. I handled edge cases first — when the unique element is at the start or end of the array. Then I applied binary search between low = 1 and high = n - 2. For each mid index, I checked if nums[mid] is different from both its neighbors (nums[mid-1] and nums[mid+1]). If true, that’s the unique element. Otherwise, I used the property of pairs to decide which side to continue searching: If the left half (up to mid) has an even number of elements, the single element is on the right side. Otherwise, it’s on the left side. This method ensures logarithmic time by reducing the search range by half at each step. ⏱️ Time Complexity O(log n) — Binary search divides the array in half each iteration. 💾 Space Complexity O(1) — Constant extra space used. #BinarySearch #LeetCode #DSA #Java #LeetcodeMedium #ArrayProblem #SingleElement #ProblemSolving
To view or add a comment, sign in
-
-
🎯 LeetCode Day 41/50 – Pascal’s Triangle Today’s challenge was about generating Pascal’s Triangle — a classic combinatorial structure where each number is the sum of the two numbers directly above it. 🔺 💡 Concepts used: Recursion to build rows step-by-step Dynamic List handling in Java Base case optimization for smaller triangles 🧩 Key insight: Each row can be constructed from the previous one by summing adjacent elements — a beautiful recursive pattern that reflects mathematical simplicity. 🕒 Runtime: 1 ms (Beats 85.89%) ⚡ 💾 Memory: 42.20 MB (Beats 26.63%) ✅ Result: 30/30 test cases passed — Accepted 🎉 #LeetCode #50DaysOfCode #Java #CodingChallenge #ProblemSolving #PascalTriangle
To view or add a comment, sign in
-
-
✅Day 50 : Leetcode 1283 - Find the Smallest Divisor Given a Threshold #60DayOfLeetcodeChallenge 🧩 Problem Statement: Given an array of integers nums and an integer threshold, find the smallest positive integer divisor such that the sum of each element divided by the divisor (rounded up to the nearest integer) is less than or equal to the threshold. 💡 My Approach: Binary Search on Divisor Range: The smallest possible divisor is 1. The largest possible divisor is the maximum element in nums. Check Function: For a given divisor, calculate the sum of ceil(nums[i] / divisor) for all elements. If the total sum ≤ threshold → we can try smaller divisors. Otherwise, increase the divisor. Repeat until optimal divisor is found. ⏱️ Time Complexity: O(n * log(max(nums))) Each binary search iteration takes O(n) to compute the sum. #Algorithms #BinarySearch #LeetCode #Java #ProblemSolving #DSA #100DaysOfCode #CodeNewbie
To view or add a comment, sign in
-
-
💡 LeetCode #88 — Merge Sorted Array Today I solved LeetCode Problem 88: Merge Sorted Array 🧩 Problem Summary: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. All merging should happen in-place, meaning you can’t use extra space for another array. Key Idea: Use three pointers starting from the end: i → last valid element in nums1 j → last element in nums2 k → last index in nums1 (total length) Compare elements from the back and fill nums1 from the end — this avoids overwriting elements we haven’t processed yet. #LeetCode #Java #DSA #TwoPointers #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
💡 LeetCode #15 — 3Sum Today I solved LeetCode Problem 15: 3Sum 🔍 Problem Summary: Given an integer array nums, return all unique triplets (a, b, c) such that: a + b + c = 0 The solution must not contain duplicate triplets. Key Idea: Use sorting + two pointers to reduce the time from O(n³) to O(n²). Steps: Sort the array. Fix one number (nums[f]) in each iteration. Use two pointers (i and j) to find pairs whose sum equals -nums[f]. Skip duplicates for both the fixed index and the pointer values. This efficiently finds all unique triplets. #LeetCode #Java #DSA #TwoPointers #ProblemSolving #CodingChallenge #Algorithms
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