🚀 Day 111 of #160DaysOfCode ✅ Topic: Dynamic Programming — Longest String Chain 💡 Platform: GeeksforGeeks (Problem: Longest String Chain) 🧠 Concept Learned: Today I solved the Longest String Chain problem using Dynamic Programming. The goal was to find the longest sequence of words where each word can be formed by adding exactly one letter to the previous word, without changing the order of characters. 📘 Approach Used: Sort all words by length (shorter first). Use a dictionary (dp) to store the longest chain ending at each word. For each word, generate all possible predecessors by removing one character at a time. If the predecessor exists in dp, update: dp[word] = max(dp[word], dp[pred] + 1) Keep track of the maximum chain length in res. 🧩 Example: Input: ["a", "b", "ba", "bca", "bda", "bdca"] Output: 4 Explanation: The longest chain is a → ba → bda → bdca ✅ Result: All test cases passed (1114 / 1114) 🎯 Understood how sorting + dynamic programming + string manipulation can be combined to solve complex sequence problems efficiently.
Solved Longest String Chain problem using DP on GeeksforGeeks
More Relevant Posts
-
Made my own programming language in C++ and it’s called Rivet. It includes: > A Lexer (tokenizer) > A Recursive Descent Parser > An Abstract Syntax Tree (AST) > An Interpreter that executes AST nodes directly Features: > Variables (let and var for immutability/mutability) > Numbers, Booleans, Strings, and Arrays > Arithmetic and logical expressions (+ - * / && ||) > If / Else conditionals > While loops > C-style For loops (for (var i = 0; i < 10; i = i + 1)) > For-in loops for arrays and strings (for x in arr { ... }) > Functions and return values > Print statement > Nested scopes and lexical environments Took a day of lexer-parser pain and “why won’t this semicolon die” moments but now it runs its own code and I’m unreasonably proud of it. Check it out link in the comments!
To view or add a comment, sign in
-
-
🔵 C Pointers Deep Dive – Understanding Pointer to Pointer (Double Pointer) in Action 🔵 Today, I revisited a core yet often misunderstood concept in C programming: Pointer to Pointer (or double pointer) — a feature that gives us the power to indirectly access and manipulate data at multiple memory levels. 🧠 What I did: 🔸 Wrote a simple C program demonstrating how int **q can be used to indirectly modify a variable through another pointer. 🔸 Used the dereference operator (*) twice to understand how data is accessed and updated via multiple levels of indirection. 🔸 Observed how changes made through **q reflect directly in the original variable. 🔍 Step-by-step breakdown: 1️⃣ int a = 10; → a simple integer variable. 2️⃣ int *p = &a; → p stores the address of a, making it a pointer to a. 3️⃣ int **q = &p; → q stores the address of pointer p, making it a pointer to a pointer. 4️⃣ **q = **q + 1; → dereferencing twice means we’re actually modifying the value of a indirectly — incrementing it by 1. 5️⃣ printf("%d", a); → outputs 11. 🛠 Why this matters: 🔸 Double pointers are essential for dynamic memory management, multidimensional arrays, and function pointers. 🔸 They provide deeper control over data structures like linked lists, trees, and graphs. 🔸 Understanding pointer indirection helps in writing efficient, memory-safe, and maintainable low-level code. 📌 Key Takeaway: 👉 Pointers to pointers amplify flexibility — allowing manipulation of variables, arrays, or even function addresses indirectly. 👉 Always ensure pointer initialization and dereferencing safety to avoid undefined behavior. 👉 Mastering this concept is a stepping stone toward mastering memory management in C. 🚀 Next up: 🔹 Exploring triple pointers in advanced data structures 🔹 Using double pointers for dynamic 2D arrays 🔹 Practical debugging of pointer issues with tools like Valgrind #CProgramming #Pointers #MemoryManagement #LowLevelProgramming #EmbeddedC #SystemsProgramming #CDeveloper #SoftwareEngineering #CodeTips #ProgrammingConcepts #DeveloperJourney #ComputerScience #CodingCommunity #LearningInPublic
To view or add a comment, sign in
-
-
Ideas for a programming language, like Rust but a scope transient thing, like set a memory location at the thread level or global only once and have many things allowed to access, like not creating references and copying, just access the different scopes of originals and scope delete like Rust when the scope ends. Also like accessing more to the outer and inner. I at least want reusable code like a function that does not create a reference every call. Like if you were to make a monolith function that only uses inside variables only but with functions and reuse. What do you think? Still memory safe if done right. X E.
To view or add a comment, sign in
-
1526. Minimum Number of Increments on Subarrays to Form a Target Array 1526. Minimum Number of Increments on Subarrays to Form a Target Array Difficulty: Hard Topics: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack, Biweekly Contest 31 You are given an integer array target. You have an integer array initial of the same size as target with all elements initially zeros. In one operation you can choose any subarray from initial and increment each value by one. Return the minimum number of operations to form a target array from initial. The test cases are generated so that the answer fits in a 32-bit integer. Example 1: Input: target = [1,2,3,2,1] Output: 3 Explanation: We need at least 3 operations to form the target array from the initial array. [0,0,0,0,0] increment 1 from index 0 to 4 (inclusive). [1,1,1,1,1] increment 1 from index 1 to 3 (inclusive). [1,2,2,2,1] increment 1 at index 2. [1,2,3,2,1] target array is formed. Example 2: Input: target = [3,1,1,2] Output: 4 Explanation: [0,0,0,0] -> [1,1,1,1] -> [1,1,1,2] -> [2,1,1,2] -> [3,1,1,2] https://lnkd.in/geCSn5Fq
To view or add a comment, sign in
-
🚀 Understanding Data Types in C Programming In C programming, data types define the type of data a variable can hold. They help the compiler understand how much memory to allocate and what kind of operations can be performed on the data. 🧩 Main Categories: Primary Data Types – int, float, char, double Derived Data Types – array, pointer, structure, union Enumeration Data Type (enum) Void Type – represents no value 💡 Example: int age = 25; // Integer type float salary = 50000; // Floating-point type char grade = 'A'; // Character type Each data type plays a crucial role in writing efficient, type-safe, and memory-optimized C programs. If you understand data types well, you understand half of C programming! #CProgramming #CodingBasics #ProgrammingTips #LearnToCode #DataTypes #SoftwareDevelopment #TechLearning #CodeWithC #BeginnersGuide #CProgrammer
To view or add a comment, sign in
-
-
Functions vs Methods in Programming Function: standalone lines of code 👩💻 to perform certain task independently without an associated object. You can directly call ☎️ a function, pass arguments if required and it operates on the data. Method: is a function that is associated to an object or a class in object oriented programming (OOP). Methods are called on objevt using dot notation: object.method() -> the method have access to the data associated with the instance of the object invoked during the runtime🏃♂️ Key 🔐 Differences: 🎯Function are independent and can be called by their name anywhere. 🎯Methods are always associated with an object and are called using objects. 🎯Methods are specific and internal to objects, however functions are general-purpose. picture: https://lnkd.in/d9C5Rs6s
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