🚀 LeetCode Daily Challenge – Count Operations to Obtain Zero (#2169) 🧩 Problem Statement Given two integers num1 and num2, perform operations until either of them becomes 0. In one operation, if num1 >= num2, replace num1 = num1 - num2, else num2 = num2 - num1. Return the total number of operations performed. 💡 Approach : Instead of performing subtraction repeatedly (which is inefficient), we can directly calculate how many times one number can be subtracted from the other using integer division (/) and modulo (%). This idea is similar to the Euclidean Algorithm used to find the GCD of two numbers. Steps: While both num1 and num2 are not zero: Add num1 / num2 to the count (this represents how many subtractions happen at once). Update num1 = num1 % num2. Swap num1 and num2 to continue. Return the total count. ⏱️ Time Complexity: O(log(min(num1, num2))) — Each iteration reduces one of the numbers significantly (like in GCD). 💾 Space Complexity: O(1) — Constant extra space used. #LeetCode #Coding #DSA #Learning #ProblemSolving #Consistency
How to Count Operations to Zero with LeetCode Challenge
More Relevant Posts
-
🚀 Day 103 of My LeetCode Journey — Problem 61: Rotate List 💡 Problem Insight: Today’s problem was about rotating a linked list to the right by k places. That means shifting each node forward while the last node loops back to the head — a great test of both logic and pointer control. 🧠 Concept Highlight: The trick lies in: Connecting the list into a cycle (by linking the tail to the head). Finding the new head after length - (k % length) steps. Breaking the cycle to finalize the rotated list. This problem reinforces key ideas about circular linked lists, modular arithmetic, and efficient traversal. 💪 Key Takeaway: Rotation teaches that sometimes progress isn’t linear — moving in circles helps you find new beginnings in unexpected ways. ✨ Daily Reflection: Every linked list problem continues to refine my understanding of structure and precision — the true backbone of algorithmic thinking. #Day103 #LeetCode #100DaysOfCode #LinkedList #ProblemSolving #RotateList #TwoPointerTechnique #DSA #CodingJourney #LearnByDoing #SoftwareEngineering
To view or add a comment, sign in
-
-
🔥 Day 92 of My LeetCode Journey — Problem 28: Find the Index of the First Occurrence in a String 💡 Problem Insight: Today’s problem was about finding the first occurrence of a substring (needle) inside another string (haystack). Essentially, it’s like implementing your own version of the strStr() function — a classic problem in string searching. 🧠 Concept Highlight: This challenge sharpens understanding of string traversal and pattern matching. The intuitive solution uses simple iteration and substring comparison, while the optimized approach can involve algorithms like KMP (Knuth-Morris-Pratt) for efficient searching. 💪 Key Takeaway: Sometimes, even built-in functions hide deep logic beneath simplicity — mastering these fundamentals builds confidence for more advanced string algorithms. ⚙️ Daily Reflection: Every search begins with clarity — whether in code or in life. Precision and patience always lead to the right match. #Day92 #LeetCode #100DaysOfCode #StringSearch #PatternMatching #ProblemSolving #DSA #CodingJourney #LearnByDoing #SoftwareEngineering
To view or add a comment, sign in
-
-
💻 Day 6 of Week 2 #Learning_Of_DSA 🚀 Today’s #LeetCode_Problem_2395 – Find Subarrays With Equal Sum 🔢 Some problems remind us that patterns hold more power than complexity 💡 Today’s challenge: Given an array, determine whether there exist two subarrays of length 2 with equal sum. 🧠 Approach: Used a Set to store sums of consecutive pairs. While traversing, for each pair (nums[i] + nums[i + 1]) — if the sum already exists in the Set → we found equal subarrays ✅ This logic gives an O(n) time solution — clean, efficient, and elegant. 💬 Takeaway: Every DSA problem is a small mirror of real-world software design — → detect patterns early → handle repetitions smartly → and always value simplicity over complication ⚙️ “The best code is not the most complex one — it’s the most readable one.” ✨ #LeetCode #DSA #LearnInPublic #CodingJourney #ProblemSolving #SoftwareEngineering #CareerGrowth #100DaysOfCode #MERNStack #TechWithPurpose #CodeNewbie #Algorithms
To view or add a comment, sign in
-
-
⚡ Day 97 of My LeetCode Journey — Problem 328: Odd Even Linked List 💡 Problem Insight: Today’s problem focused on rearranging a singly linked list so that all nodes at odd indices come first, followed by all even-indexed nodes — while maintaining their relative order. A great challenge to test how well you understand pointer manipulation! 🧠 Concept Highlight: The solution revolves around re-linking nodes using two pointers — one tracking odd nodes and another for even nodes. By carefully connecting them, we achieve the rearrangement in-place without extra space. It’s a smart exercise in linked list restructuring and pointer logic. 💪 Key Takeaway: Organizing efficiently — whether in data or in life — often means rearranging, not replacing. A small change in order can create big clarity. ✨ Daily Reflection: Linked lists truly train the mind to think sequentially and structurally — every link counts, just like every day of consistent learning. #Day97 #LeetCode #100DaysOfCode #LinkedList #ProblemSolving #DSA #CodingJourney #LearnByDoing #SoftwareEngineering #Pointers
To view or add a comment, sign in
-
-
🚀 Day 37 of #100DaysOfCode Challenge 🚀 🧠 Problem: 🧩 LeetCode 282 — Expression Add Operators (Hard) This problem was all about exploring backtracking with arithmetic logic. We’re given a string of digits and need to insert +, -, or * between them to reach a target value. ⚙️ Approach Used backtracking to: -Pick every possible substring as the next number. -Try adding each operator before it (+, -, *). -Track three things: -current value → total so far -previous operand → to handle multiplication correctly -expression → the string we’re building -Also skipped invalid paths like numbers with leading zeros. 📘 Learning -Understood how to evaluate expressions on the fly without using eval(). -Learned to manage operator precedence (* before +/-) using recursion and previous operand adjustment. -Realized that some problems can’t be optimized further — they test how well you can prune and organize recursion. #100DaysOfCode #DSA #CodingChallenge #StriversSheet #ProblemSolving #TakeUForward #Recursion #CodingInterview #ProgrammingTips #LeetCode #Backtracking
To view or add a comment, sign in
-
-
🎯 Day 83 of #100DaysOfCode 🔹 Problem: Count the Digits That Divide a Number – LeetCode ✨ Approach: A simple yet elegant digit-based problem! I extracted each digit of the number using modulo and division, then checked whether the digit cleanly divides the original number. Every valid digit increases the count — a perfect use-case for number breakdown and modular arithmetic. 🔢⚡ 📊 Complexity Analysis: ⏱ Time Complexity: O(d) — where d is the number of digits 💾 Space Complexity: O(1) — no extra data structures used ✅ Runtime: 0 ms (Beats 100% 🚀) ✅ Memory: 42.29 MB 🔑 Key Insight: Even basic problems sharpen precision — breaking numbers digit-by-digit reinforces strong logical thinking and clean coding habits. Sometimes the simplest loops teach the most. ✨ #LeetCode #100DaysOfCode #DSA #NumberTheory #ModularArithmetic #CleanCode #EfficientCoding #LogicBuilding #TechJourney #ProgrammingChallenge #CodingDaily
To view or add a comment, sign in
-
-
Day 6 – LeetCode Challenge Today, I solved Problem #128: “Longest Consecutive Sequence” using C++. 🔍 Problem Overview: The task is to find the length of the longest consecutive elements sequence in an unsorted integer array. The key challenge is to ensure the solution works in O(n) time complexity. 💡 Approach: To achieve linear time, I used an unordered_set to quickly check if a number exists. For each number, I only begin counting a sequence when it is the start of a new streak (i.e., (num - 1) does not exist in the set). This ensures each number is processed only once. 🧠 Algorithm Design: Insert all elements into an unordered_set for O(1) average lookups. For every number, check if it's the start of a sequence. If yes, count forward (num + 1, num + 2, ... ) while elements exist in the set. Track and update the maximum streak length. ⏱ Time Complexity: O(n) 📌 Space Complexity: O(n) #LeetCode #CPlusPlus #DSA #100DaysOfCode #ProblemSolving #Algorithms #CodingChallenge #TechCommunity #GeetaUniversity
To view or add a comment, sign in
-
-
🌟 Day 93 of My LeetCode Journey — Problem 686: Repeated String Match 💡 Problem Insight: Today’s problem explored how many times string A must be repeated so that string B becomes a substring of it. It’s a fun mix of string repetition and pattern matching — testing both logic and edge-case awareness. 🧠 Concept Highlight: The core idea is to keep repeating A until it’s at least as long as B, then check if B exists within it (or one more repetition). This problem reinforces concepts of string concatenation, searching, and boundary conditions in text processing. 💪 Key Takeaway: Sometimes, solutions aren’t about complexity but about knowing when to stop repeating — in both coding and persistence! ✨ Daily Reflection: Simple problems like these highlight the beauty of algorithmic reasoning — transforming trial-and-error into structured logic. #Day93 #LeetCode #100DaysOfCode #StringMatching #ProblemSolving #DSA #CodingJourney #LearnByDoing #SoftwareEngineering #Persistence
To view or add a comment, sign in
-
-
Day 12 of my Coding Challenge Problem: Rearrange Array Elements by Sign Question: Given an array containing both positive and negative integers, rearrange the elements so that positives and negatives alternate — starting with a positive number — while keeping their original order. Approach: For this problem, I used the index-based placement technique: Assigned even indices for positive numbers and odd indices for negative numbers. Iterated through the array once and placed each number directly in its correct position. Used two pointers — one for positive and one for negative indices — to fill the result array efficiently. Key Insights: Eliminated the need for separate positive and negative lists. Time Complexity: O(n) Space Complexity: O(n) A clean and efficient approach using index mapping and pointer logic. #Day12 #100DaysOfCode #DSA #CodingChallenge #LeetCode #ProgrammingJourney #ProblemSolving #CPP
To view or add a comment, sign in
-
-
Today, I learned two things: I cannot solve a LIS problem, and how to solve a LIS problem. For some peculiar reason, I didn't use this algorithm (though I thought I did). It's pretty straightforward when you read about it, but it did puzzle me a bit when I tried to understand it. I encountered it while solving a hard problem on LeetCode; I solved it using DFS, optimized DFS, and optimized BFS with an indegree map, but none of them finished on time. Only a modified LIS approach was mentioned as a valid solution (others were correct, but "too" slow). That's why it's important to learn basic algorithms. It's not that you'll be asked to solve the problems that directly ask about these specific solutions, but it might be mixed into a bigger problem, so it's annoying to get stuck in a small detail while understanding the overall approach. The post: https://lnkd.in/dtJW7F9A The problem: https://lnkd.in/dcwHHN9B #LeetCode #DSATips #DSA #ThinkDSA #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
keep grinding champ :) Matta Veera Venkata Ramana