#100DaysOfCode – Day 71 String Rotation Task: Given two strings s and goal, determine if s can become goal after some number of rotations (moving the first character to the end each time). Example: Input: s = "abcde", goal = "cdeab" Output: true My Approach First, check if both strings have the same length otherwise, rotation is impossible. Then, observe that any valid rotation of s will always appear as a substring in s + s. Simply check: return (s + s).contains(goal); Time Complexity: O(N²) Space Complexity: O(N) Sometimes, elegant insights lead to minimal code doubling a string can reveal every possible rotation effortlessly! #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #StringManipulation #takeUforward #GeeksForGeeks #CodeNewbie #InterviewPrep
How to check if a string can be rotated to match another string in Java
More Relevant Posts
-
#100DaysOfCode – Day 67 Reverse Words in a String Problem: – Reverse Words in a String Task: – Given a string, reverse the order of the words and remove extra spaces. Example: Input: s = " the sky is blue " → Output: "blue is sky the" My Approach: Used trim() to remove leading and trailing spaces. Split the string using split("\\s+") to handle multiple spaces. Reversed the array and joined the words with a single space. Time Complexity: O(N) | Space Complexity: O(N) Even simple string problems can teach the importance of clean code and efficient use of built-in methods. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #GeeksForGeeks #CodeNewbie #StringManipulation
To view or add a comment, sign in
-
-
💡 LeetCode #344 — Reverse String Today I solved LeetCode Problem 344: Reverse String 🔁 Problem Summary: Write a function that reverses a string. The input string is given as a character array s, and you must reverse it in-place (without using extra space). Key Idea: Use the two-pointer technique 👈👉 Initialize one pointer at the start (left) and another at the end (right). Swap the characters at both pointers and move them toward the center. #LeetCode #Java #DSA #TwoPointers #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🎯 LeetCode 394 – Decode String Today I solved a really interesting Stack + String based problem! 💡 Problem Summary: We are given an encoded string containing patterns like 3[a2[c]] where: Numbers represent how many times the substring should repeat. Nested patterns are allowed. The goal is to decode the string correctly. 🧠 Approach: I used two stacks: One to store counts (how many times to repeat) One to store previously formed strings We iterate through the string: Build numbers when digits appear When [ appears, push state to stacks When ] appears, pop and reconstruct substring Else, just append characters normally ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(n) #LeetCode #Java #DSA #Stack #StringManipulation #CodingJourney #LearnEveryday #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
🔹 Day 46: Is Subsequence (LeetCode #392) 📌 Problem Statement: Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence is formed by deleting some (possibly none) characters from the original string without disturbing the relative order of the remaining characters. ✅ My Approach: I used a two-pointer technique — one pointer iterates through string t, and the other tracks progress through string s. Each time a matching character is found, the pointer for s moves forward. If we reach the end of s, it means all its characters appeared in sequence within t. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ⚡ Submission Stats: Runtime: 2 ms (Beats 68.53%) Memory: 41.32 MB (Beats 87.28%) 💡 Reflection: A simple yet elegant problem that highlights how pointer movement can efficiently handle string comparisons without extra memory usage. ✨ #LeetCode #Java #Strings #TwoPointers #100DaysOfCode #Day46
To view or add a comment, sign in
-
-
💡 LeetCode #58 — Length of Last Word Today I solved LeetCode Problem 58: Length of Last Word 🧠 Problem Summary: Given a string s consisting of words and spaces, return the length of the last word in the string. A word is defined as a sequence of non-space characters. Key Idea: We can traverse the string from end to start — Skip trailing spaces. Count the number of characters until the next space (which marks the last word). This avoids unnecessary splitting and saves extra space. #LeetCode #Java #DSA #Strings #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 85 Delete the Middle Node of a Linked List Problem Statement: Given the head of a singly linked list, delete the middle node and return the modified list. My Approach: Used two-pointer technique (slow & fast) to identify the middle node in a single traversal. Maintained a prev pointer to skip the middle node without extra space. Carefully handled the edge case when the list has only one node. Complexity: Time: O(N) Space: O(1) Linked lists are all about pointers and precision a small mistake (like an extra semicolon ";") can make a huge difference. Understanding how slow and fast pointers move gives deep insight into efficient traversal patterns. #LeetCode #100DaysOfCode #Java #LinkedList #ProblemSolving #takeUforward #CodingJourney #DataStructures #CodeNewbie
To view or add a comment, sign in
-
-
💡 LeetCode #15 — 3Sum Today I solved LeetCode Problem 15: 3Sum 🔍 Problem Summary: Given an integer array nums, return all unique triplets (a, b, c) such that: a + b + c = 0 The solution must not contain duplicate triplets. Key Idea: Use sorting + two pointers to reduce the time from O(n³) to O(n²). Steps: Sort the array. Fix one number (nums[f]) in each iteration. Use two pointers (i and j) to find pairs whose sum equals -nums[f]. Skip duplicates for both the fixed index and the pointer values. This efficiently finds all unique triplets. #LeetCode #Java #DSA #TwoPointers #ProblemSolving #CodingChallenge #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 33 of My Daily Coding Challenge 🚀 Today I implemented and revised Cyclic Sort (Java) — one of the most efficient sorting techniques for arrays containing numbers from 1 to N. 💡 Key takeaway: Instead of comparing adjacent elements, Cyclic Sort keeps placing each number at its correct index — making it super fast for such problems. 🔗 Solution: [https://lnkd.in/epUjThMt] Building consistency, one algorithm at a time 💻💪 #DailyCodingChallenge #Java #DSA #CyclicSort #SortingAlgorithms #100DaysOfCode #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 6/60 — #60DaysDSAChallenge Today's question: Check if a String is Palindrome or Not 🔄 Concept: A palindrome is a string that reads the same backward as forward — like madam, level, or racecar. 📚 What I learned: • How to compare characters from both ends of a string • Improved my understanding of string manipulation • Focused on writing clean and simple logic Small progress every day adds up to big results 🚀 #DSA #Java #CodingJourney #ProblemSolving #Consistency #LearnCoding #DSAChallenge #60DaysDSAChallenge
To view or add a comment, sign in
-
-
📌 Day 3/100 - Remove Duplicates from Sorted Array (LeetCode 26) 🔹 Problem: Given a sorted array, remove the duplicates in-place so that each element appears only once and return the new length. You must modify the array without using extra space for another array. 🔹 Approach: I used a simple counting-based approach: Iterate through the array using a single loop. If the current element is the same as the next, skip it. Otherwise, place it at the current count index and increment count. Finally, return count as the number of unique elements. 🔹 Key Learning: Practiced in-place array modification efficiently without extra space. Improved understanding of loop-based filtering logic. Realized that sometimes the simplest linear approach works best! Consistency compounds — each problem adds a new layer of confidence! 🚀#100DaysOfCode #LeetCode #Java #ProblemSolving #Array #DSA #TwoPointers
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