#100DaysOfCode – Day 72 Rotate String Task: Given two strings s and goal, check if s can become goal after some number of shifts. Example: Input: s = "abcde", goal = "cdeab" → Output: true My Approach: Checked if both strings have the same length. Concatenated the original string: s + s. Verified if goal exists as a substring in the doubled string. Time Complexity: O(N) Space Complexity: O(N) Sometimes, the simplest observation can make a problem effortless like checking if goal exists inside s + s. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #GeeksForGeeks #StringManipulation #CodeNewbie #DSA #CodingJourney
Solved Rotate String problem in Java with simple observation
More Relevant Posts
-
Day 50 of #75DaysDSAChallenge Problem: 7. Reverse Integer Difficulty: 🟠 Medium Platform: LeetCode 🧩 Problem Statement Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes it to go outside the signed 32-bit integer range [-2³¹, 2³¹ - 1], return 0. Example: Input: x = 123 Output: 321 💡 Approach 1️⃣ Extract the last digit using x % 10. 2️⃣ Remove the last digit using x / 10. 3️⃣ Add the digit to the reversed number. 4️⃣ Before updating, check for overflow conditions. 5️⃣ Continue until all digits are processed. #LeetCode #Java #DSA #CodingChallenge #75DaysDSAChallenge #ProblemSolving #TechLearning #CodingJourney
To view or add a comment, sign in
-
-
💡 LeetCode #1 — Two Sum Today I solved LeetCode Problem 1: Two Sum 🔢 Problem Summary: Given an array of integers nums and an integer target, return the indices of the two numbers that add up to the target. You must solve it in O(n) time. Key Idea: Use a HashMap to store numbers and their indices as you traverse the array. For each element, check if target - nums[i] is already in the map. If yes → we’ve found a valid pair. If not → store the current number in the map. This avoids nested loops and gives linear time performance. #LeetCode #Java #DSA #HashMap #TwoSum #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
💻 Day 76 of #100DaysOfCoding Today’s problem was “Check If Digits Are Equal in String After Operations I” (LeetCode – Easy). The task was to repeatedly sum each pair of consecutive digits (mod 10) until the string becomes exactly two digits long and then check if both are equal. I used a simple and clear approach with a while loop and StringBuilder, updating the string in each iteration until it reduced to two digits. It’s a great example of how small logical patterns can make an otherwise repetitive problem neat and efficient ✨ #100DaysOfCoding #LeetCode #CodingJourney #ProblemSolving #Java #CodeEveryday #DSA #WomenInTech #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
-
💡 LeetCode #2824 — Count Pairs Whose Sum Is Less Than Target Today I solved LeetCode Problem 2824: Count Pairs Whose Sum Is Less Than Target 🔢 Problem Summary: Given an integer array nums and a number target, return the number of pairs (i, j) where i < j and nums[i] + nums[j] < target Key Idea: Use the two-pointer technique after sorting the array. Sort the array to make pair checking efficient. Keep one pointer at the start (i) and one at the end (j). If nums[i] + nums[j] is less than target, then all pairs between i and j are valid → add (j - i) to the count. Otherwise, move the right pointer left. This gives an O(n log n) solution due to sorting. #LeetCode #Java #DSA #TwoPointers #Sorting #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 87 Linked List Sorting & Node Rearrangement Linked List manipulation specifically, sorting a list that contains only 0s, 1s, and 2s. Problem: Given the head of a linked list containing only 0s, 1s, and 2s, rearrange the list so that all 0s appear first, followed by all 1s, and then all 2s. Example: Input: 1 → 2 → 2 → 1 → 0 → 2 Output: 0 → 1 → 1 → 2 → 2 → 2 Created three separate dummy linked lists to store 0s, 1s, and 2s. Traversed the original list once, linking each node to its respective list. Finally, merged all three lists in order (0s → 1s → 2s). Concepts Used: Linked List traversal Pointer manipulation Dummy node technique Time Complexity: O(N) Space Complexity: O(1) Efficient linked list problems often come down to clean pointer handling and a solid understanding of list connections no extra sorting needed! #takeUforward #100DaysOfCode #Java #LinkedList #GeeksForGeeks #ProblemSolving #DSA #CodingChallenge #CodeNewbie
To view or add a comment, sign in
-
-
🌳 Day 46 of #LeetCodeJourney Problem: 100. Same Tree ✅ Today’s challenge was about comparing two binary trees — checking if they’re structurally identical and have the same node values. A neat recursive problem that refreshes the basics of tree traversal and recursion! 💡 Key takeaway: If you can break a problem down into smaller identical subproblems — recursion will always have your back. #LeetCode #100DaysOfCode #Java #DSA #BinaryTree #Recursion #CodingJourney
To view or add a comment, sign in
-
-
🚀Day 88 – DSA in Java Solved “Hand of Straights” (LeetCode – Medium) Approach: ➡️ Sorted the array ➡️ Used HashMap to track frequencies ➡️ Formed consecutive groups of size k ➡️ Decremented counts as groups formed ⚡ Runtime: 24 ms (Beats 89.95%) 💾 Memory: 45.2 MB (Beats 89.4%) Explored how HashMap + sorting can simplify grouping problems and also learned about TreeMap for maintaining sorted order dynamically. #Day88 #LeetCode #Java #DSA #ProblemSolving #LearningEveryday
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
-
-
🚀 Day 7️⃣7️⃣ of #100DaysOfCode Solved LeetCode Problem #1437 — Check If All 1’s Are at Least K Places Away 🔍✨ 🔧 Concept: Given a binary array, ensure that every 1 is separated by at least K zeros. The solution simply tracks the previous index of 1 and checks the distance. 🧠 Key Idea: Scan the array once When a 1 is found, verify: 👉 currentIndex - previousIndex > k If any pair violates this, return false ⚡ Efficient: Time Complexity: O(n) Space Complexity: O(1) Another clean and efficient logical problem solved. #LeetCode #Java #Arrays #ProblemSolving #DSA #CodingJourney #100DaysOfCode #DeveloperLife #Motivation
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