#100DaysOfCode – Day 69 String Manipulation Task: Find the longest common prefix among an array of strings. Example: Input: ["flower", "flow", "flight"] → Output: "fl" My Approach: Took the first string as the initial prefix. Iterated through each subsequent string. Trimmed the prefix until it matched the start of each word. Time Complexity: O(N × M) (where N = number of strings, M = average string length) String problems are all about observation understanding patterns, boundaries, and when to stop iterating. A few lines of logic can make a big difference in performance and clarity! #takeUforward #100DaysOfCode #Java #LeetCode #ProblemSolving #StringManipulation #CodingJourney #GeeksForGeeks #CodeNewbie #DataStructures #Algorithms
#100DaysOfCode - Day 69: Finding the longest common prefix in an array of strings
More Relevant Posts
-
#100DaysOfCode – Day 74 Count and Say Problem: Given an integer n, return the n-th term of the “Count and Say” sequence a fascinating pattern where each term describes the previous one. Example: Input: n = 4 Output: "1211" My Approach: Used recursion to generate the previous term. Applied run-length encoding logic counted consecutive digits and built the next term using a StringBuilder. Optimized for clean, readable iteration with O(N²) complexity (due to string building). Understanding recursive string construction deepens how we visualize “generation-based” sequences it’s not just about coding, it’s about seeing patterns grow. #100DaysOfCode #Java #LeetCode #ProblemSolving #Recursion #StringManipulation #CodingJourney #TechWithPurpose #takeUforward
To view or add a comment, sign in
-
-
Anagrams and Minimum Steps: A Frequency Counting Solution! Just solved the "Minimum Steps to Make Two Strings Anagram" problem! When strings 's' and 't' are the same length, the key is efficiently determining how many characters in 't' need to be replaced to match the required character distribution of 's'. My approach is simple and highly efficient: 1. Count Requirements: Use a HashMap to store the exact frequency of every character in string 's'. 2. Match & Mismatch: Iterate through string 't'. If a character is needed (count > 0), we use it up. If it's not needed, it represents one step (one character in 't' that must be changed). This lands us in optimal O(N) time complexity and O(1) space complexity (since the alphabet size is constant). Frequency counting is a powerhouse technique for any string problem! #Algorithms #DataStructures #StringManipulation #LeetCode #CodingChallenge #Java #100daysofcode
To view or add a comment, sign in
-
-
💡 Mastering Array Rotation — LeetCode #189 Today, I solved an interesting array manipulation problem: Rotate Array — a classic coding interview question that tests both problem-solving and optimization skills. 🧩 Problem Statement Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. ⚙️ Intuitive Approach Rotating an array means shifting elements circularly to the right. A naïve approach would use extra space, but the optimal solution performs it in-place using array reversal. Step-by-Step Logic -> Reverse the entire array -> Reverse the first k elements -> Reverse the remaining n - k elements ⏱️ Complexity Analysis Time Complexity: O(n) Space Complexity: O(1) In-place Rotation: ✅ #LeetCode #Java #DSA #CodingChallenge #ProblemSolving #Arrays #InPlaceAlgorithm #DataStructures #LearningEveryday
To view or add a comment, sign in
-
-
🌳 Day 64 of #100DaysOfLeetCode 🌳 🧩 Problem: 105. Construct Binary Tree from Preorder and Inorder Traversal 💡 Approach: We can rebuild the tree by understanding how preorder and inorder traversals work: Preorder: Root → Left → Right Inorder: Left → Root → Right The first element of preorder gives the root. Then, we find that root in the inorder list — elements left of it form the left subtree, and elements right of it form the right subtree. We recursively repeat this process for left and right parts. To optimize lookup time, we use a HashMap to store inorder indices for O(1) access. ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(n) ✨ Key Takeaways: Understanding traversal orders is crucial for tree reconstruction. Use maps to avoid repeated searches in inorder traversal. Recursion mirrors the natural tree structure perfectly. #LeetCode #Java #Coding #BinaryTree #DataStructures #100DaysOfCode #ProblemSolving #ProgrammingJourney
To view or add a comment, sign in
-
-
💻 Day 19 of My LeetCode Journey 🧩 Problem: 205. Isomorphic String ✨ My Approach: To check if two strings are isomorphic, I used two HashMaps — one to store character mappings from string s to string t, and another to track whether a character in t has already been mapped. 🔹 If a mapping already exists, I verify that it’s consistent. 🔹 If not, I ensure no two characters from s map to the same character in t. 🔹 If all mappings hold correctly, the strings are isomorphic. ⚙️ Time Complexity: O(n) 💾 Space Complexity: O(n) ✅ Learning: This problem helped me understand the concept of one-to-one mapping between characters and how to use HashMap effectively to track relationships between elements. #Day19 #LeetCode #Java #CodingJourney #ProblemSolving #IsomorphicStrings #HashMap #LearningEveryday #DataStructures
To view or add a comment, sign in
-
-
🚀 115 days of #200DaysOfCode Problem: 24. Swap Nodes in Pairs Problem Statement: Given the head of a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes, only nodes themselves may be changed. Approach: Used a dummy node and iteratively swapped each adjacent node pair via pointer manipulation, which enabled in-place node swaps without extra space. Logic: Leveraged pointer rewiring to achieve the swaps efficiently with O(1) extra space and O(n) time complexity, cleanly iterating through the list to handle both even and odd-length cases. 👉 Question link 🔗: https://lnkd.in/g6cwvMgz #LeetCode #Java #LinkedList #Pointers #DSA #Coding #Algorithms #InterviewPrep #200DaysOfCode
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 81 Linked List Cycle Problem Given the head of a linked list, determine whether the list contains a cycle meaning a node’s next pointer refers back to a previous node. My Approach Used Floyd’s Cycle Detection Algorithm (Tortoise & Hare Method): Initialized two pointers slow and fast. Moved slow one step and fast two steps in each iteration. If they ever meet → cycle detected. If fast or fast.next becomes null → no cycle exists. Complexity Time: O(n) Space: O(1) Even in problems involving dynamic structures like linked lists, a simple pointer-based approach can lead to an elegant and optimal solution. #100DaysOfCode #LeetCode #Java #ProblemSolving #DataStructures #LinkedList #TortoiseAndHare #takeUforward #CodeNewbie #CodingJourney
To view or add a comment, sign in
-
-
🚩 Problem: 349. Intersection of Two Arrays 🔥 Day 42 of #100DaysOfLeetCode 🔍 Problem Summary: Given two integer arrays nums1 and nums2, return an array of unique elements that appear in both arrays. The result must not contain duplicates. The order of elements in the output does not matter. ✅ Approach: Using HashSet Store elements of nums1 in a HashSet. Loop through nums2, and if an element exists in HashSet, add to result set. Convert the set into an array. 📊 Complexity: Time Complexity: O(m + n) Space Complexity: O(m + n) 🎯 Key Takeaway: This problem reinforces the concept of using HashSet to remove duplicates and perform efficient membership checks, which is fundamental for solving array and hashing problems optimally. Link:[https://lnkd.in/gz9Y99Ak] #100DaysOfLeetCode #Day42 #Problem349 #IntersectionOfArrays #HashSet #Java #DSA #Algorithms #CodingChallenge #ProblemSolving #LeetCode #InterviewPreparation #DataStructures #TechCareers #ArjunInfoSolution #CodingCommunity #CodeNewbie #ZeroToHero #SoftwareEngineering
To view or add a comment, sign in
-
-
💻 Day 34 — LeetCode 912: Sort an Array (Merge Sort Implementation) Today, I learned and implemented Merge Sort, a classic Divide and Conquer algorithm that efficiently sorts arrays with a time complexity of O(n log n). I applied it to LeetCode 912 (Sort an Array) — where the task is to sort an integer array without using built-in sorting methods. This problem helped me understand: How recursion splits the array into halves How merging combines sorted halves Why Merge Sort guarantees stable and consistent performance 🧠 Key takeaway: Merge Sort ensures O(n log n) in all cases (best, average, and worst), making it one of the most reliable sorting algorithms. #LeetCode #Day34 #DSA #SortingAlgorithms #MergeSort #CodingJourney #Java #ProblemSolving
To view or add a comment, sign in
-
-
💻 Solving LeetCode: Kth Smallest Element in a BST Implemented an inorder traversal approach to efficiently find the kth smallest element in a Binary Search Tree. ✅ Key Points: Inorder traversal of BST gives elements in sorted order. Keep a count while traversing; when count == k, we’ve found our answer. Time Complexity: O(N) in worst case Space Complexity: O(H) due to recursion (H = height of tree) This is a classic example of leveraging BST properties for optimized search! #Coding #Java #DataStructures #BST #LeetCode #ProblemSolving #InorderTraversal
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