Day 25 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to check whether a list is sorted in ascending order. The goal was to verify the order of elements by comparing each element with the next one. What the program does: • Takes a list as input • Compares each element with the next element • Checks if the list follows ascending order • Returns True if sorted, otherwise False How the logic works: 1)A function is_sorted(lst) is defined 2)A loop runs from the first element to the second-last element 3)Each element is compared with the next element (lst[i] and lst[i+1]) 4)If any element is greater than the next one, the list is not sorted 5)The function immediately returns False 6)If the loop finishes without finding such a case, the function returns True Example: List 1: [1, 2, 3, 4, 5] → Sorted → True List 2: [1, 3, 2, 4, 5] → Not Sorted → False List 3: [] → Sorted → True List 4: [7] → Sorted → True Why this works well: – Only one pass through the list – Time Complexity: O(n) – Works for empty and single-element lists Key learnings from Day 25: – Sequential comparison logic – Handling edge cases in lists – Writing efficient list validation functions – Strengthening algorithmic thinking #100DaysOfCode #Day25 #Python #PythonProgramming #Algorithms #ProblemSolving #DataStructures #CodingPractice #LogicBuilding #LearnByDoing #ComputerScience #InterviewPrep #BTech #CSE #AIandML #VITBhopal #TechJourney
Python Ascending Order Checker
More Relevant Posts
-
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
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 30 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to check whether two strings are rotations of each other. The idea is that if one string is a rotation of another, it will appear as a substring of the original string concatenated with itself. What the program does: • Takes two strings as input • Checks if both strings have the same length • Concatenates the first string with itself • Verifies if the second string exists inside the concatenated string • Returns True if they are rotations, otherwise False How the logic works: 1)First, the program checks if both strings have equal length 2)If lengths differ, they cannot be rotations 3)The first string is concatenated with itself: temp = string1 + string1 4)If string2 appears as a substring inside temp, then it is a valid rotation 5)The function returns the result (True or False) Example: String 1:"abcde" String 2:"cdeab" Output: True (because "cdeab" is a rotation of "abcde") Another example: String 1:"abc" String 2:"acb" Output:False Why this approach works well: – Uses string concatenation trick – Avoids complex rotation checks – Time Complexity: O(n) Key learnings from Day 30: – Understanding string rotation logic – Using substring checks effectively – Solving problems with simple mathematical insights – Strengthening string manipulation skills #100DaysOfCode #Day30 #Python #PythonProgramming #StringAlgorithms #ProblemSolving #CodingPractice #DataStructures #Algorithms #InterviewPrep #LearnByDoing #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
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 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 29 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the maximum occurring character in a string. The goal was to count the frequency of each character and determine which one appears the most. What the program does: • Takes a string as input • Counts the frequency of each character using a dictionary • Tracks the character with the highest occurrence • Handles edge cases like an empty string • Returns the most frequent character How the logic works: 1)A dictionary char_counts is used to store character frequencies 2)The program iterates through each character in the string 3)For every character, its count is updated using .get(char, 0) + 1 4)After counting, another loop checks which character has the highest frequency 5)The character with the maximum count is stored and returned 6)If the string is empty, the function returns None Example: Input: "hello world" Output: Maximum occurring character → l Input: "program" Output: Maximum occurring character → r Why this approach works well: – Uses dictionary for fast lookups – Time Complexity: O(n) – Efficient way to track frequencies Key learnings from Day 29: – Using dictionaries for frequency counting – Iterating through strings efficiently – Handling edge cases in programs – Strengthening string manipulation logic #100DaysOfCode #Day29 #Python #PythonProgramming #StringManipulation #Algorithms #ProblemSolving #CodingPractice #DataStructures #InterviewPrep #LearnByDoing #ComputerScience #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 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 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
-
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