Day 35 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to count the number of words in a sentence without using the split() function. The goal was to understand how word detection works internally by scanning characters one by one. What the program does: • Takes a sentence as input • Iterates through each character • Detects transitions between spaces and words • Counts words manually without using split() • Handles punctuation and extra spaces How the logic works: •Two variables are initialized: – word_count to track the number of words – in_word to track whether we are currently inside a word •The program loops through each character in the sentence •If the character is alphanumeric (isalnum()): – It indicates part of a word – If we were not previously inside a word, the word count increases •If the character is not alphanumeric: – It marks the end of a word – in_word becomes False •This continues until the entire sentence is processed Example: Input: "Hello world! How are you?" Output: Word count → 5 Another example: Input: "This is a test sentence with extra spaces." Output: Word count → 8 Another example: Input: "One-two three." Output: Word count → 3 Why this approach is useful: – Shows how word counting works internally – Avoids built-in shortcuts – Handles punctuation and multiple spaces – Time Complexity: O(n) Key learnings from Day 35: – Parsing strings character by character – Using boolean flags to track state – Understanding how word boundaries work – Strengthening string processing logic #100DaysOfCode #Day35 #Python #PythonProgramming #StringProcessing #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
SATISH KUMAR’s Post
More Relevant Posts
-
Day 41 of my #100DaysOfCode challenge 🚀 Today I implemented the Quick Sort algorithm in Python. Quick Sort is one of the most efficient and widely used sorting algorithms based on the divide-and-conquer approach. What the program does: • Takes an unsorted list as input • Selects a pivot element • Divides the list into three parts – Elements smaller than pivot – Elements equal to pivot – Elements greater than pivot • Recursively sorts the left and right parts • Combines everything into a sorted list How the logic works: • If the list has 1 or 0 elements, it is already sorted • A pivot element is selected (middle element in this case) • The list is divided into three parts: – left → elements less than pivot – middle → elements equal to pivot – right → elements greater than pivot • Recursively apply Quick Sort on left and right • Combine results: sorted = left + middle + right Example: Input: [3, 6, 8, 10, 1, 2, 1] Output: [1, 1, 2, 3, 6, 8, 10] Why Quick Sort is powerful: – Average Time Complexity: O(n log n) – Faster in practice than many sorting algorithms – Widely used in real-world applications Key learnings from Day 41: – Understanding pivot-based partitioning – Applying divide-and-conquer strategy – Writing recursive logic efficiently – Strengthening advanced DSA concepts #100DaysOfCode #Day41 #Python #PythonProgramming #QuickSort #SortingAlgorithms #DataStructures #Algorithms #DivideAndConquer #ProblemSolving #CodingPractice #InterviewPrep #LearnByDoing #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 45 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to check if an array contains duplicates within a given distance k. This problem is widely asked in interviews and helps in understanding hashing and efficient lookups. What the program does: • Takes an array and an integer k as input • Checks if any duplicate elements exist within distance k • Returns True if such duplicates exist • Otherwise returns False How the logic works: • A dictionary (num_indices) is used to store the last seen index of each number • Traverse the array using enumerate() • For each element: – If it already exists in the dictionary – Check the distance between indices • If the difference is ≤ k, return True • Otherwise, update the index of the current element • If no such pair is found, return False Example: Input: nums = [1, 2, 3, 1], k = 3 Output: True (duplicate 1 found within distance 3) Another example: Input: nums = [1, 2, 3, 4, 5], k = 2 Output: False Another example: Input: nums = [1, 0, 1, 1], k = 1 Output: True Why this approach is efficient: – Uses hashing for constant-time lookup – Time Complexity: O(n) – Space Complexity: O(n) Key learnings from Day 45: – Using dictionaries for fast lookups – Understanding index-based conditions – Applying hashing in real problems – Writing optimized solutions for interviews #100DaysOfCode #Day45 #Python #PythonProgramming #Hashing #SlidingWindow #DataStructures #Algorithms #ProblemSolving #CodingPractice #InterviewPrep #LearnByDoing #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 40 of my #100DaysOfCode challenge 🚀 Today I implemented the Merge Sort algorithm in Python. Merge Sort is a powerful divide-and-conquer algorithm that divides the list into smaller parts, sorts them, and then merges them back together. What the program does: • Takes an unsorted list as input • Recursively divides the list into halves • Sorts each half separately • Merges the sorted halves into a final sorted list How the logic works: • If the list has 1 or 0 elements, it is already sorted (base case) • The list is divided into two halves using the middle index • Each half is recursively sorted using merge_sort() • A helper function merge() combines the two sorted halves • Elements are compared and merged in sorted order • Remaining elements are appended after comparison Example: Input: [38, 27, 43, 3, 9, 82, 10] Output: [3, 9, 10, 27, 38, 43, 82] Why Merge Sort is powerful: – Time Complexity: O(n log n) – Efficient for large datasets – Stable sorting algorithm – Widely used in real-world applications Key learnings from Day 40: – Understanding divide-and-conquer strategy – Writing recursive functions – Merging sorted arrays efficiently – Moving towards advanced DSA concepts #100DaysOfCode #Day40 #Python #PythonProgramming #MergeSort #SortingAlgorithms #DataStructures #Algorithms #DivideAndConquer #ProblemSolving #CodingPractice #InterviewPrep #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 43 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the Longest Common Prefix (LCP) among a list of strings. This is a popular problem that helps strengthen string manipulation and comparison logic. What the program does: • Takes a list of strings as input • Finds the common starting characters shared by all strings • Returns the longest common prefix • Handles edge cases like empty lists and single strings How the logic works: • If the list is empty, return an empty string • Sort the list of strings • Compare only the first and last strings (they will have the maximum difference) • Iterate character by character • Add matching characters to the prefix • Stop when characters don’t match • Return the final prefix Example: Input: ["flower", "flow", "flight"] Output: "fl" Another example: Input: ["dog", "racecar", "car"] Output: "" (No common prefix) Another example: Input: ["apple", "apricot", "april"] Output: "ap" Why this approach works well: – Sorting reduces comparisons to just two strings – Efficient and easy to implement – Time Complexity: O(n log n + m) Key learnings from Day 43: – String comparison techniques – Using sorting to simplify problems – Handling edge cases effectively – Writing optimized and clean logic #100DaysOfCode #Day43 #Python #PythonProgramming #Strings #Algorithms #ProblemSolving #CodingPractice #DataStructures #InterviewPrep #LearnByDoing #DeveloperGrowth #ProgrammingJourney #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 39 of my #100DaysOfCode challenge 🚀 Today I revisited and strengthened my understanding of the Insertion Sort algorithm in Python. Repetition is key in mastering Data Structures & Algorithms, so I reimplemented Insertion Sort to improve clarity and confidence. What the program does: • Takes an unsorted list as input • Iterates through elements one by one • Places each element at its correct position • Builds a sorted list step by step How the logic works: • Start from the second element of the list • Store the current element as key • Compare it with elements before it • Shift larger elements one position to the right • Insert the key at its correct position • Repeat until the entire list is sorted Example: Input: [12, 11, 13, 5, 6] Output: [5, 6, 11, 12, 13] Another example: Input: [64, 25, 12, 22, 11] Output: [11, 12, 22, 25, 64] Why revisiting algorithms matters: – Improves problem-solving speed – Strengthens conceptual clarity – Builds confidence for interviews – Helps write optimized code faster Key learnings from Day 39: – Reinforcing sorting algorithm concepts – Improving implementation accuracy – Practicing clean and readable code – Building consistency in DSA #100DaysOfCode #Day39 #Python #PythonProgramming #InsertionSort #SortingAlgorithms #DataStructures #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Today's topic: recursion. A function that calls itself. Sounds simple, right? Here are two ways to add up a list of numbers: Without recursion — honest, reliable, easy to follow: python def suma(lista): suma = 0 for i in range(0, len(lista)): suma = suma + lista[i] return suma print(suma([6,3,4,2,10])) # 25 With recursion — elegant, almost poetic... and a little terrifying: python def suma(lista): if len(lista) == 1: return lista[0] else: return lista[0] + suma(lista[1:]) print(suma([6,3,4,2,10])) # 25 Same result. Two completely different roads to get there. The recursive version looks more "pro" — but if you forget to define when it stops, the function calls itself forever. Literally. Forever. 💀 So yes, it's getting challenging. And yes, recursion feels more elegant to write. But I'm not ready to fully trust something that could loop into oblivion if I blink wrong. Lesson of the day: simple is not the same as bad. And documenting the moments that confuse you? That's part of learning too. #Python #LearningToCode #DaysOfCode #PythonProgramming #CodingJourney #Recursion #BeginnerCoder #TechLearning #CodeNewbie #LinkedInLearning
To view or add a comment, sign in
-
-
Day 36 of my #100DaysOfCode challenge 🚀 Today I worked on implementing the Insertion Sort algorithm in Python. Insertion Sort is a simple and intuitive sorting technique where elements are picked one by one and inserted into their correct position in the sorted part of the list. What the program does: • Takes an unsorted list as input • Iterates through elements starting from the second element • Compares the current element with previous elements • Shifts larger elements to the right • Inserts the element in the correct position How the logic works: 1. Start from the second element of the list (index 1) 2. Store the current element as key 3. Compare it with elements before it 4. Shift larger elements one position to the right 5. Insert the key into its correct sorted position 6. Repeat until the entire list is sorted Example: Input: [12, 11, 13, 5, 6] Output: [5, 6, 11, 12, 13] Another example: Input: [64, 34, 25, 12, 22, 11, 90] Output: [11, 12, 22, 25, 34, 64, 90] Why Insertion Sort is useful: – Easy to understand and implement – Works efficiently for small or nearly sorted datasets – Time Complexity: O(n²) (worst case) Key learnings from Day 36: – Understanding basic sorting algorithms – Working with element shifting logic – Implementing algorithmic thinking step by step – Strengthening Data Structures & Algorithms fundamentals #100DaysOfCode #Day36 #Python #PythonProgramming #InsertionSort #SortingAlgorithms #DataStructures #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 49 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the Equilibrium Index of an array. An equilibrium index is an index where the sum of elements on the left is equal to the sum of elements on the right. What the program does: • Takes an array as input • Finds an index where left sum = right sum • Returns the index if found • Returns -1 if no such index exists How the logic works: • Calculate the total sum of the array • Initialize left_sum = 0 • Traverse the array using enumerate() • For each element: – Right sum = total_sum - left_sum - current element – If left_sum == right_sum, return the index • Add the current element to left_sum • If no equilibrium index is found, return -1 Example: Input: [-7, 1, 5, 2, -4, 3, 0] Output: 3(Left sum = Right sum = 1) Another example: Input: [1, 2, 3] Output: -1 (No equilibrium index) Another example: Input: [1, 0, -1] Output: 1 Why this approach is efficient: – Uses prefix sum concept – Avoids nested loops – Time Complexity: O(n) Key learnings from Day 49: – Understanding prefix sums – Optimizing from brute force to O(n) – Working with running totals – Strengthening array problem-solving #100DaysOfCode #Day49 #Python #PythonProgramming #Arrays #PrefixSum #Algorithms #DataStructures #ProblemSolving #CodingPractice #InterviewPrep #LearnByDoing #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 9 of #100DaysOfCode — Finding the Sum of the Smallest Numbers in Python Today I explored two different approaches to solve a simple but important problem: 👉 Find the sum of the smallest N numbers in a list ✅ Approach 1: Pythonic & Efficient numbers = [5, 2, 9, 1, 7] n = 2 result = sum(sorted(numbers)[:n]) print(result)🔹 How it works: sorted(numbers) → sorts the list[:n] → picks the smallest n elementssum() → adds them up💡 Clean, readable, and perfect for most use cases. ✅ Approach 2: Manual Logic (Without Built-ins) arr = [5, 2, 9, 4, 3, 5] N = 2 total = 0 data = len(arr) for k in range(N): min_index = 0 for i in range(1, data): if arr[i] < arr[min_index]: min_index = i total += arr[min_index] arr[min_index] = float('inf') print("Sum of smallest", N, "numbers:", total)🔹 How it works: Repeatedly finds the smallest elementAdds it to totalMarks it as used (by setting to infinity)💡 Great for understanding core logic and algorithm design 🔍 Key Takeaways ✔️ Built-in functions save time and reduce complexity ✔️ Manual approach helps strengthen problem-solving skills ✔️ Always balance readability vs control 💬 Best Comment Insight “Don’t just learn shortcuts — understand what’s happening under the hood. That’s where real growth happens.” #Python #CodingJourney #30DaysOfCode #LearnToCode #Programming #Developers #ProblemSolving #PythonBasics
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