Day 6 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the second largest number in a list without using sorting. Finding the second largest element means identifying the number that is greater than all others except the maximum value. What the program does: • Takes a list of numbers as input • Handles edge cases like lists with fewer than two elements • Traverses the list only once for efficiency • Finds the second largest value without using built-in sorting How the logic works: If the list has fewer than two elements, the function returns None Two variables (first and second) are initialized to negative infinity The list is traversed element by element If the current number is greater than first, – second is updated with the previous first – first is updated with the current number If the number lies between first and second, second is updated Example: Original list: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] Output: Second largest number = 6 Key learnings from Day 6: – Tracking multiple values in a single loop – Writing optimized logic without sorting – Understanding time complexity (O(n)) – Improving problem-solving skills in Python #100DaysOfCode #Day6 #Python #PythonProgramming #ProblemSolving #DSA #LearningInPublic #BTech #CSE #AIandML #DataStructures #CodingChallenge #CodeNewbie #TechJourney
Python Program Finds Second Largest Number in List Without Sorting
More Relevant Posts
-
Day 9 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the second largest number in a list using an optimized approach. The goal was to solve the problem without sorting the list and by traversing it only once. What the program does: • Takes a list of numbers as input • Handles edge cases where a second largest element does not exist • Tracks the largest and second largest values efficiently • Returns the second largest number How the logic works: If the list contains fewer than two elements, the function returns None Two variables (first and second) are initialized with negative infinity The list is traversed one element at a time If the current number is greater than first: – second is updated with the previous first – first is updated with the current number If the number lies between first and second, second is updated After traversal, the function returns the second largest value Example: Input list: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] Output: Second largest number = 6 Key learnings from Day 9: – Solving problems without built-in sorting – Using conditional logic effectively – Understanding single-pass algorithms – Writing optimized Python code #100DaysOfCode #Day9 #Python #PythonProgramming #ProblemSolving #DataStructures #CodingChallenge #LearningInPublic #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 7 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to remove duplicate elements from a list while preserving the original order. Removing duplicates means keeping only the first occurrence of each element and ignoring repeated values. What the program does: • Takes a list of elements as input • Traverses the list one element at a time • Stores only unique elements in a new list • Preserves the original order of elements How the logic works: An empty list (unique_list) is created to store unique elements The program iterates through each item in the original list If the item is not already present in unique_list, it is added Duplicate elements are skipped automatically The final list containing only unique elements is returned Example: Original list: [1, 2, 2, 3, 4, 4, 5] Output: List without duplicates: [1, 2, 3, 4, 5] Key learnings from Day 7: – Understanding list traversal in Python – Preserving order while removing duplicates – Writing clean and readable functions – Strengthening basic logic-building skills #100DaysOfCode #Day7 #Python #PythonProgramming #ProblemSolving #CodingChallenge #LearningInPublic #CodeNewbie #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 32 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to implement a custom version of the isdigit() function. Instead of using Python’s built-in method, I created my own function to check whether a string contains only numeric digits. What the program does: • Takes a string as input • Checks each character in the string • Verifies whether it lies between '0' and '9' • Returns True if all characters are digits • Returns False otherwise How the logic works: 1)The function first checks if the string is empty 2)If it is empty, it returns False 3)The program iterates through each character in the string 4)It checks whether the character falls within the range '0' to '9' 5)If any character fails this condition, the function returns False 6)If all characters satisfy the condition, the function returns True Example: Input: "123" Output: True Input: "123a" Output: False Input: "-1" Output: False Input: "0" Output: True Why this is useful: – Helps understand how built-in functions work internally – Uses ASCII character comparison – Strengthens string validation logic Key learnings from Day 32: – Implementing built-in functionality manually – Understanding ASCII-based comparisons – Writing validation logic for strings – Strengthening Python fundamentals #100DaysOfCode #Day32 #Python #PythonProgramming #StringValidation #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 17 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to count the number of vowels and consonants in a given string. The goal was to practice string traversal and character classification. What the program does: • Takes a string input from the user • Converts the string to lowercase for consistency • Checks each character individually • Counts vowels and consonants separately • Returns both counts How the logic works: A function count_vowels_consonants(string) is defined Two strings are created: – One containing all vowels (aeiou) – One containing all consonants Two counters are initialized to 0 The program loops through each character in the string If the character is in the vowel string, vowel count increases If the character is in the consonant string, consonant count increases The function returns both counts Example: Input: my name is SATISH KUMAR Output: Vowels: 7 Consonants: 12 Key learnings from Day 17: – Iterating through strings – Using conditional statements effectively – Handling case sensitivity with .lower() – Strengthening basic string manipulation skills #100DaysOfCode #Day17 #Python #PythonProgramming #StringManipulation #ProblemSolving #CodingPractice #LogicBuilding #LearnByDoing #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Python Journey — Day 13 | Functions with Numbers, Strings & Lists Today I continued practicing functions in Python by solving different logical problems using reusable function-based solutions. Problems I solved : • Sum of digits of a number • Product of digits • Armstrong number check • Reverse a number • Palindrome number check • Count vowels in a string • Count consonants in a string • Perfect number check • Strong number check • Find largest element in a list • Remove duplicates from a list • Reverse a list • Find second largest element • Count even and odd numbers in a list I implemented these problems using functions along with loops and list and string logic to improve code reusability and structure. Thanks to Rudra Sravan kumar sir for the guidance and continuous support. Learning daily and getting more confident #Python #PythonDeveloper #1000Coders #Coding #LearningJourney #ProblemSolving #CodeEveryDay
To view or add a comment, sign in
-
Day 11 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find all pairs in a list that add up to a given target sum. The goal was to solve this efficiently without using nested loops. What the program does: • Takes a list of numbers and a target sum as input • Uses a set to track previously seen numbers • Finds pairs whose sum equals the target value • Returns all valid pairs How the logic works: An empty list pairs is created to store valid pairs A set seen is initialized to keep track of visited numbers The list is traversed one element at a time For each number, its complement is calculated as: complement = target_sum - num If the complement already exists in the set, a pair is formed The current number is added to the set for future comparisons After traversal, all valid pairs are returned Example: Numbers: [1, 2, 3, 4, 5, 6] Target Sum: 7 Output: Pairs with sum 7: [(3, 4), (2, 5), (1, 6)] Key learnings from Day 11: – Using sets for efficient lookups – Reducing time complexity from O(n²) to O(n) – Applying complement logic – Writing optimized and clean Python functions #100DaysOfCode #Day11 #Python #PythonProgramming #DataStructures #Algorithms #HashSet #ProblemSolving #CodingPractice #LearningInPublic #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
🚀#120DaysChallenge of Python Full Stack Journey Hello everyone, I’m Lakshmi Sravani 😊 #120DaysChallenge. #34Day - Modules Today I explored and practiced some important built-in Python modules with hands-on examples: 📌 Math Module Importing the math module • Using constants like math.pi • Mathematical functions: sqrt(), pow(), log() • Trigonometric functions: sin(), cos(), tan() • Rounding functions: ceil() – round up floor() – round down • Difference between: import math from math import pi, sqrt, log Understanding NameError when variables/modules are not imported 📌 Sys Module • Exploring sys.path • Understanding Python’s module search path • Using for loop with proper syntax • Checking Python version using sys.version 📌 OS Module • Working with file system operations • os.getcwd() – current working directory • os.listdir() – list files & folders • os.mkdir() – create a new directory • Understanding os.path 📌 Random Module • Generating random numbers using: • randint() • sample() • choice() Practical mini-application: 🎲 Dice Rolling Simulation using while loop Using modules like math, sys, os, and random shows how Python simplifies real-world tasks through reusable and well-structured code. Pooja Chinthakayala Codegnan Uppugundla Sairam Saketh Kallepu #Python #PythonFullStack #120DaysChallenge #LearningJourney #Programming #FreshGraduate #CareerDevelopment #WomenInTech #Codegnan
To view or add a comment, sign in
-
🔥 Day 11/100 – Learning Python Loops 🐍 Today I explored one of the most important concepts in Python — Loops. Loops help us execute a block of code multiple times, making our programs more efficient and powerful. 🔹 For Loop with String We can iterate through each character in a string: Example: Looping through "banana" prints each letter one by one. 🔹 For Loop with range() Using range() helps generate a sequence of numbers. Example: range(6) starts from 0 and ends at 5. 🔹 Nested Loops We can also use a loop inside another loop. Example: Combining adjectives and fruits like: red apple, big banana, tasty cherry. 🔹 Keywords Used in Loops ✔ break ✔ continue ✔ else Understanding loops is very important for data analysis, automation, and problem-solving — especially as I continue learning Python for my tech career. Consistency is the key 🚀 See you tomorrow for Day 12! #Day11 #100DaysOfCode #Python #Programming #LearningJourney #BCA #FutureDataAnalyst If you want, I can also give you a shorter version or a more beginner-friendly version.
To view or add a comment, sign in
-
-
Day 10 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to merge two sorted lists into a single sorted list. The goal was to combine both lists efficiently while maintaining the sorted order — similar to the merging step in Merge Sort. What the program does: • Takes two already sorted lists as input • Compares elements from both lists one by one • Adds the smaller element to a new list • Appends any remaining elements after comparison • Returns the final merged sorted list How the logic works: Two pointers (i and j) are initialized to track positions in both lists A while loop runs until one of the lists is fully traversed The elements at index i and j are compared The smaller element is added to the merged list The corresponding pointer is incremented After the loop, any remaining elements from either list are appended using extend() Example: List 1: [1, 3, 5, 7] List 2: [2, 4, 6, 8] Output: Merged sorted list: [1, 2, 3, 4, 5, 6, 7, 8] Key learnings from Day 10: – Understanding the two-pointer technique – Applying comparison-based logic efficiently – Learning the core idea behind Merge Sort – Writing clean and structured functions #100DaysOfCode #Day10 #Python #PythonProgramming #DataStructures #Algorithms #TwoPointerTechnique #CodingPractice #LearningInPublic #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 14 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the common elements between two lists using sets. The goal was to solve the problem efficiently without using nested loops. What the program does: • Takes two lists as input • Converts both lists into sets • Uses set intersection to find common elements • Converts the result back into a list • Prints the common elements How the logic works: Two lists are defined with numeric values Both lists are converted into sets using set() The intersection operator & is used to find common elements The resulting set is converted back into a list The final list of common elements is displayed Example: List 1:[1, 2, 3, 4, 5] List 2:[4, 5, 6, 7, 8] Output: Common elements:[4, 5] Key learnings from Day 14: – Understanding set operations in Python – Using intersection (&) efficiently – Avoiding nested loops for better performance – Writing clean and optimized code #100DaysOfCode #Day14 #Python #PythonProgramming #SetOperations #DataStructures #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #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