How to Get 0 ms on LeetCode 🚀😂 Solved a problem. Got 3 ms. Felt smart for a minute 🧠✨ Then I saw someone with 0 ms. Ego slightly hurt. Am I getting old? Did someone unlock O(0)? Is there a secret JVM setting I missed?? 😭 So I opened their solution… and found this: static { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try (FileWriter fw = new FileWriter("display_runtime.txt")) { fw.write("000"); } })); } Bro didn’t optimize the code. Bro optimized the scoreboard 🏆😂 Honestly… I respect the creativity 🤝🔥 #LeetCode #Java #CodingLife
LeetCode 0 ms Solution Revealed
More Relevant Posts
-
🚀 Day 81 / 100 – LeetCode Daily Challenge 📌 Problem: Minimum Partitions to Decompose a Number (1689) 🧠 Concept: Greedy | String Manipulation Today’s problem was deceptively simple but conceptually rich — finding the minimum number of deci-binary numbers needed to sum up to a given string n. The key insight? 🔍 The answer is simply the maximum digit in the string! Why? Because in any addition of deci-binary numbers (each made of only 0s and 1s), the largest digit in the target number dictates how many numbers are needed in the worst-case scenario. So if the number is "82734", we need at least 8 numbers (one for each unit at the position of '8'). ✅ One pass. One max check. Clean and greedy. 📊 Runtime: 6 ms | Beats 75.56% 💾 Memory: 47.43 MB ✨ Key takeaway: Sometimes the most efficient solution is hiding in plain sight — just read the problem carefully and think about the underlying constraints. #LeetCode #CodingJourney #100DaysOfCode #Day81 #GreedyAlgorithm #Java #ProblemSolving #TechCommunity #DevLife #CodeNewbie
To view or add a comment, sign in
-
-
#Day32 of #365DaysOfCode Today’s LeetCode Practice: 🔹 Container With Most Water (LeetCode 11) Solved a classic two-pointer optimization problem where the goal is to find two lines that together form a container holding the maximum water. 💡 Key Insight: Start with two pointers at both ends. Calculate area using: width × min(height[left], height[right]) Move the pointer with the smaller height inward, because the smaller height limits the water capacity. This guarantees exploring better possibilities efficiently. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Consistency > Motivation. Day by day, improving problem-solving and logical thinking skills #LeetCode #ProblemSolving #Java #CodingJourney #FutureEngineer #Consistency #LearningEveryday
To view or add a comment, sign in
-
-
#Day28 of #365DaysOfCode Today’s LeetCode practice: 🔹 Word Search (LeetCode 79) Solved a backtracking problem where I had to check whether a given word exists in a 2D board by moving horizontally or vertically through adjacent cells. 💡 Key Insight: Start exploring from every cell. If the character matches the current letter of the word, move in all 4 possible directions. Mark the cell as visited and revert the change if the path doesn’t lead to a solution. On to Day 29 🔥 #LeetCode #Java #DSA #ProblemSolving #CodingJourney #Backtracking #Recursion
To view or add a comment, sign in
-
-
💻 Day 37 of #75DaysOfLeetCode Today’s problem: Remove Linked List Elements (Easy) 🔗 The task was to remove all nodes from a linked list that have a specific value. 🧠 Key Learning: The tricky part was handling edge cases — especially when the head node itself needs to be deleted. 💡 I used a dummy node approach, which made the solution clean and avoided special handling for the head. ⚙️ Approach: Create a dummy node pointing to head Traverse the list using a pointer Skip nodes where value == target Return dummy.next ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 🔥 What I learned today: Consistency matters more than difficulty. Even “easy” problems strengthen core concepts like pointers and edge cases. #Day38 #LeetCode #DataStructures #LinkedList #Java #CodingJourney #75DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 21 of my #100DaysOfCode Journey Today, I solved the LeetCode question Contains Duplicate II. The task is to check if there are two equal elements in the array such that their index difference is at most k. ✅ Steps: First, iterate through each element in the array For every element, check only the next k elements Compare values within this limited range If a match is found → return true 💻 My Approach: I used a sliding window + brute force approach (without using HashMap/HashSet). Instead of checking the whole array, I optimized it by limiting the inner loop to k distance only. 🌟 Learning Takeaways: Optimizing brute force can avoid TLE Understanding constraints (like k distance) helps reduce complexity Multiple approaches exist — choosing based on space/time is key #DSA #Java #LeetCode #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 117 🚀 | LeetCode Progress Solved 3 problems today and strengthened array manipulation skills 💪 📌 Problem 1: Sort Array By Parity (#905) – 🟢 Easy 👉 Two-pointer / index swapping technique 👉 Place even numbers at the front while iterating 👉 In-place solution with O(1) extra space 👉 Time Complexity: O(n) Efficient way to partition arrays without extra memory ⚡ 📌 Problem 2: Find All Numbers Disappeared in an Array (#448) – 🟢 Easy 👉 Index marking technique using negative values 👉 Mark visited indices by flipping the sign 👉 Positive indices at the end represent missing numbers 👉 Time: O(n) | Space: O(1) (excluding result list) A clever trick to use the array itself as a hash map 🧠 📌 Problem 3: Minimum Changes to Make an Alternating Binary String (#1758) – 🟢 Easy 👉 Compare with two possible patterns: "010101..." and "101010..." 👉 Count mismatches for both patterns 👉 Return the minimum operations needed 👉 Time Complexity: O(n) Simple logic but great practice for pattern-based string problems 🔍 Small improvements every day lead to big progress over time 📈 #Day117 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #GeekStreak #100DaysOfCod
To view or add a comment, sign in
-
🚀 Day 27 of My LeetCode Journey 📌 Problem: Maximum Product of Three Numbers (LeetCode 628) Today’s challenge was to find the maximum product of any three numbers in an integer array. The important observation is that the maximum product can come from: • The three largest numbers, or • The two smallest numbers (negative values) multiplied by the largest number. 🧠 Approach Used: Single Pass (Tracking Maximum & Minimum Values) Instead of sorting the array, we iterate through the array once and keep track of: The three largest numbers The two smallest numbers Finally, we compute the maximum between: 1️⃣ max1 × max2 × max3 2️⃣ min1 × min2 × max1 ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) This approach avoids sorting and efficiently finds the result in a single traversal of the array. #Day27 #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 520 of #750DaysOfCode 🚀 🔢 1536. Minimum Swaps to Arrange a Binary Grid (LeetCode - Medium) Today I solved an interesting Greedy + Matrix problem. 🧠 Problem Summary We are given an n x n binary grid. In one step, we can swap adjacent rows. The grid is valid only if: 👉 All cells above the main diagonal are 0. We must return the minimum number of swaps needed to make the grid valid, or -1 if it's impossible. 💡 Key Insight For each row i, it must have at least (n - 1 - i) trailing zeros. So instead of checking the entire matrix repeatedly: ✅ Count trailing zeros for every row ✅ Use a greedy approach to place correct rows at correct positions ✅ Bring valid rows upward using adjacent swaps ✅ Count total swaps If at any point no valid row is found → return -1 ⚙️ Approach Used Count trailing zeros for each row For every row position: Find a row below that satisfies required condition Bubble it up using adjacent swaps Maintain swap count ⏱ Time Complexity O(n²) — Works perfectly for n ≤ 200 🧩 What I Learned ✔ How to convert a matrix condition into a trailing zero requirement ✔ How greedy row placement minimizes swaps ✔ Importance of transforming the problem into a simpler representation Consistency > Motivation. One problem at a time. 🚀 #LeetCode #Java #GreedyAlgorithm #ProblemSolving #DataStructures #CodingJourney #750DaysOfCode #Day520
To view or add a comment, sign in
-
-
Day 111 🚀 | LeetCode Grind Continues Solved 3 problems today 💪 1️⃣ Rotate Array 👉 Cyclic replacements to rotate in-place ⏱ O(n) | 📦 O(1) 2️⃣ Relative Ranks 👉 Track original indices + sort scores 👉 Assign medals based on rank 🥇🥈🥉 ⏱ O(n²) | 📦 O(n) 3️⃣ Self Dividing Numbers 👉 Check each digit 👉 No zero, all digits must divide the number ⏱ O(n × digits) Small wins, big consistency 🔥 #Day111 #LeetCode #DSA #Java #GeekStreak #ProblemSolving #CodingJourney
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
Nice share 😂