🚀 Day 45 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Convert to Base 7 Problem Insight: Convert a given integer into its base 7 representation. The challenge is to handle both positive and negative numbers correctly while building the result efficiently. Approach: • Handled edge case when number is 0 • Checked if the number is negative and stored the sign • Used modulo (% 7) to extract digits • Divided the number by 7 in each step • Stored digits using StringBuilder and reversed at the end • Added negative sign if required Time Complexity: • O(log₇ n) Space Complexity: • O(log₇ n) (for storing result) Key Learnings: • Base conversion can be efficiently done using division & modulo • StringBuilder helps optimize string operations • Handling negative numbers is an important edge case • Reverse logic is commonly used in digit-building problems Takeaway: Breaking a problem into small steps makes even number system conversions simple and intuitive! #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
Converting to Base 7 with LeetCode
More Relevant Posts
-
🚀 Day 16 of #100DaysOfCode Today’s problem: Minimum Absolute Difference 📊 🔍 Problem Understanding: Given an array of distinct integers, find all pairs with the minimum absolute difference. 🧠 Approach: First, I sorted the array Then compared adjacent elements (since minimum difference will always be between neighbors in sorted order) Tracked the minimum difference and stored all valid pairs 👉 Key Insight: Sorting reduces unnecessary comparisons and simplifies the problem ⚙️ Concepts Used: Sorting (Arrays.sort) Greedy observation (check only neighbors) List handling for storing pairs 📊 Complexity: ⏱️ Time Complexity: O(N log N) (due to sorting) 💾 Space Complexity: O(N) (for storing result pairs) 📚 Key Learnings: Learned how sorting simplifies problems Understood how to reduce complexity from brute force O(N²) → O(N log N) Improved thinking in terms of patterns and optimization 💯 Result: ✔️ Accepted (All test cases passed) ✔️ Runtime: 1 ms (100%) 🔥 ✔️ Clean and efficient solution Sometimes the best optimization is just sorting + observation 💡 Let’s keep building consistency 🚀 #Day16 #100DaysOfCode #Java #DSA #LeetCode #ProblemSolving #Sorting
To view or add a comment, sign in
-
-
🚀 Day 43 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Sum of Unique Elements Problem Insight: Find elements in an array that appear exactly once and calculate their total sum. Approach: • Used a frequency array to count occurrences of each number • Traversed the array to build frequency • Added only those elements to sum whose frequency is exactly 1 Time Complexity: • O(n) Space Complexity: • O(1) (fixed size array used for constraints) Key Learnings: • Frequency array is faster than HashMap when range is fixed • Two-pass approach makes logic clear and simple • Always check constraints before choosing data structure Takeaway: Right data structure makes the solution simple and efficient 🚀 #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🔥 Day 60 / 100 – LeetCode Challenge ✅ Solved: 160. Intersection of Two Linked Lists Today’s problem was all about understanding pointer behavior and memory references in linked lists. 💡 Key Insight: Instead of comparing values, we compare node references. If two linked lists intersect, they will share the same tail nodes. 🚀 Approach Used (Optimal): Two pointers (pA, pB) Traverse both lists When one reaches the end, switch to the other list They eventually meet at the intersection node (or null) 🧠 Why it works: Both pointers travel equal distance → LengthA + LengthB, aligning perfectly without extra space. ⏱ Complexity: Time: O(m + n) Space: O(1) 💻 Result: ✔️ Accepted (41/41 test cases) ⚡ Runtime: 1 ms (Beats 99.94%) 📌 Takeaway: Sometimes the smartest solution is not about extra data structures, but about clever traversal. #Day60 #100DaysOfCode #LeetCode #Java #DSA #LinkedList #CodingJourney
To view or add a comment, sign in
-
-
Day 66/100 🚀 | #100DaysOfDSA Solved LeetCode 14 – Longest Common Prefix today. The task was to find the longest common prefix string among an array of strings. Initially, I couldn’t come up with this optimal approach and first solved it using a brute-force O(n²) method, comparing characters across all strings. Approach (Optimized): Used sorting to simplify the problem. • Sorted the array of strings. • Took the first and last strings after sorting. • Compared characters of both strings until they differ. • The common prefix between these two will be the answer for all strings. This works because after sorting, the most different strings will be at the extremes. Time Complexity: O(n log n + m) (where n = number of strings, m = length of prefix comparison) Space Complexity: O(1) (ignoring sorting space) Key takeaway: Sorting can sometimes reduce multi-string comparison problems to just comparing two extreme cases, making the solution much simpler and efficient. #100DaysOfDSA #LeetCode #DSA #Java #Strings #Sorting #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 77/100 Completed ✅ 🚀 Solved LeetCode – Search a 2D Matrix II (Java) ⚡ Implemented an efficient approach by starting from the top-right corner of the matrix and eliminating rows or columns based on comparison with the target. This reduces the search space at every step, achieving O(m + n) time complexity. 🧠 Key Learnings: • Smart traversal in a sorted 2D matrix • Eliminating search space using row & column properties • Moving left (col--) when value is greater • Moving down (row++) when value is smaller • Better than brute-force (O(m × n)) approach 💯 This problem improved my understanding of matrix traversal strategies and how to optimize searching using sorted properties. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #problemSolving #optimization #arrays #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 49 🔍 Solved: Largest Number Today I worked on an interesting problem where the goal was to arrange numbers such that they form the largest possible number. 💡 Key Insight: Instead of normal sorting, we compare numbers based on their string combinations (like "ab" vs "ba"). 📌 Approach: ✔ Converted integers to strings ✔ Used a custom comparator for sorting ✔ Compared (a + b) and (b + a) ✔ Sorted in descending order based on best combination ✔ Handled edge case when all elements are 0 Why this works: By comparing two numbers in different orders, we ensure that the arrangement always produces the maximum possible value when concatenated. 🎯 What I Learned: This problem taught me that sorting can go beyond numbers—custom logic and string manipulation are powerful tools in problem solving. #Java #DSA #LeetCode #Sorting #Comparator #CodingJourney #ProblemSolving #TechSkills 🚀
To view or add a comment, sign in
-
-
🚀 Day 48 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Sort Array By Parity Problem Insight: Rearrange the array so that all even numbers come before odd numbers. The order of elements doesn’t matter. Approach: • Used the two-pointer technique (partition logic) • Maintained a pointer j to track the position for even numbers • Traversed the array using i • Whenever an even number is found, swapped it with index j and incremented j • This ensures all even elements move to the front in a single pass Time Complexity: O(n) Space Complexity: O(1) (in-place solution) Key Learnings: • Two-pointer technique is very useful for array partitioning problems • Swapping helps avoid extra space usage • This pattern is similar to problems like moving zeros or segregating positives/negatives Takeaway: Simple logic + optimal approach = clean and efficient solution. Consistency is making these patterns easier to recognize! #DSA #Java #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀Day 4/100 – LeetCode Journey Today’s problem: 3Sum Closest🔥 Approach (Sorting + Two Pointer)💡 👉 Workflow (step-by-step): 1. Sort the array → helps in using two-pointer efficiently 2. Fix one element (nums[k]) 3. Use two pointers: i = k + 1 (left) j = n - 1 (right) 4. Calculate: sum = nums[k] + nums[i] + nums[j] 5. Compare: If this sum is closer to target than previous → update closestSum ✅ 6. Move pointers: If sum < target → i++ (increase sum) If sum > target → j-- (decrease sum) Repeat until all possibilities are checked. Key Idea: We are not finding exact match, we are finding the closest possible sum to target ⚡ Time Complexity: O(n²) → outer loop + two pointer 🧠 Space Complexity: O(1) → no extra space used Thanks to RAVI KUMAR Sir for guidance! Getting better every day 🚀 #100DaysOfCode #LeetCode #DSA #Java
To view or add a comment, sign in
-
-
🚀 Day 38 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Maximum Product of Two Elements in an Array. Problem Insight: Given an integer array, the goal is to find two elements such that: (nums[i] - 1) * (nums[j] - 1) is maximized Approach: • First, sort the array using Arrays.sort() • Use two nested loops to check all possible pairs • For each pair, calculate → (nums[i] - 1) * (nums[j] - 1) • Keep track of the maximum product Time Complexity: • O(n²) — due to nested loops Space Complexity: • O(1) — no extra space used Key Learnings: • Understanding operator precedence is very important in expressions • Sorting helps in simplifying many problems • Even simple problems can have optimized solutions beyond brute force Takeaway: Brute force helps in understanding the problem deeply, but optimization (like using the two largest elements directly) makes the solution efficient 🚀 #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Arrays
To view or add a comment, sign in
-
-
Day 114 - LeetCode Journey Solved LeetCode 572 – Subtree of Another Tree ✅ This problem focuses on determining whether one binary tree is a subtree of another. A subtree must match both in structure and node values, which makes it more than just a simple value comparison problem. Approach: I used a recursive strategy combining two key steps: Traverse each node of the main tree At every node, check if the subtree starting from that node is identical to the given subRoot For checking identical trees, I implemented a helper function that compares: • Node values • Left subtree • Right subtree If all match, we confirm the subtree exists. Otherwise, we continue searching in the left and right branches of the main tree. Complexity Analysis: • Time Complexity: O(n × m) in the worst case, where n is nodes in root and m is nodes in subRoot • Space Complexity: O(h), due to recursion stack Key Takeaways: • Tree problems often require combining traversal + comparison logic • Breaking problems into helper functions simplifies implementation • Understanding recursion flow is crucial for tree-based questions 🌳 All test cases passed successfully 🎯 #LeetCode #DSA #BinaryTree #Recursion #Java #CodingJourney #ProblemSolving
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