🔥 DSA Challenge – Day 137/360 🚀 📌 Topic: Bit Manipulation / Math 🧩 Problem: Divide Two Integers Problem Statement: Divide two integers without using multiplication, division, and mod operator. Return the quotient truncated toward zero. 🔍 Example: Input: dividend = 10, divisor = 3 Output: 3 💡 Approach: Optimized (Bit Manipulation) 1️⃣ Step 1 – Convert both numbers to long and take absolute values to avoid overflow 2️⃣ Step 2 – Use left shift (<<) to find the largest multiple of divisor 3️⃣ Step 3 – Subtract and accumulate result, then apply correct sign ⏱ Complexity: Time: O(log N) Space: O(1) 📚 Key Learning: Using bit manipulation (left shift) can significantly optimize repeated subtraction problems and avoid time limit issues. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #137DaysOfCode #LeetCode #BitManipulation
Divide Two Integers Without Multiplication or Division
More Relevant Posts
-
🔥 DSA Challenge – Day 135/360 🚀 📌 Topic: Bit Manipulation 🧩 Problem: Check if a Number is Power of 2 Problem Statement: Given an integer n, determine whether it is a power of 2 or not. 🔍 Example: Input: n = 4 Output: true Input: n = 6 Output: false 💡 Approach: Optimized (Bit Manipulation) 1️⃣ Step 1 – If n <= 0, return false (powers of 2 are always positive) 2️⃣ Step 2 – Use bit trick: n & (n - 1) removes the lowest set bit 3️⃣ Step 3 – If result becomes 0, then only one set bit was present ✔ This avoids looping and works in constant time ⏱ Complexity: Time: O(1) Space: O(1) 📚 Key Learning: A number is a power of 2 if it has exactly one set bit in binary representation. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #135DaysOfCode #BitManipulation #LeetCode
To view or add a comment, sign in
-
-
Day 39 #SDE Problems on mathematical optimization and dynamic programming on strings. Solved: • Count Good Numbers • Word Break Key Learning: • “Count Good Numbers” uses fast exponentiation (binary exponentiation) to efficiently compute large powers under modulo. • “Word Break” is a classic DP problem, where we check if a string can be segmented using a dictionary — reinforcing recursion + memoization patterns. #LeetCode #DSA #DynamicProgramming #Recursion #Algorithms #Java #SoftwareEngineering
To view or add a comment, sign in
-
🔥 DSA Challenge – Day 120/360 🚀 📌 Topic: Math + Recursion 🧩 Problem: Count Good Numbers Problem Statement: Count total valid numbers of length n where even indices have 5 choices and odd indices have 4 choices. 🔍 Example: Input: n = 4 Output: 400 💡 Approach: Optimized (Binary Exponentiation) 1️⃣ Step 1 – Count even positions → use (n + 1) / 2 2️⃣ Step 2 – Count odd positions → use n / 2 3️⃣ Step 3 – Compute power using fast exponentiation and multiply ✔ Use formula: 5^(ceil(n/2)) × 4^(floor(n/2)) ✔ Apply modulo to handle large numbers ✔ Use recursion to reduce time complexity ⏱ Complexity: Time: O(log n) Space: O(log n) 📚 Key Learning: Binary Exponentiation helps reduce power calculation from O(n) to O(log n), which is very useful in large constraints problems. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #360DaysOfCode #LeetCode
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 131/360 🚀 📌 Topic: Backtracking / Recursion 🧩 Problem: N-Queens Problem Statement: Place N queens on an N×N chessboard such that no two queens attack each other. 🔍 Example: Input: n = 4 Output: [[".Q..","...Q","Q...","..Q."], ["..Q.","Q...","...Q",".Q.."]] 💡 Approach: Optimized Backtracking (Hashing) 1️⃣ Step 1 – Try placing a queen column by column 2️⃣ Step 2 – Use arrays to check if row & diagonals are safe in O(1) 3️⃣ Step 3 – Place queen → recurse → backtrack if needed ⏱ Complexity: Time: O(N!) Space: O(N) + recursion stack 📚 Key Learning: Using hashing for rows & diagonals avoids repeated checks and makes backtracking much faster ⚡ #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #131DaysOfCode #LeetCode
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
-
-
🚀 DSA Preparation 💪 Solved a basic yet important Array + Two Pointer problem. Focused on rearranging elements by grouping even and odd numbers efficiently. Great for improving in-place operations and partitioning logic 🔥 🧠 Problem 🔎 Sort Array By Parity Given an integer array nums, move all even integers to the beginning followed by all odd integers. 👉 Return any array that satisfies this condition. Example Input: nums = [3,1,2,4] Output: [2,4,3,1] Input: nums = [0] Output: [0] ⚡ Key Learning 📌 Use two pointers / partition approach 📌 Efficiently rearrange elements in one pass 📌 Time Complexity: O(n) → traverse the array once 📌 Space Complexity: O(1) → in-place rearrangement (no extra space) Improving DSA with strong fundamentals 🚀 #DSA #LeetCode #Arrays #TwoPointers #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 130/360 🚀 📌 Topic: Backtracking / DFS on Grid 🧩 Problem: Word Search Problem Statement: Given a 2D grid of characters and a word, check if the word exists by moving in 4 directions (no cell reuse). 🔍 Example: Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]] word = "ABCCED" Output: true 💡 Approach: Backtracking + DFS 1️⃣ Step 1 – Start from every cell matching the first character 2️⃣ Step 2 – Explore 4 directions (up, down, left, right) recursively 3️⃣ Step 3 – Mark visited cells and backtrack after exploring ✔️ Avoid revisiting the same cell ✔️ Stop early when characters don’t match ✔️ Return true as soon as full word is found ⏱ Complexity: Time: O(N * M * 4^L) Space: O(L) (recursion stack) 📚 Key Learning: Backtracking is powerful for exploring all possible paths while avoiding invalid ones using pruning. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #130DaysOfCode #LeetCode #Backtracking
To view or add a comment, sign in
-
-
Day 59 of My DSA Journey Today I solved LeetCode 762 – Prime Number of Set Bits in Binary Representation on . 📌 Problem Given two integers "left" and "right", count how many numbers in this range have a prime number of set bits (1s) in their binary representation. Example: Input: "left = 6, right = 10" Output: "4" --- 🧠 Approach – Bit Manipulation + Prime Check Steps I followed: • For each number in range "[left, right]": - Count number of set bits (1s) using bit manipulation ("n & 1", "n >> 1") • Check if the count is a prime number - Used a predefined list of primes: "{2,3,5,7,11,13,17,19}" • If yes → increment the answer --- ⏱ Time Complexity: "O(n * log n)" Where "n = right - left + 1" (each number takes log n for bit counting) 📦 Space Complexity: "O(1)" — Constant extra space --- 💡 Key Learnings ✔ Practicing Bit Manipulation concepts ✔ Efficiently counting set bits ✔ Combining multiple concepts (bits + prime check) 👉 This problem shows how combining simple ideas can solve interesting problems 🚀 --- Consistency continues — learning something new every day 💪🔥 #100DaysOfCode #DSA #BitManipulation #Math #LeetCode #Java #ProblemSolving #CodingJourney #DeveloperJourney #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
#CodeEveryday — My DSA Journey | Day 4 🧩 Problem Solved: Word Search (LeetCode #79) 💭 What I Learned: Used DFS + backtracking to search for a word in a 2D grid by exploring all possible paths. At each step: ✔️ Checked boundary conditions and character match ✔️ Explored all 4 directions (up, down, left, right) ✔️ Marked the current cell as visited to avoid revisiting ✔️ Backtracked by unmarking the cell after exploration Ensured correctness by stopping early when a mismatch occurs or when the full word is found. This strengthened my understanding of grid traversal with constraints and path tracking. ⏱ Time Complexity: O(m × n × 4^L) (L = length of word) 🧠 Space Complexity: O(L) (recursion stack) ⚡ Key Takeaways: ✔️ Backtracking is essential for path-based problems in grids ✔️ Marking visited cells prevents cycles ✔️ Early stopping improves performance significantly 💻 Language Used: Java ☕ 📘 Concepts: DFS · Backtracking · Matrix Traversal · Recursion #CodeEveryday #DSA #LeetCode #Java #Backtracking #DFS #ProblemSolving #Algorithms #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
Day 73/75 — Weighted Word Mapping Nice mix of strings + math + mapping. Approach: • For each word → calculate total weight • Sum weights of each character using: weights[ch - 'a'] • Take modulo 26 → remainder • Map to reverse alphabet: 0 → 'z', 1 → 'y', …, 25 → 'a' Key line: char mappedChar = (char) ('z' - remainder); • Append result for each word → final string Time Complexity: O(total characters) Space Complexity: O(1) (excluding output) What’s interesting here: Instead of normal mapping (a→z), it's reversed → small twist but important Key learning: Always read mapping rules carefully — one small detail flips logic 73/75 🔥 #Day73 #DSA #Strings #Math #Java #LeetCode
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