#100DaysOfCode – Day 74 Count and Say Problem: Given an integer n, return the n-th term of the “Count and Say” sequence a fascinating pattern where each term describes the previous one. Example: Input: n = 4 Output: "1211" My Approach: Used recursion to generate the previous term. Applied run-length encoding logic counted consecutive digits and built the next term using a StringBuilder. Optimized for clean, readable iteration with O(N²) complexity (due to string building). Understanding recursive string construction deepens how we visualize “generation-based” sequences it’s not just about coding, it’s about seeing patterns grow. #100DaysOfCode #Java #LeetCode #ProblemSolving #Recursion #StringManipulation #CodingJourney #TechWithPurpose #takeUforward
"Count and Say sequence using recursion and string manipulation"
More Relevant Posts
-
💡 Mastering Array Rotation — LeetCode #189 Today, I solved an interesting array manipulation problem: Rotate Array — a classic coding interview question that tests both problem-solving and optimization skills. 🧩 Problem Statement Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. ⚙️ Intuitive Approach Rotating an array means shifting elements circularly to the right. A naïve approach would use extra space, but the optimal solution performs it in-place using array reversal. Step-by-Step Logic -> Reverse the entire array -> Reverse the first k elements -> Reverse the remaining n - k elements ⏱️ Complexity Analysis Time Complexity: O(n) Space Complexity: O(1) In-place Rotation: ✅ #LeetCode #Java #DSA #CodingChallenge #ProblemSolving #Arrays #InPlaceAlgorithm #DataStructures #LearningEveryday
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 69 String Manipulation Task: Find the longest common prefix among an array of strings. Example: Input: ["flower", "flow", "flight"] → Output: "fl" My Approach: Took the first string as the initial prefix. Iterated through each subsequent string. Trimmed the prefix until it matched the start of each word. Time Complexity: O(N × M) (where N = number of strings, M = average string length) String problems are all about observation understanding patterns, boundaries, and when to stop iterating. A few lines of logic can make a big difference in performance and clarity! #takeUforward #100DaysOfCode #Java #LeetCode #ProblemSolving #StringManipulation #CodingJourney #GeeksForGeeks #CodeNewbie #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🌳 Day 21 of #100DaysOfLeetCode – Unique Binary Search Trees 🌳 Today’s challenge was all about counting how many structurally unique BSTs can be formed using n distinct numbers. 🧮 This problem beautifully blends dynamic programming and combinatorial logic — where the number of unique trees for each n depends on the possible root positions and their left/right subtree combinations. ⚙️ 💡 Key takeaway: Dynamic programming helps in reusing subproblem results efficiently — making even complex recursive patterns simpler and faster! 🚀 #LeetCode #100DaysChallenge #BinarySearchTree #DynamicProgramming #ProblemSolving #CodingJourney #Java #DataStructures
To view or add a comment, sign in
-
-
📅 Day 81 of #100DaysOfLeetCode Problem: Insert into a Binary Search Tree (LeetCode #701) Approach: The task is to insert a new node with a given value into a Binary Search Tree (BST). Start from the root and recursively find the correct position: If the new value is smaller than the current node’s value, go to the left subtree. Otherwise, go to the right subtree. When a null spot is found, insert a new node there. The BST property is preserved throughout this process. Complexity: ⏱️ Time: O(h) — where h is the height of the tree. 💾 Space: O(h) — recursive call stack. 🔗 Problem Link: https://lnkd.in/dCS7zxVG 🔗 Solution Link: https://lnkd.in/dxB4ZNtV #LeetCode #100DaysOfCode #BinarySearchTree #Recursion #Java #TreeTraversal #DSA #Algorithms #CodingChallenge #ProblemSolving #CodeNewbie #StudyWithMe #BuildInPublic #LearnToCode #DailyCoding
To view or add a comment, sign in
-
-
🚀 Day 63 of My LeetCode journey 🚀 Problem : Custom Sort String Today’s problem was interesting because instead of sorting using normal alphabetical order, we sort the given string based on a custom priority order. 🧠 Problem Understanding Given: order → defines priority of characters. str → the input string which needs to be rearranged. Goal: ✅ Arrange characters of str based on the sequence defined in order. ✅ Characters not present in order should appear at the end (any order). 💡 Approach (Simple & Efficient) Count frequency of each character in str. First append characters following the order. Then append remaining characters. Time Complexity: O(n) Space Complexity: O(1) (fixed array size for 26 letters) ✨ Learnings Sometimes the problem isn't about sorting, but about following a custom priority. Frequency counting is extremely powerful for character-based problems. StringBuilder → best way to build strings efficiently in Java. #leetcode #coding #dsa #java #100DaysOfCode #day63 #learningEveryday #problemSolving
To view or add a comment, sign in
-
-
🚀 115 days of #200DaysOfCode Problem: 24. Swap Nodes in Pairs Problem Statement: Given the head of a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes, only nodes themselves may be changed. Approach: Used a dummy node and iteratively swapped each adjacent node pair via pointer manipulation, which enabled in-place node swaps without extra space. Logic: Leveraged pointer rewiring to achieve the swaps efficiently with O(1) extra space and O(n) time complexity, cleanly iterating through the list to handle both even and odd-length cases. 👉 Question link 🔗: https://lnkd.in/g6cwvMgz #LeetCode #Java #LinkedList #Pointers #DSA #Coding #Algorithms #InterviewPrep #200DaysOfCode
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 81 Linked List Cycle Problem Given the head of a linked list, determine whether the list contains a cycle meaning a node’s next pointer refers back to a previous node. My Approach Used Floyd’s Cycle Detection Algorithm (Tortoise & Hare Method): Initialized two pointers slow and fast. Moved slow one step and fast two steps in each iteration. If they ever meet → cycle detected. If fast or fast.next becomes null → no cycle exists. Complexity Time: O(n) Space: O(1) Even in problems involving dynamic structures like linked lists, a simple pointer-based approach can lead to an elegant and optimal solution. #100DaysOfCode #LeetCode #Java #ProblemSolving #DataStructures #LinkedList #TortoiseAndHare #takeUforward #CodeNewbie #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 77/100 of #100DaysOfLeetCode Today I solved Binary Search (LeetCode Problem 704), a classic algorithmic challenge and an important concept for efficient searching. The task was to determine the index of a target value in a sorted array using an algorithm with O(log n) time complexity. If the target exists, return its index; otherwise return -1. 💡 Key Takeaway: Binary search is a fundamental algorithm that helps build strong problem-solving intuition and improves understanding of time complexity. #100DaysOfCode #LeetCode #CodingJourney #Java #DSA #BinarySearch #KeepLearning #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 62/100 of #100DaysOfLeetCode Today’s challenge was “Happy Number” (LeetCode Problem 202). The task was to determine whether a given number is a Happy Number — meaning that by repeatedly replacing the number with the sum of the squares of its digits, the process eventually reaches 1. 💡 Key Takeaways: Strengthened understanding of pointer movement logic. Improved implementation skills using mathematical and logical thinking in Java. #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 56 of my #100DaysOfLeetCode Challenge 🚀 Today's problem: Matrix Diagonal Sum Language: Java In this challenge, I practiced calculating the sum of both primary and secondary diagonals of a square matrix. The goal was to improve my understanding of nested loops and conditional logic for index-based problems. Key Takeaways: Strengthened logic for 2D array traversal Improved debugging and edge case handling Reinforced clean, readable code habits Here’s the core idea from my solution: If i == j (primary diagonal) or i + j == n - 1 (secondary diagonal), add that element to the sum. #LeetCode #Java #CodingChallenge #100DaysOfCode #ProblemSolving #SoftwareEngineering
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