Day 97/100 – #100DaysOfCode 🚀 | #Java #Strings #Logic ✅ Problem Solved: Longest Uncommon Subsequence I (LeetCode) 🧩 Problem Summary: Given two strings, find the length of the longest uncommon subsequence — a subsequence that appears in one string but not in the other. 💡 Approach Used: ✔ Observational / logical approach ✔ If both strings are equal, no uncommon subsequence exists ✔ If they are different, the longer string itself is the answer Why it works: A string is always a subsequence of itself If strings differ, the longer one cannot be a subsequence of the shorter ⚙ Time Complexity: O(1) 📦 Space Complexity: O(1) ✨ Takeaway: Some problems look like DP but are solved with pure logic. Always check for simple observations before overengineering. #Java #LeetCode #Strings #Logic #100DaysOfCode #CodingChallenge
Java LeetCode: Longest Uncommon Subsequence Solution
More Relevant Posts
-
Day 92/100 – #100DaysOfCode 🚀 | #Java #DynamicProgramming #Strings ✅ Problem Solved: Longest Palindromic Subsequence (LeetCode) 🧩 Problem Summary: Given a string, find the length of the longest subsequence that is also a palindrome. (A subsequence does not need to be contiguous.) 💡 Approach Used: ✔ Used Dynamic Programming (2D DP) ✔ Define dp[i][j] as the length of the longest palindromic subsequence in substring s[i…j] Logic: If s[i] == s[j] → dp[i][j] = 2 + dp[i+1][j-1] Else → dp[i][j] = max(dp[i+1][j], dp[i][j-1]) Fill the table bottom-up by increasing substring length ⚙ Time Complexity: O(N²) 📦 Space Complexity: O(N²) ✨ Takeaway: Problems involving subsequences often hint toward DP. Breaking the string into overlapping subproblems makes complex patterns manageable. #Java #LeetCode #DynamicProgramming #Strings #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
Day 29/100 ✅ LeetCode 138: Copy List with Random Pointer Solved this problem by creating a deep copy of a linked list where each node contains an additional random pointer. The approach ensures that both next and random pointers are copied correctly without modifying the original list. Key steps involved: Create copied nodes Link copied nodes with original nodes Assign random pointers efficiently Separate the original and cloned lists This problem helped me strengthen my understanding of linked list manipulation and pointer mapping. Solution:-https://lnkd.in/gD9TWWsg #LeetCode #LeetCode138 #CopyListWithRandomPointer #LinkedList #DSA #Java #ProblemSolving #CodingPractice #DeepCopy #DataStructures #Day29
To view or add a comment, sign in
-
-
#200DaysOfCode – Day 108 Combination Sum III Problem:- Combination Sum III Task:- Find all valid combinations of k numbers that sum up to n, using only numbers from 1 to 9, where: Each number is used at most once No duplicate combinations are allowed Example: Input: k = 3, n = 7 Output: [[1, 2, 4]] My Approach:- Used Backtracking (DFS) to explore all possible combinations. Started from a given number to avoid duplicates. Stopped recursion when: The combination size exceeded k The sum became negative Added the combination to the result only when: Exactly k numbers were chosen The sum became 0 Time Complexity:- Exponential (bounded due to range 1–9) Space Complexity:- O(k) (recursive stack + temporary list) Backtracking may look complex at first, but with clear base conditions and pruning, it becomes a powerful and elegant tool for solving combination problems efficiently. #takeUforward #200DaysOfCode #Java #ProblemSolving #LeetCode #Backtracking #Recursion #DSA #CodingJourney #CodeNewbie
To view or add a comment, sign in
-
-
Time complexity , I know this is the important topic for the analysis of algorithm. Note : Loops inside loop (nested loop) not always caring O(N^2) complexity. Its totally says that complexity depends on how inner loop behaves with respect to outer loop and input size. Hope its Helpful. #TimeComplexity #Java #LearningJourney #DSA #DataStructure #ProblemSolving
To view or add a comment, sign in
-
Converting a number from any base to decimal doesn’t need powers. Just remember: result = result * base + digit This single formula works for binary, octal, decimal, hexadecimal — everything. Time: O(n) Space: O(1) Master the logic, not the shortcuts. Save this for revision 📌 #DSA #Java #NumberSystems #ProblemSolving #CodingInterview
To view or add a comment, sign in
-
-
Day 91/100 – #100DaysOfCode 🚀 | #Java #BinaryTree #BFS ✅ Problem Solved: Find Largest Value in Each Tree Row (LeetCode) 🧩 Problem Summary: Given the root of a binary tree, return an array containing the largest value in each level (row) of the tree. 💡 Approach Used: ✔ Used Breadth-First Search (Level Order Traversal) ✔ Process the tree level by level using a queue For each level: Initialize maxValue to the smallest possible integer Traverse all nodes at that level Update maxValue Add it to the result list ⚙ Time Complexity: O(N) 📦 Space Complexity: O(W) (where W = maximum width of the tree) ✨ Takeaway: Level-order traversal is ideal when problems require row-wise processing in trees — clean, intuitive, and efficient. #Java #LeetCode #BinaryTree #BFS #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
Day 99/100 – #100DaysOfCode 🚀 | #Java #PrefixSum #HashMap ✅ Problem Solved: Continuous Subarray Sum (LeetCode 523) 🧩 Problem Summary: Given an integer array and an integer k, determine if the array has a continuous subarray of size at least 2 whose sum is a multiple of k. 💡 Approach Used: ✔ Used Prefix Sum + HashMap ✔ Key observation: If two prefix sums have the same remainder when divided by k, the subarray between them has a sum divisible by k. Steps: Maintain running sum Store (prefixSum % k) → earliest index in a HashMap If the same remainder appears again and the subarray length ≥ 2 → return true Initialize map with (0 → -1) to handle edge cases ⚙ Time Complexity: O(N) 📦 Space Complexity: O(K) (where K = number of unique remainders) ✨ Takeaway: Modular arithmetic paired with prefix sums is a powerful pattern for detecting divisible subarrays in linear time. #Java #LeetCode #PrefixSum #HashMap #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
Java Stream API: Pipeline Power! → Intermediate (lazy: map, filter, sorted…) → Terminal (eager: collect, reduce…) List<Integer> evensSquared = Arrays.asList(1,2,3,4,5).stream() .filter(n -> n%2==0) .map(n -> n*n) .collect(Collectors.toList()); // [4, 16] Transform collections declaratively. #Java #Collections #Streams #Java8 #Map #FunctionalProgramming #CleanCode #List #Arrays #Coding #StreamAPI #Arrays #Intermediate #TerminalOperations #Collectors
To view or add a comment, sign in
-
-
🚀 LeetCode 1662 – Check If Two String Arrays are Equivalent Combine two string arrays using String.join("", array) and compare with .equals() — solves the problem in just one line! 💡 Returns false if any array is empty. #LeetCode #Java #DSA #ProblemSolving #CodingJourney #LearnToCode #SoftwareEngineer #DailyCoding
To view or add a comment, sign in
-
-
Day 95/100 – #100DaysOfCode 🚀 | #Java #HashMap #Randomization ✅ Problem Solved: Random Flip Matrix (LeetCode 519) 🧩 Problem Summary: You are given a binary matrix initialized with all 0s. Each call to flip() should randomly return the position of a 0 and change it to 1. No position should be flipped more than once until reset() is called. 💡 Approach Used: ✔ Used HashMap + Randomization to simulate shuffling ✔ Treat the matrix as a flattened 1D array Steps: Map each index to its actual value using a HashMap Randomly pick an index from the remaining unflipped range Swap it with the last available index Decrease the available range On reset(), clear the map and restore the range ⚙ Time Complexity: O(1) per flip() 📦 Space Complexity: O(K) (where K = number of flipped cells) ✨ Takeaway: This problem is a great example of achieving uniform randomness without storing the entire matrix — smart indexing beats brute force. #Java #LeetCode #HashMap #Randomization #100DaysOfCode #CodingChallenge
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