Title: From "What" to "How": Implementing My First Algorithm Hey LinkedIn fam! 👋 Today, my journey was all about understanding what an array is: a contiguous block of memory for storing elements of the same type. I took the logical next step: learning how to do something useful with it. My focus was on my very first searching algorithm: Linear Search. The task is simple, just like finding a specific dish on a menu: "Find the index of an element in a given array." The logic is exactly what you'd do in real life: Start at the beginning (index 0). Check each element, one by one. If you find what you're looking for (the key), you immediately stop and return its index. But the real "aha!" coding moment for me was handling the "Not Found" case. You can't just return 0, because 0 is a valid index! The elegant solution is to return a sentinel value—a number that's outside the possible range of indices. In this case: -1. Then, in the main code, you just check: if (index == -1) { ... print "Not Found" } It's so cool to see the theory (the diagram) and the practical, clean code come together. It feels great to connect these fundamental building blocks. One step at a time! What was the first algorithm you remember learning after arrays? #Java #Algorithms #LinearSearch #DataStructures #CodingJourney #LearnInPublic #SoftwareDevelopment #ProgrammingFundamentals
From Arrays to Linear Search: My First Algorithm
More Relevant Posts
-
💻 Mastering Linked Lists in Just 8 Hours — My DSA Milestone Last week, I decided to challenge myself — to master Singly Linked List (SLL) in one go. Many people find it tricky because of pointers, but once you visualize the flow, it actually becomes surprisingly simple. In just 8 hours, I built, broke, and rebuilt linked lists from scratch — 👉 created nodes, 👉 inserted and deleted dynamically, 👉 reversed the list, 👉 detected loops, and 👉 even played with the slow-fast pointer technique to find the middle node efficiently. The moment you understand that: > “Fast moves 2 steps, slow moves 1 step, and when fast stops — slow is your middle.” everything clicks ✨ Complexity simplified: Traversal: O(n) Reversal: O(n) Space: O(1) All in pure pointer logic — no extra data structures, no shortcuts. Now, Singly Linked List ✅ Next target: Trees & Recursion 🌳 Because DSA is not about memorizing algorithms — it’s about understanding flow. --- 💬 If you’re starting your DSA journey — begin with Linked Lists. It teaches you how data moves, how memory connects, and how logic flows. #DSA #Python #CodingJourney #LinkedList #SoftwareEngineering #100DaysOfCode
To view or add a comment, sign in
-
🧩 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐖𝐞𝐞𝐤𝐥𝐲 𝐂𝐨𝐧𝐭𝐞𝐬𝐭 𝟒𝟕𝟒 🚀 Just wrapped up this week’s 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗪𝗲𝗲𝗸𝗹𝘆 𝗖𝗼𝗻𝘁𝗲𝘀𝘁 𝟰𝟳𝟰 — managed to 𝘀𝗼𝗹𝘃𝗲 𝟮 𝗼𝘂𝘁 𝗼𝗳 𝟰 𝗾𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 🎯 Each problem brought a new challenge in logic building and optimization — and it was a great brain workout 🔹 𝗤𝟭. 𝗙𝗶𝗻𝗱 𝗠𝗶𝘀𝘀𝗶𝗻𝗴 𝗘𝗹𝗲𝗺𝗲𝗻𝘁𝘀 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: • Created a hash map to track all numbers present in the array. • Found the min and max elements to define the expected range. • Identified numbers missing from that range efficiently. ⏱️ 𝗧𝗶𝗺𝗲 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: O(n + (max − min)) 💾 𝗦𝗽𝗮𝗰𝗲 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: O(n) — for the hash map ➡️ Key takeaway: Simple hashing + range logic can replace sorting-based approaches. 🔹 𝗤𝟮. 𝗠𝗮𝘅𝗶𝗺𝘂𝗺 𝗣𝗿𝗼𝗱𝘂𝗰𝘁 𝗼𝗳 𝗧𝗵𝗿𝗲𝗲 𝗘𝗹𝗲𝗺𝗲𝗻𝘁𝘀 𝗔𝗳𝘁𝗲𝗿 𝗢𝗻𝗲 𝗥𝗲𝗽𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: • Observed that the product’s magnitude depends on the largest absolute values. • Since one number can be replaced in [-10⁵, 10⁵], tested both extremes (10⁵ and −10⁵). • Chose the maximum product possible between the two cases. ⏱️ 𝗧𝗶𝗺𝗲 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: O(n) 💾 𝗦𝗽𝗮𝗰𝗲 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: O(1) — constant space ➡️ Key takeaway: Sometimes, focusing on mathematical relationships beats complex iteration logic. 💭 𝗥𝗲𝗳𝗹𝗲𝗰𝘁𝗶𝗼𝗻𝘀 • Solved 2 problems confidently ✅ • Improved speed in analyzing mathematical patterns and handling edge cases • Next goal → solve 3/4 questions and focus more on binary search & greedy optimization #LeetCode #WeeklyContest474 #ProblemSolving #Python #CompetitiveProgramming #DSA #CodingJourney #ContinuousLearning #Algorithms
To view or add a comment, sign in
-
-
🎉 𝗣𝘆𝘁𝗵𝗼𝗻'𝘀 𝗦𝘁𝗶𝗹𝗹 𝗖𝗿𝘂𝘀𝗵𝗶𝗻𝗴 𝗜𝘁—𝗕𝘂𝘁 𝗜𝘀 𝗖'𝘀 𝗖𝗼𝗺𝗲𝗯𝗮𝗰𝗸 𝗬𝗼𝘂𝗿 𝗪𝗮𝗸𝗲-𝗨𝗽 𝗖𝗮𝗹𝗹? 🚀 Fresh off the October 2025 TIOBE Software Index: Python holds the crown at 24.45% popularity, dominating data science, web dev, and AI like the boss it is (down just a hair from last month, but up 2.55% YoY). But here's the plot twist—C surges to #2 at 9.29%, nipping at C++'s heels thanks to the shiny C23 standard's focus on speed and simplicity. SQL sneaks back into the top 10, while Perl waves goodbye. 💥 𝗣𝗿𝗼 𝗧𝗶𝗽 𝗳𝗼𝗿 𝗗𝗲𝘃𝘀: If you're all-in on Python (guilty! 🐍), branch out to C for those performance-hungry projects—it's the ultimate glow-up for low-level optimization without the full rewrite headache. Or dive into Go 1.24's new generics and weak pointers for cleaner concurrency. The dev world's evolving faster than ever; staying versatile = staying ahead. #ProgrammingEverything #TIOBEIndex #Python #CProgramming #DevTips #CodeLife 𝙋.𝙎. 𝙌𝙪𝙖𝙣𝙩𝙪𝙢 𝙘𝙝𝙞𝙥𝙨 just hit mass-production accuracy—next up, error-free qubits in your IDE? Mind blown. 🤯
To view or add a comment, sign in
-
-
🔹 Day 5 of 30 – LeetCode Challenge: Longest Increasing Subsequence 📈 Today’s problem was all about finding patterns and optimizing logic! I solved the Longest Increasing Subsequence (LIS) problem — a fundamental concept in Dynamic Programming and Binary Search optimization. 🧩 Problem: Given an array of integers, find the length of the longest subsequence where each element is strictly greater than the previous one. Example: Input: nums = [10,9,2,5,3,7,101,18] Output: 4 Explanation: [2,3,7,101] is the longest increasing subsequence. 💡 Approach: There are two ways to solve this: 1. Dynamic Programming (O(n²)) a. For each element, look back at all previous elements. b. Update dp[i] as the length of the LIS ending at that index. 2.Binary Search Optimization (O(n log n)) a. Maintain a list sub representing potential increasing subsequences. b. Use bisect_left to replace elements efficiently. ⚙️ Complexity: Time: O(n log n) Space: O(n) 🏆 Result: ✅ All test cases passed ⚡ Optimized solution using Binary Search 💪 Strengthened understanding of Dynamic Programming and Binary Search combination 💬 Learning: This problem helped me understand how to convert a quadratic DP approach into a logarithmic one by thinking about sorted subsequences and binary search placements — a powerful pattern for future optimization problems. #Day5 #LeetCode #DynamicProgramming #BinarySearch #Python #Algorithms #DataStructures #30DaysOfCode #MTech #CodingChallenge #LIS
To view or add a comment, sign in
-
-
🌳 DSA Challenge – Day 99 Problem: Balanced Binary Tree ⚖️🌲 This classic tree problem tests your understanding of recursion, depth-first search, and how to efficiently check balance conditions in binary trees. 🧠 Problem Summary: A height-balanced binary tree is one in which the height of the two subtrees of every node never differs by more than 1. Your task: Given the root of a binary tree, determine whether it is height-balanced. ⚙️ My Approach: 1️⃣ Use a recursive DFS helper util() to traverse the tree. 2️⃣ For each node, compute: Whether its left and right subtrees are balanced. The maximum depth of its left and right subtrees. 3️⃣ If at any point the height difference exceeds 1, return False. 4️⃣ The function returns both a boolean (isBalanced) and an integer (height). 💡 Optimization Insight: Instead of computing the height in a separate pass (which would make it O(n²)), this approach combines balance checking and height calculation in one DFS traversal, resulting in O(n) time complexity. 📈 Complexity Analysis: Time Complexity: O(n) — Each node is visited once. Space Complexity: O(h) — Recursion stack, where h is the height of the tree. ✨ Key Takeaway: Efficient recursion patterns often come from returning multiple values — combining partial results avoids redundant computation and keeps solutions elegant. 🔖 #DSA #100DaysOfCode #BinaryTree #LeetCode #ProblemSolving #CodingChallenge #Python #Algorithms #Recursion #TreeTraversal #TechCommunity #LearningEveryday
To view or add a comment, sign in
-
-
💡 Day 43 / 100 – Search in Rotated Sorted Array (LeetCode #33) Today’s problem was a twist on the classic binary search — quite literally! The challenge was to find a target element in a rotated sorted array. At first glance, the array looks unsorted, but there’s actually a pattern. By identifying which part of the array is properly sorted at every step, we can still apply binary search logic efficiently — achieving O(log n) time complexity. This problem beautifully blends pattern recognition with logical precision. 🔍 Key Learnings Even when data looks “unsorted,” patterns often exist beneath. Modified binary search can adapt to many problem variations. Understanding midpoint relationships helps in avoiding brute force. 💭 Thought of the Day Adaptability is key — in coding and in life. Just like binary search adjusts to a rotated array, we can adjust to challenges by recognizing the underlying order in the chaos. Clear logic turns confusion into clarity. 🔗 Problem Link: https://lnkd.in/gS8FcbeE #100DaysOfCode #Day43 #LeetCode #Python #BinarySearch #ProblemSolving #Algorithms #CodingChallenge #DataStructures #CodingJourney #PythonProgramming #LogicBuilding #KeepLearning #TechGrowth #Motivation
To view or add a comment, sign in
-
-
🔥 Day 11 of 30 – LeetCode Challenge: Search Insert Position 🧠 Today’s problem focuses on Binary Search with a twist—if the target isn’t found in the array, we must determine the correct index where it should be inserted to maintain sorted order. 🧩 Problem Summary Given a sorted array of distinct integers and a target, return: ✅ Index of the target if found 📍 If not found, index where it should be inserted Example 1: Input: nums = [1,3,5,6], target = 5 Output: 2 Example 2: Input: nums = [1,3,5,6], target = 2 Output: 1 Example 3: Input: nums = [1,3,5,6], target = 7 Output: 4 💡 Approach – Binary Search We use binary search to narrow down the potential index. If the target isn’t found, the left pointer will indicate the correct insertion position. ⚙️ Complexity Analysis Time O(log n) Space O(1) 🏆 Key Learnings ✅ Reinforced understanding of binary search 📍 Learned how pointer positions help determine insertion index ⚡ More confidence with boundary-based problems ✨ Real-World Applications 🔹 Auto-suggestion systems (insert new search term) 🔹 Maintaining ordered data lists 🔹 Ranking & leaderboard systems #Day11 #LeetCode #BinarySearch #Python #WomenWhoCode #DSA #ProblemSolving #CodingJourney #MTech #KeepLearning
To view or add a comment, sign in
-
-
A script executes. An application decides. #ZeroToFullStackAI Day 6/135: The Principle of Control Flow. For the past five days, our code has been a simple, top-to-bottom script. It executes one line after another, no matter what. The `ValueError` from our Day 5 challenge proved this is not enough. We need a way to handle different conditions. Today, we build the "brain" of our application. This is "Control Flow". It’s the mechanism that allows our code to analyze a situation and make a decision. Our tool for this is the `if/elif/else` structure: 1. 'if' : The primary gate. It asks a `True/False` question. 2. 'elif' : The secondary gate. It *only* asks its question if the `if` was `False`. 3. 'else': The "catch-all." It runs *only* if all preceding conditions were `False`. This is the first and most fundamental tool for writing non-linear, intelligent logic. We can now create different paths for our program to follow. We've taught our code to make logical decisions. But we still haven't built the "safety net" for when it receives bad data (like the `ValueError`). That is the final piece of our foundation. Tomorrow, we build the safety net: **Error Handling**. #Python #DataScience #SoftwareEngineering #AI #Developer #Logic
To view or add a comment, sign in
-
-
⚡ Day 85 of #100DaysOfDSA – Reverse Bits 💡 📌 Problem. no 190: Given a 32-bit unsigned integer, reverse its bits and return the result. Solved using bit manipulation by shifting and combining bits efficiently through iterative processing. ⚡ Runtime: 15 ms – Beats 74.65% of submissions 💾 Memory: 12.49 MB – Beats 49.36% of solutions 💻 Language Used: Python ✅ Status: Accepted – All 600 test cases passed successfully! This problem strengthened my understanding of low-level bit operations, binary manipulation, and efficient use of shifting operators. It’s a great reminder that small operations can have big effects on data representation. 🔑 Key Learnings: ✔️ Learned how to manipulate bits effectively using bitwise operators ✔️ Understood the significance of shifting and masking in binary form ✔️ Improved my grasp of algorithmic efficiency at the bit level 🎯 Day 85 — A smart bitwise challenge that sharpened my binary logic and precision-based problem-solving! ⚙️💻🔥 #100DaysOfCode #100DaysOfDSA #LeetCode #PythonProgramming #DataStructures #AlgorithmPractice #CodeNewbie #DailyCoding #ProblemSolving #TechJourney #WomenWhoCode #CodeLife #CodingChallenge #DSAChallenge #DeveloperLife #PythonDeveloper #LearnToCode #CodingCommunity #CodeEveryday #SoftwareEngineering #KathirCollegeOfEngineering #KathirCollege #BTechLife #AIDS #FutureEngineer #CodingMotivation #ProgrammingSkills
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