🚀 Day 31 / 100 | Check Digitorial Permutation -Intuition: Permutation does not change the factorial sum. So instead of checking all permutations, compute the factorial sum once and check if its digits are the same as the original number’s digits. If both have same digits ,permutation exists and answer is true. -Approach: O(n) Check factorial for each digit. Traverse the number and calculate sum of factorial of digits. Store original number separately. Now compare digit frequency of original number and factorial sum If frequencies match ,return true Else, return false -Complexity: Time Complexity: O(n) n->number of digits in num. Space Complexity: O(1) #100DaysOfCode #Java #DSA #LeetCode
Checking Permutation Existence in Factorial Sum
More Relevant Posts
-
Day 42 of DSA 🚀 | Alternating Binary String Today’s problem: Minimum Changes To Make Alternating Binary String 🔹 Task: Convert a binary string into an alternating string (0101... or 1010...) using the minimum number of flips. 💡 Key Insight: Only two valid patterns exist: 010101... 101010... Count mismatches with one pattern and compute the other using: min(count, n - count) 📌 Example s = "0100" → Output = 1 ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) Small problem, but a great reminder that recognizing patterns can simplify the solution drastically. #DSA #Java #LeetCode #ProblemSolving #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Day 69/100 – LeetCode Challenge ✅ Problem: #229 Majority Element II Difficulty: Medium Language: Java Approach: Extended Boyer-Moore Voting Algorithm Time Complexity: O(n) Space Complexity: O(1) Key Insight: At most two elements can appear more than ⌊n/3⌋ times. Track two candidates and their counts simultaneously. When a new element matches neither candidate, decrement both counts. Solution Brief: Phase 1: Find two potential candidates: Maintain two candidates and their counts Update based on matches or count resets Phase 2: Verify both candidates actually appear > n/3 times Add valid candidates to result list. #LeetCode #Day69 #100DaysOfCode #Array #Java #Algorithm #CodingChallenge #ProblemSolving #MajorityElementII #MediumProblem #BoyerMoore #VotingAlgorithm #DSA
To view or add a comment, sign in
-
-
#Day_49_of_my_DSA_Journey (mission: abki bar string, array par) *Problem: Find how many times a sorted array has been rotated. A rotated sorted array is created when a sorted array is shifted from some pivot point. Example: Sorted Array → [1,2,3,4,5,6,7,8] Rotated Array → [7,8,1,2,3,4,5,6] ✅Key Idea *The number of rotations equals the index of the minimum element in the array. *Instead of scanning the entire array (O(n)), we can use Binary Search to find the pivot element efficiently. ✅Approach ->Use Binary Search to find the smallest element. ->Compare arr[mid] with arr[high]. ->If arr[mid] > arr[high] → minimum lies in the right half. ->Otherwise → minimum lies in the left half. ->Continue until low == high. *Time Complexity: O(log n) *Space Complexity: O(1) #DSA #Java #BinarySearch #CodingPractice #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 12/100 – LeetCode Challenge Problem Solved: Permutations Today’s problem was about generating all possible permutations of a given array of distinct integers. This is a classic backtracking problem where the objective is to build permutations step by step while ensuring each element is used exactly once in every arrangement. I implemented a recursive solution supported by a boolean array to track which elements were already included in the current permutation. At every recursive call, I select an unused element, add it to the current list, mark it as used, and continue exploring deeper. Once a permutation reaches the required length, it is added to the result set. Then comes the most important part — backtracking. I remove the last element and reset its state so other combinations can be explored. Time Complexity: O(n × n!) Space Complexity: O(n) excluding the output list #100DaysOfLeetCode #Java #Backtracking #Recursion #Algorithms #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 44 of DSA 🚀 Solved Minimum Number of Flips to Make the Binary String Alternating. 💡 Key Insight: An alternating binary string can only follow two patterns: 010101... 101010... To handle rotations efficiently: Double the string (s + s) Use a sliding window of size n Count mismatches with both patterns Track the minimum flips required. ⏱ Time: O(n) 💾 Space: O(n) Good practice for sliding window + pattern matching. #DSA #Java #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
Day 18/75 — Toggle Light Bulbs (State Tracking) Today’s problem: Given a list of bulbs that are toggled, determine which bulbs remain ON at the end. Approach: • Use a boolean array to track bulb states • For each bulb in the input list → toggle its state • After processing all operations → collect bulbs that remain ON Time Complexity: O(n) Space Complexity: O(1) (fixed 100 bulbs) Key Insight: Sometimes the simplest problems are about maintaining correct state efficiently rather than complex algorithms. This reinforces: • State tracking • Boolean toggling logic • Array-based simulation 18/75 — consistency over intensity. #Day18 #75DaysChallenge #DSA #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 37 of DSA – Linked List Cycle Today I solved Linked List Cycle using the Two Pointer technique (Floyd’s Algorithm). Instead of using extra space (like a HashSet), I learned how to: Use a slow pointer (moves 1 step) Use a fast pointer (moves 2 steps) Detect a cycle when both pointers meet 💡 Key Insight: If there is no cycle → fast pointer reaches null. If there is a cycle → fast eventually catches slow. Time Complexity: O(n) Space Complexity: O(1) This problem strengthened my understanding of pointer movement and loop detection in linked lists. #100DaysOfCode #DSA #Java #LinkedList #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 83/100 – LeetCode Challenge ✅ Problem: #46 Permutations Difficulty: Medium Language: Java Approach: Backtracking with Swapping Time Complexity: O(n × n!) Space Complexity: O(n) for recursion stack Key Insight: Generate all permutations by fixing each element at current position and recursively permuting remaining elements. Use swapping to avoid extra space for visited tracking. Solution Brief: Base case: When index i reaches end, add current array as permutation. Recursive case: For each position j from i to end: Swap elements at i and j Recurse on i + 1 Swap back (backtrack) to restore original order #LeetCode #Day83 #100DaysOfCode #Backtracking #Java #Algorithm #CodingChallenge #ProblemSolving #Permutations #MediumProblem #Recursion #Swapping #DSA
To view or add a comment, sign in
-
-
🚀 Day 46 / 100 | Permutations Intuition: If we have n numbers, there can be n! different permutations. The idea is to try placing every number in every possible position. Once a number is used in the current permutation, we skip it until we backtrack. Approach: O(n! * n) Use backtracking to explore all possible arrangements. Maintain a list to store the current permutation. Keep track of which elements are already used.(flag) Add an unused element, explore deeper recursively, then remove it to try another option. Repeat this process until all permutations are generated. Complexity: Time Complexity: O(n * n!) Space Complexity: O(n) #100DaysOfCode #Java #DSA #LeetCode #Backtracking
To view or add a comment, sign in
-
-
🚀 Day 29 of #75daysofLeetCode 2095 – Delete the Middle Node of a Linked List Just solved an interesting linked list problem that perfectly demonstrates the power of the two-pointer technique (slow & fast pointers). 🔍 Problem Insight: Given a linked list, delete its middle node where the middle is defined as ⌊n/2⌋ (0-based indexing). 💡 Key Idea: Instead of calculating the length, we can efficiently find the middle using: 🐢 Slow pointer (1 step) ⚡ Fast pointer (2 steps) When the fast pointer reaches the end, the slow pointer will be at the middle node! 🛠 Approach: ✔ Handle edge case (single node → return null) ✔ Traverse using slow & fast pointers ✔ Keep track of previous node ✔ Remove the middle node in one pass ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 🔥 Why this matters? This pattern is widely used in: Finding middle of linked list Detecting cycles Splitting lists Mastering this unlocks many problems! #LeetCode #DSA #LinkedList #Java #CodingInterview #ProblemSolving #TechLearning
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