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
Python String Rotation Check with Concatenation
More Relevant Posts
-
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 34 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find all possible substrings of a given string. A substring is a continuous sequence of characters within a string. The goal was to generate every possible substring using nested loops. What the program does: • Takes a string as input • Uses nested loops to generate substrings • Extracts substrings using string slicing • Stores all substrings in a list • Returns the list of all substrings How the logic works: •A function find_all_substrings(s) is defined •An empty list substrings is created to store results •The first loop selects the starting index i •The second loop selects the ending index j •Each substring is extracted using slicing: s[i:j+1] •The substring is appended to the result list •Finally, all substrings are returned Example: Input: "abc" Output: ['a', 'ab', 'abc', 'b', 'bc', 'c'] Another example: Input: "hello" Output: ['h', 'he', 'hel', 'hell', 'hello', 'e', 'el', 'ell', 'ello', 'l', 'll', 'llo', 'l', 'lo', 'o'] Why this approach works well: – Uses nested loops to explore all start–end positions – Demonstrates string slicing clearly – Time Complexity: O(n²) Key learnings from Day 34: – Understanding substring generation – Using nested loops effectively – Applying string slicing in Python – Strengthening string algorithm concepts #100DaysOfCode #Day34 #Python #PythonProgramming #StringAlgorithms #ProblemSolving #CodingPractice #Algorithms #LearnByDoing #ComputerScience #ProgrammingJourney #DeveloperGrowth #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 31 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to remove all vowels from a given string. The goal was to practice string traversal and filtering characters based on conditions. What the program does: • Takes a string as input • Checks each character in the string • Removes vowels (a, e, i, o, u) in both lowercase and uppercase • Builds a new string without vowels • Returns the final filtered string How the logic works: 1)A string vowels is defined containing all vowel characters 2)An empty string result_string is created to store the result 3)The program loops through each character in the input string 4)If the character is not a vowel, it is added to result_string 5)The process continues until all characters are checked 6)Finally, the filtered string is returned Example: Input: "Hello World" Output:"Hll Wrld" Another example: Input: "AEIOUaeiou" Output: "" (All characters are vowels) Why this approach works well: – Simple and easy to understand logic – Efficient single-pass traversal – Time Complexity: O(n) Key learnings from Day 31: – Iterating through strings – Filtering characters based on conditions – Working with string concatenation – Strengthening string manipulation fundamentals #100DaysOfCode #Day31 #Python #PythonProgramming #StringManipulation #ProblemSolving #CodingPractice #Algorithms #LearnByDoing #ComputerScience #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 42 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the K-th largest element in an array. This is a common problem in coding interviews and helps build understanding of sorting and indexing. What the program does: • Takes an array and a value k as input • Sorts the array in descending order • Returns the k-th largest element • Handles duplicate values correctly How the logic works: • The array is sorted in descending order using sorted() • Since Python uses 0-based indexing,the k-th largest element is at index k-1 • The element at index k-1 is returned as the result Example: Input: Array: [3, 2, 1, 5, 6, 4] k = 2 Output: 5 (2nd largest element) Another example: Input: Array: [3, 2, 3, 1, 2, 4, 5, 5, 6] k = 4 Output: 4 Why this approach works: – Simple and easy to implement – Uses built-in sorting for reliability – Time Complexity: O(n log n) Key learnings from Day 42: – Understanding sorting in descending order – Working with indexing (k-1) – Solving common interview problems – Handling duplicates in arrays #100DaysOfCode #Day42 #Python #PythonProgramming #Arrays #Sorting #Algorithms #DataStructures #ProblemSolving #CodingPractice #InterviewPrep #LearnByDoing #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
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 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 1: The Foundation & The "Aha!" Moment Focus: Variables & Fundamentals Today, I officially wrote my first lines of Python after a long time, and let’s just say… it was a beautifully humbling experience. 😅 I realized that even the "simplest" tasks—like adding numbers or printing a sentence—require total precision. Python is gentle until you forget a single quote mark, and then it’s game over! What I tackled today: The Execution Flow: Understanding how Python reads code from top to bottom. The Power of Variables: They’re essentially just containers, but naming them is an art form. The Rules: Learned why (my_var) works, but (2_var) breaks everything. Data Types: Realizing that 10 (integer) and "10" (string) might look the same to us, but they are worlds apart to a computer. It’s exciting, a little frustrating, and 100% worth it. 😁 #Python #Day1 #LearningToCode #TechBeginner #CodingFromScratch
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 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