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
Python Program to Find Second Largest Number in List
More Relevant Posts
-
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
-
-
🚀#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 26 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the intersection of two arrays (lists). The goal was to identify the elements that appear in both arrays using Python’s set operations. What the program does: • Takes two lists as input • Converts the lists into sets • Finds the common elements between them • Demonstrates two ways to compute intersection • Prints the intersection result How the logic works: 1)Two lists (arr1 and arr2) are defined 2)Both lists are converted into sets using set() 3)Intersection is calculated using the .intersection() method 4)The same result is also computed using the & operator 5)The resulting set is converted back into a list and printed Example: Input: Array 1:[1, 2, 3, 4, 5] Array 2:[4, 5, 6, 7, 8] Output: Intersection:[4, 5] Why using sets is powerful: – Removes duplicate values automatically – Faster lookup operations – Time Complexity around O(n) Key learnings from Day 26: – Understanding set operations in Python – Using .intersection() vs & operator – Writing efficient list comparison logic – Strengthening data structure knowledge #100DaysOfCode #Day26 #Python #PythonProgramming #SetOperations #DataStructures #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #InterviewPrep #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 12 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to convert a decimal number into its binary representation without using built-in functions like bin(). The goal was to understand how number base conversion works internally. What the program does: • Takes a decimal number as input • Uses division and modulo operations • Builds the binary representation manually • Returns the final binary number as a string How the logic works: An empty string binary is initialized to store the result A while loop runs as long as the number is greater than 0 The remainder when dividing by 2 (n % 2) is calculated The remainder is added to the front of the binary string The number is reduced using integer division (n // 2) The loop continues until the number becomes 0 The final binary string is returned Example: Input - 34 Output - Binary representation of 34 is: 100010 Key learnings from Day 12: – Understanding number system conversion – Using modulo and integer division effectively – Building logic step-by-step without built-in shortcuts – Strengthening fundamental programming concepts #100DaysOfCode #Day12 #Python #PythonProgramming #NumberSystems #BinaryConversion #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #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 47 of My Python & DSA Journey Today I solved the “Check if Binary String Has at Most One Segment of Ones” problem on LeetCode. 🔍 Problem Overview: Given a binary string containing only 0s and 1s, the task is to determine whether the string contains at most one continuous segment of 1s. If multiple separated segments of 1s exist, the result should be False. 🧠 Approach: I iterated through the string and tracked how many times a new segment of 1s starts. Whenever a 1 appears either at the beginning of the string or immediately after a 0, it indicates the start of a new segment. If more than one such segment is found, the condition fails. ⚡ Key Takeaways: • Strengthened understanding of string traversal • Practiced pattern recognition in binary strings • Improved logical problem-solving using Python 📊 Complexity: • Time Complexity: O(n) • Space Complexity: O(1) Consistently solving problems helps me improve my algorithmic thinking and coding efficiency every day. Looking forward to learning more and solving tougher challenges ahead! Under the Guidance of : Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day47 #Python #LeetCode #DataStructures #Algorithms #CodingJourney #ProblemSolving #100DaysOfCode
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
-
-
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 6 of 20 Learning Challenge 🎉🖥 Lists, tuples, and dictionaries are Python's power trio. 🗂️📋 Six days in and I now understand why Python is the world's most popular programming language; it is powerful yet readable. Today I dove deep into Python data structures: lists, tuples, dictionaries, and sets. I learned when to use each one and why it matters. Lists for ordered, mutable data. Tuples for fixed, protected data. Dictionaries for key-value relationships. Sets for unique collections. I built a small contact book program using dictionaries storing names, phone numbers, and emails. Something clicked today. I stopped seeing code as abstract symbols and started seeing it as a blueprint for real-world solutions. 💡 Choose your data structure wisely. The right container makes all the difference. #Python #DataStructures #LearningJourney #WomenInTech #BackendDevelopment #Django #CodeNewbie #Git20DaysChallenge #AfricaAgility #AgitCohort9
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
-
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
keep it up