🚀 Day 39/100 – Find Common Elements in Three Sorted Arrays Today I learned how to find the common numbers in three sorted arrays using an efficient approach. 🧠 Problem Statement: Given three sorted arrays, find the elements that are common in all three. 💻 Example: # Three sorted arrays arr1 = [1, 5, 10, 20, 40, 80] arr2 = [6, 7, 20, 80, 100] arr3 = [3, 4, 15, 20, 30, 70, 80, 120] # Output: [20, 80] ⚙️ Approach: ✅ Use three pointers (one for each array). ✅ Move pointers smartly to compare elements. ✅ If all three are equal → add to result. ✅ If not, move the pointer of the smallest value forward. 🧩 Code: def findCommon(arr1, arr2, arr3): i = j = k = 0 common = [] while i < len(arr1) and j < len(arr2) and k < len(arr3): if arr1[i] == arr2[j] == arr3[k]: common.append(arr1[i]) i += 1 j += 1 k += 1 elif arr1[i] < arr2[j]: i += 1 elif arr2[j] < arr3[k]: j += 1 else: k += 1 return common print(findCommon(arr1, arr2, arr3)) 🎯 Output: [20, 80] 💡 Key Takeaway: Efficient pointer logic can save both time and space complexity, especially when dealing with sorted data. #100DaysOfCode #Day38 #Python #DSA #LearningEveryday #CodingChallenge #Arrays
Finding Common Numbers in Three Sorted Arrays with Python
More Relevant Posts
-
🚀 Day 40 / 100 — #100DaysOfLeetCode 💡 (1625) Lexicographically Smallest String After Applying Operations (Medium) This was a really fun graph + BFS problem disguised as a string manipulation challenge. The trick is realizing that applying the two operations (add & rotate) repeatedly explores a finite set of states, forming an implicit graph, where each node is a string transformation. 🧩 Problem Overview You are given: A numeric string s Two integers a and b You can repeatedly: Add a (mod 10) to all digits at odd indices. Rotate the string right by b positions. Find the lexicographically smallest string possible after any number of operations. ⚙️ Approach — BFS on States Used Breadth-First Search (BFS) to explore all reachable strings: Start from the initial string s. Use a set vis to track visited states. For each string, generate: One by performing addition on odd indices. One by rotating by b. Continue until all unique transformations are explored. Track the smallest lexicographical string seen. 📈 Complexities Time Complexity: O(10 * n) Each state can appear up to 10 times due to modulo operations, and each state has n length. Space Complexity: O(10 * n) For storing visited transformations. ✅ Key Insights The problem is finite because both operations are modular and cyclic. BFS guarantees we explore all possible reachable strings in an optimal manner. Lexicographical comparison after BFS is straightforward — track the smallest string so far. ✨ Takeaway This problem beautifully demonstrates how: “Even string problems can secretly be graph traversal problems.” It’s a neat mix of modular arithmetic, rotation logic, and state-space search. #LeetCode #100DaysOfCode #BFS #GraphTraversal #StringManipulation #ProblemSolving #Python #Algorithms
To view or add a comment, sign in
-
-
Day 62 of My Data Analytics Journey Today, I explored the Pandas Series, the building block of every DataFrame! A Pandas Series is like a smart column in Excel — one-dimensional, labeled, and capable of holding any data type (numbers, text, dates, etc.). What makes it powerful is how easily you can index, slice, perform calculations, and even handle missing values — all with a single line of code! Every big dataset starts from a simple Series , and today, I understood why. #Pandas #Python #PandasSeries #DataAnalytics #LearningJourney #DataScience #100DaysOfCode #EntriElevate
To view or add a comment, sign in
-
Day 32 / 100 – Single Number III (LeetCode #260) Today’s challenge was about identifying two unique numbers in an array where every other number appears exactly twice. The twist — it had to be solved in linear time and with constant space. This problem helped me dive deeper into bitwise operations, showing how simple binary logic can reveal elegant patterns hidden inside data. 🔍 Key Learnings XOR can be used to cancel out duplicates and isolate unique values. The rightmost set bit helps separate numbers into logical groups. Bit manipulation offers a powerful way to write optimized and clean algorithms. 💭 Thought of the Day Today reminded me that clever thinking often beats complex logic. When we focus on how data behaves at the bit level, we unlock a new layer of understanding — one that turns code into pure logic. Progress isn’t about solving more; it’s about solving smarter. 🔗 Problem Link:https://lnkd.in/gNjjkBni #100DaysOfCode #Day32 #LeetCode #Python #ProblemSolving #BitManipulation #CodingChallenge #Algorithms #DataStructures #TechGrowth #LearningJourney #CodeEveryday
To view or add a comment, sign in
-
-
There’s an opinion that good visualization isn’t really about Python. But here’s a wonderful counterexample to that idea: python-graph-gallery.com by Yan Holtz — it’s truly inspiring. And it’s also an excellent, well-structured guide on how to create great visualizations in Python on your own!
"Python creates only ugly charts" ❌ I've heard this so many times! It's true that most of the matplotlib charts out there are... not polished. It's also true that the Matplotlib's API is hard to grasp. And the doc is... not easy to follow. But with: - a bit of #dataviz design theory - a few simple fundamental concepts about the syntax - and a bit of iteration... ✨ You can create literally anything! I've spent years of my life gathering examples in the python-graph-gallery.com I've also created Matplotlib-journey.com with Joseph Barbier to provide the best learning experience. Let's push the limits of Matplotlib and get rid of its bad reputation! ---- Original chart by Gilbert Fontana 🙏
To view or add a comment, sign in
-
-
I just found the ultimate NumPy cheat code. Seriously, --- I used to waste 20 minutes a day Googling array slicing or broadcast rules. My code was slow. My flow was broken. That inefficiency cost me focus and valuable time on projects. --- So, I compressed the entire core of NumPy onto two pages. It's not a textbook; it's a 2-page, high-density reference. Every critical method. Every efficient shortcut. Every syntax trick. This handwritten cheat sheet is the $100 value—it's the sheer speed it gives you. Zero fluff. 100% immediate utility. Just pure, battle-tested NumPy power. --- Stop searching the docs. Start executing faster. Your Data Science workflow is about to get a massive upgrade. ⚡️ --- I attached the cheat sheet here and if you find it out useful then don't forget to follow and give a like. --- #DataScience #Python #NumPy #CheatSheet #MachineLearning
To view or add a comment, sign in
-
Stop filtering your Pandas DataFrames like this — df[df['col'] == 'value']. It feels intuitive, but you're forcing Pandas to scan the entire column. There’s a faster, smarter way. In Part 2 of my Pandas Series on Dev.to, I break down Indexing — one of the most underrated performance boosters in Pandas. Most people think the index is just row numbers, but it’s actually a high-speed, label-based lookup system (like a dictionary key). Here’s what I cover: • How set_index() and reset_index() can reshape your DataFrame for speed • Why MultiIndex feels like a cheat code for hierarchical data access • Pro tip: Always sort your index (df.sort_index()) if you want fast range-based slicing (like dates) Mastering indexing = faster queries, cleaner code, and way better interview answers. Link to full article in the first comment 👇 #Python #Pandas #DataEngineering #DataScience #DataAnalysis #InterviewPrep
To view or add a comment, sign in
-
-
🧩 Day 29 — 3Sum Closest (LeetCode 16) 📝 Problem Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. 🔁 Approach -Sort the array to use the two-pointer technique effectively. -Iterate through each element nums[i] (except the last two) and treat it as the first element of the triplet. -For each i, set two pointers: -left = i + 1 -right = len(nums) - 1 -Compute the sum of the three numbers: -total = nums[i] + nums[left] + nums[right] -If total == target, return total immediately (perfect match). -Otherwise, compare the absolute difference between total and target to update the closestSum. -Adjust pointers: -If total < target, move left pointer right to increase sum. -If total > target, move right pointer left to decrease sum. -Continue until all triplets are checked. -Return the final closestSum. 📊 Complexity -Time Complexity: O(n²) -Space Complexity: O(1) 🔑 Concepts Practiced -Sorting and two-pointer pattern -Optimization using sorted array and pointer movement -Handling duplicates efficiently -Absolute difference comparison for closest value #Leetcode #python #DSA #Sorting #problemSolving
To view or add a comment, sign in
-
-
🚀 DSA Progress – Day 106 ✅ Problem #557: Reverse Words in a String III 🧠 Difficulty: Easy | Topics: String, Two Pointers, In-place Reversal 🔍 Approach: Implemented a two-pointer traversal method to reverse each word in the sentence individually without changing the word order. Step 1 (Conversion): Since Python strings are immutable, first convert the input string into a list to allow in-place modifications. Step 2 (Traversal): Use pointer i to find the start of a word and pointer j to find its end by moving forward until a space or end of the string is found. Step 3 (Reversal): Once the word boundaries (i to j-1) are identified, reverse that portion in place using slicing (s[i:j] = reversed(s[i:j])). Step 4 (Iteration): Continue scanning until the entire sentence is processed. Finally, join the list back into a string and return it. This method ensures that each word’s characters are reversed, while their overall positions remain unchanged in the sentence. 🕒 Time Complexity: O(n) — Each character is visited once. 💾 Space Complexity: O(n) — For the list representation of the string. 📁 File: https://lnkd.in/gdefC89D 📚 Repo: https://lnkd.in/g8Cn-EwH 💡 Learned: This problem reinforced how two-pointer logic and in-place modification can be used to efficiently handle string problems. It also highlighted the importance of mutable vs immutable data types in Python. Breaking the sentence word by word made the logic clean and modular — a good reminder that even simple problems can sharpen control-flow and boundary-handling skills. ✅ Day 106 complete — flipped every word inside out but kept the sentence standing tall! ✨🪞📜 #LeetCode #DSA #Python #Strings #TwoPointers #InPlace #CodingJourney #InterviewPrep #DailyPractice #GitHubJourney
To view or add a comment, sign in
-
💯 Day 42 / 100 – 100 Days of #LeetCode Challenge 🔁 Problem: 744. Find Smallest Letter Greater Than Target Goal: Given a sorted list of letters and a target letter, find the smallest letter that is greater than the target. The list wraps around, meaning if no letter is greater, return the first letter in the list. Approach: ✅ Sort the list to ensure it’s in order (though usually given sorted). ✅ Iterate through the letters: If a letter is greater than the target, return it immediately. ✅ If no such letter exists, return the first letter (wrap-around case). Complexity: ⏱ Time: O(n) – Linear scan through the letters. 🗂 Space: O(1) – Constant extra space. 💡 Key Takeaways: Simple iteration logic can solve problems efficiently without extra data structures. Watch out for wrap-around conditions in sorted arrays. This problem is a good intro to binary search optimization ideas! #100DaysOfLeetCode #Day42 #Python #DSA #Stack #ProblemSolving #CodingChallenge #LeetCode #LearningEveryday
To view or add a comment, sign in
-
-
🚀 DSA Challenge – Day 83 Problem: Minimum Possible Length of Original String from Concatenated Anagrams 🔡✨ This was an elegant string manipulation and frequency-matching problem — a beautiful blend of observation and brute-force validation. 🧠 Problem Summary: You are given a string s, known to be a concatenation of anagrams of some original string t. The task is to determine the minimum possible length of t. ✅ Each substring of length len(t) should contain exactly the same frequency of characters. ✅ The string s can thus be divided into equal-length chunks, all being anagrams of t. ✅ The goal is to find the smallest such length that satisfies this property. ⚙️ My Approach: 1️⃣ Iterate through all divisors i of n = len(s) — potential lengths of t. 2️⃣ For each possible i, check if the string can be divided into equal parts where each part has identical character frequencies. 3️⃣ Use hash maps to store frequency counts and compare each block. 4️⃣ Return the smallest i that satisfies the condition. 📈 Complexity: Time: O(n²) → Checking frequency for each valid divisor. Space: O(k) → For storing character counts per block. ✨ Key Takeaway: When tackling anagram-based problems, frequency comparison is your strongest ally. Instead of guessing patterns, rely on structure and repetition to reveal the hidden base string. 🔍 🔖 #DSA #100DaysOfCode #LeetCode #ProblemSolving #StringManipulation #Anagram #Python #CodingChallenge #InterviewPrep #EfficientCode #HashMap #DataStructures #TechCommunity #CodeEveryday #LearningByBuilding
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