Day 20 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the missing number in a sequence of natural numbers. The goal was to solve the problem efficiently using a mathematical formula instead of looping through numbers manually. What the program does: • Takes a list of numbers with one missing value • Calculates the expected sum of first n natural numbers • Calculates the actual sum of the given list • Finds the missing number by subtracting both sums How the logic works: Since one number is missing, the total count should be len(numbers) + 1 The formula for sum of first n natural numbers is used: n * (n + 1) // 2 The actual sum of the list is calculated using sum() The missing number is found using: expected_sum - actual_sum The result is printed Example: Input list:[1, 2, 3, 5, 6, 7, 8] Output: Missing number: 4 Key learnings from Day 20: – Using mathematical formulas for optimization – Reducing time complexity to O(n) – Avoiding unnecessary loops – Strengthening problem-solving approach #100DaysOfCode #Day20 #Python #PythonProgramming #Algorithms #ProblemSolving #CodingPractice #LogicBuilding #LearnByDoing #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
Python Program Finds Missing Number in Sequence
More Relevant Posts
-
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 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 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
To view or add a comment, sign in
-
-
Organizing Data Lists & Tuples Day 5: If variables are containers, today I learned how to build a warehouse. I dove deep into Lists and Tuples. Lists: Perfect for items that need to change, grow, or be sorted (Mutable). Tuples: The "set it and forget it" version (Immutable). Learning how to slice through a list felt like a superpower. It’s amazing how much more organized your logic becomes when you know how to group your data properly. A Python tuple is an ordered and immutable collection of elements enclosed in parentheses, commonly used for grouping related data that should not change. #DataStructures #PythonLists #LearningInPublic #TechJourney #Pythonday5
To view or add a comment, sign in
-
-
📅 Weekly Learning Log — Phase 1, Week 1 Committing to learning Python in public. Here's what I covered this week: 🗓 Day 2 — Variables, built-in functions & type casting (int, float, str, list, tuple) 🗓 Day 3 — Booleans, arithmetic, comparison & logical operators. Applied maths: slope, Euclidean distance, area 🗓 Day 4 — Strings: slicing, f-strings, escape sequences, 20+ string methods 🗓 Day 5 — Lists: indexing, unpacking with *rest, append/pop/del, sort, extend 💻 Also grinding the HackerRank Python track — currently at 115/220 points with Hello World & If-Else solved, Loops next! Key insight: the [start:end:step] slicing pattern works the same way on strings AND lists — that clicked everything into place. Onwards to tuples, sets, and dictionaries next week. 🐍 Following the 30 Days of Python challenge by Asabeneh Yetayeh. #Python #30DaysOfPython #LearningInPublic #HackerRank #CodingJourney #PythonProgramming #UMPSA #Phase1 #WeeklyLog #CodeNewbie
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 68 of 100 Days LeetCode Challenge Problem: 🔹 #1207 – Unique Number of Occurrences 🔗 https://lnkd.in/g2vjwwft Learning Journey: 🔹 Today’s problem required checking whether the frequency of each element in an array is unique. 🔹 I first used Counter to count how many times each number appears in the array. 🔹 Then I extracted the occurrence counts using .values(). 🔹 To verify uniqueness, I compared the length of the occurrences list with the length of a set created from those values. 🔹 If both lengths match, it means all occurrence counts are unique. Concepts Used: 🔹 Hash Map / Frequency Counting 🔹 Python Counter from collections 🔹 Sets for Uniqueness Check Key Insight: 🔹 Converting values to a set removes duplicates automatically. 🔹 If the size of the set equals the number of frequency values, then all occurrence counts are distinct. Complexity: 🔹 Time: O(n) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
🔥 Day 2 of #100DaysOfLeetCode 📌 Problem: Largest Number — Medium (#179) 🔗 https://lnkd.in/dzV8UhUc 💡 Approach: Normal sorting doesn't work here! The trick is to compare numbers by their concatenation. For "3" and "30" → compare "330" vs "303" → "330" wins → 3 comes first! Used Bubble Sort with a custom comparator — no extra libraries needed. 🐍 My Python Solution: nums = list(map(str, nums)) for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i]+nums[j] < nums[j]+nums[i]: nums[i], nums[j] = nums[j], nums[i] result = "".join(nums) return "0" if result[0]=="0" else result 📚 What I Learned Today: Sometimes the sorting key isn't the value itself — it's how two elements behave TOGETHER. Concatenation comparison is a powerful trick for number ordering problems! ⚡ Time : O(n²) — Bubble Sort 📦 Space : O(n) — String conversion #LeetCode #Python #DSA #100DaysOfLeetCode #100DaysOfCode #CodingJourney #DataScience #ProblemSolving #Programming #CS
To view or add a comment, sign in
-
-
🚀 Day 51 of My Python Journey Today I solved Apply Discount to Prices on LeetCode. 🔍 Problem Overview: The problem gives a sentence containing words and prices (values starting with $). The task is to apply a given discount percentage to all valid prices and return the updated sentence. The updated prices must be formatted with exactly two decimal places. 🧠 Approach: • Split the sentence into individual words. • Check whether a word represents a valid price (starts with $ and the remaining characters are digits). • Convert the price to an integer and apply the discount formula. • Format the discounted price to two decimal places and rebuild the sentence. ⚡ Key Learnings: • Practiced string parsing and validation • Improved understanding of formatting numbers in Python • Strengthened problem-solving using conditional logic 📊 Complexity: • Time Complexity: O(n) • Space Complexity: O(n) Under the Guidance of : Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day51 #Python #LeetCode #DataStructures #Algorithms #CodingJourney #ProblemSolving #100DaysOfCode
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
-
Explore related topics
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