💻 Daily Coding Practice – LeetCode 2788: Split Strings by Separator Today I solved a neat problem: 👉 Given an array of strings and a separator character, split each string by the separator and return all non-empty substrings in order. 🔹 Step-by-Step Approach (Manual Traversal) 1. Initialize an empty result list. 2. Loop through each string in the input list. 3. For each string: Track the start index of the current substring. Traverse each character. 4. If the character equals the separator → extract the substring from start to current index, add it if non-empty, and update start. 5. Otherwise, keep building the substring. 6. After finishing the string, add the last substring if non-empty. 7. Return the result list. This approach avoids regex overhead and gives precise control over empty substrings. ⚡ Complexity Analysis Time Complexity: Outer loop iterates over all strings → O(N) Inner loop iterates over all characters in each string → O(M) Substring operations across the string sum to O(M) Overall: O(N * M) Space Complexity: Result list stores all substrings → O(K) (where K is total substrings produced). Temporary variables use constant space. Overall: O(K) 🔑 Key Takeaways Manual traversal ensures correctness for tricky cases like consecutive separators or leading/trailing separators. Built-in split() is shorter but requires regex handling for special characters like | or $. Always filter out empty substrings to match problem requirements. 🚀 Solving problems like this daily strengthens my fundamentals and builds confidence in handling edge cases. #LeetCode #Java #ProblemSolving #DailyCodingChallenge #BackendDevelopment #LearningJourney💡
LeetCode 2788: Split Strings by Separator
More Relevant Posts
-
𝗟𝗼𝘄-𝗟𝗲𝘃𝗲𝗹 𝗗𝗲𝘀𝗶𝗴𝗻 𝗶𝘀𝗻’𝘁 𝗮𝗯𝗼𝘂𝘁 𝗢𝗢𝗣. 𝗜𝘁’𝘀 𝗮𝗯𝗼𝘂𝘁 𝗽𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲𝘀. A lot of people treat LLD as something tightly bound to: • classes • inheritance • design patterns • Java-style diagrams That’s a misunderstanding. LLD isn’t a language feature or a framework choice. 𝗜𝘁’𝘀 𝘁𝗵𝗲 𝗱𝗶𝘀𝗰𝗶𝗽𝗹𝗶𝗻𝗲 𝗼𝗳 𝗵𝗼𝘄 𝘆𝗼𝘂 𝘀𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲 𝗯𝗲𝗵𝗮𝘃𝗶𝗼𝗿 𝗮𝗻𝗱 𝗿𝗲𝘀𝗽𝗼𝗻𝘀𝗶𝗯𝗶𝗹𝗶𝘁𝗶𝗲𝘀. The same LLD principles apply to: • components (even fully functional ones) • plain functions • modules • services • APIs You can write terrible LLD with perfect OOP. And you can write clean, scalable LLD with zero classes. What actually matters: • clear responsibility boundaries • predictable data flow • low coupling, high cohesion • decisions that are easy to change later Those principles don’t care whether you’re using: • React hooks • Node services • Python functions • or a single class If your code is easy to reason about, easy to extend, and hard to misuse — that’s good low-level design. Everything else is just syntax. #lld #softwaredesign #engineering #cleanarchitecture
To view or add a comment, sign in
-
🚀 𝗢𝗢𝗣𝗦 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮 Object-Oriented Programming is built on 4 core principles 👇 1️⃣ 𝗜𝗻𝗵𝗲𝗿𝗶𝘁𝗮𝗻𝗰𝗲 → One class acquires properties of another → Promotes code reusability 2️⃣ 𝗘𝗻𝗰𝗮𝗽𝘀𝘂𝗹𝗮𝘁𝗶𝗼𝗻 → Binding data and methods together → Protects internal state of an object 3️⃣ 𝗣𝗼𝗹𝘆𝗺𝗼𝗿𝗽𝗵𝗶𝘀𝗺 → One interface, multiple implementations → Method overloading & overriding 4️⃣ 𝗔𝗯𝘀𝘁𝗿𝗮𝗰𝘁𝗶𝗼𝗻 → Hiding implementation details → Showing only essential features 📌 These 4 principles work together to make code: ✅ Modular ✅ Reusable ✅ Scalable ✅ Easy to maintain 🚀 𝗢𝗼𝗽𝘀 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 3 – 𝗣𝗼𝗹𝘆𝗺𝗼𝗿𝗽𝗵𝗶𝘀𝗺 Polymorphism allows objects to take many forms. It enables one interface to be used for different implementations. Let’s simplify it 👇 🔹 𝗖𝗼𝗺𝗽𝗶𝗹𝗲-𝗧𝗶𝗺𝗲 𝗣𝗼𝗹𝘆𝗺𝗼𝗿𝗽𝗵𝗶𝘀𝗺 (Method Overloading) Multiple methods with the same name but different parameters. ➡️ Decided at compile time. 🔹 𝗥𝘂𝗻-𝗧𝗶𝗺𝗲 𝗣𝗼𝗹𝘆𝗺𝗼𝗿𝗽𝗵𝗶𝘀𝗺 (Method Overriding) Subclass provides a specific implementation of a method already defined in parent class. ➡️ Decided at runtime using dynamic method dispatch. 🔹 𝗙𝗹𝗲𝘅𝗶𝗯𝗶𝗹𝗶𝘁𝘆 Same method call behaves differently based on object. ➡️ Makes systems extensible. 🔹 𝗕𝗲𝘁𝘁𝗲𝗿 𝗠𝗮𝗶𝗻𝘁𝗮𝗶𝗻𝗮𝗯𝗶𝗹𝗶𝘁𝘆 New implementations can be added without changing existing code. ➡️ Promotes scalability. 📌 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Polymorphism increases flexibility and extensibility by allowing one interface to support multiple behaviors. If you're preparing for Java interviews or strengthening your OOP fundamentals, mastering polymorphism is essential 💡 💬 What’s your favorite real-world example to explain polymorphism? #Java #OOP #Polymorphism #JavaDeveloper #Programming #SoftwareEngineering #InterviewPrep #LearningDaily
To view or add a comment, sign in
-
-
Many developers believe that complex conditional logic requires endless chains of if-else statements or clunky switch cases. This assumption often leads to brittle codebases, where a single missing logic branch can cause unpredictable runtime failures in production. We frequently accept this verbosity as a necessary trade-off of software engineering, but it actively hinders both readability and long-term maintainability. Functional languages like Haskell and OCaml treated this feature as a first-class citizen for decades before it finally migrated to the mainstream. We now see robust implementations in Rust with its match keyword and recently in Python 3.10 with structural pattern matching. This adoption curve proves that the industry recognizes the limitations of traditional control flow when dealing with complex data types. Adopting these modern features allows teams to write code that expresses intent much more clearly than legacy approaches. You no longer need to manually unpack variables or check types before acting on them because the language handles the structural validation for you. Consider a common scenario where you must handle an API response that might return a success payload, a distinct error code, or a loading state. In a traditional Java 8 environment, you would likely write a series of checks using instanceof casts that clutter the business logic with implementation details. Rust solves this elegantly by forcing you to handle every possible variant of an Enum at compile time through exhaustive matching. The power of pattern matching extends beyond simple value checking into deep structural decomposition of objects and arrays. You can look inside a complex JSON object to extract specific fields only when they match a precise nested structure. The transition from imperative branching to declarative matching requires a significant mental adjustment for developers raised on C-style syntax. You must stop thinking about how to manualy extract data and instead start defining what the data should look like for a valid operation. This move toward a declarative future allows the compiler to take on the cognitive load of ensuring logical completeness. Ultimately, you should ask yourself if your current codebase relies too heavily on archaic control structures that hide the true shape of your data. #SoftwareEngineering #RustLang #Python #Programming #CodeQuality #Refactoring #DevCommunity #TechDebt #FunctionalProgramming #SoftwareArchitecture
To view or add a comment, sign in
-
-
🚀 Day 2 of My Coding Practice! Solved another problem today on LeetCode – 1071. Greatest Common Divisor of String Problem Statement: Given two strings str1 and str2, return the largest string that divides both strings. Key Idea: If a string divides both strings, then: (str1 + str2) must be equal to (str2 + str1). Then the answer length will be: GCD(length of str1, length of str2) Algorithm Steps Input: String str1, String str2 Output: Largest common divisor string Algorithm: Check if (str1 + str2) equals (str2 + str1). If not equal → return empty string. Find gcd of lengths of str1 and str2. Return substring of str1 from 0 to gcd length. Example Walkthrough Input: str1 = "ABCABC" str2 = "ABC" Process: "ABCABCABC" == "ABCABCABC" ✔ GCD(6, 3) = 3 Output: "ABC" Pseudocode function gcdOfStrings(str1, str2): if (str1 + str2) ≠ (str2 + str1): return "" len1 = length of str1 len2 = length of str2 gcdLength = gcd(len1, len2) return substring of str1 from 0 to gcdLength 📌 Concepts Practiced: ✔ String concatenation logic ✔ Mathematical GCD ✔ Problem-solving approach Consistency over intensity 💪 #LeetCode #Java #ProblemSolving #Day2 #100DaysOfCode #BTech
To view or add a comment, sign in
-
-
Variable Naming Convention: Writing Code That Communicates Clearly A variable naming convention is a standardized approach to assigning meaningful, readable, and maintainable names to variables. Strong naming improves clarity, team collaboration, and long-term scalability of codebases. General Rules • Use descriptive names that reflect stored data. • Avoid single letters except loop counters (i, j). • Do not use spaces or special characters. • Do not start with numbers. • Avoid reserved keywords. • Maintain consistency across the project. Example student_age → clear sa → unclear Common Naming Styles snake_case (Common in Python) total_marks user_name is_logged_in camelCase (Common in JavaScript) totalMarks userName isLoggedIn PascalCase (Typically for Classes) StudentRecord UserProfile UPPER_CASE (Constants) MAX_SIZE API_KEY PI_VALUE Python Naming Convention — PEP 8 Variables student_name total_price file_path Boolean Variables is_active has_permission can_edit Private/Internal Variables _user_id _temp_data Meaningful Prefix Patterns Counter → count_students Flag/Boolean → is_valid List → students Dictionary → user_dict Good Naming total_students average_score customer_address Poor Naming t data1 valueTempX Domain-Focused Naming (Full-Stack / UI Development) api_response db_connection form_input_value grid_column_width Advanced Guidelines • Avoid redundant type hints in names. • Prefer semantic clarity over brevity. • Use singular for single items and plural for collections. • Maintain consistent terminology across modules. Clean naming is not style preference; it is architecture discipline. #Python #CodingStandards #CleanCode #Programming #SoftwareDevelopment
To view or add a comment, sign in
-
My most important language isn’t Java or Python. It’s "Business." The hardest part of Solution Architecture isn’t the code—it’s the communication. If you talk only about "tech," you get ignored. If you talk about "risk" and "revenue," you get budget. My Translation Guide: ❌ Don't say: "We need to refactor this legacy code because it's messy." ✅ Do say: "Cleaning this up now will speed up future feature delivery by 30%." ❌ Don't say: "We need a CI/CD pipeline." ✅ Do say: "We need to release features daily instead of monthly." As Architects, we have to be bilingual. If you can't translate architecture into business value, you aren't building solutions—you're just drawing diagrams. Call to Action: What’s the hardest concept you’ve had to explain to a non-techie? 👇 #SolutionArchitecture #SoftSkills #TechLeadership #Communication
To view or add a comment, sign in
-
-
Day 29 – Linked List in C++ | OOP Design: Pros & Trade-offs Today I worked on a singly linked list implemented using Object-Oriented Programming (OOP) in C++. The design uses two main classes: - Node → represents data + link - linkedList → manages creation, insertion, deletion, and traversal This approach clearly shows how OOP principles apply to data structures—but it also comes with trade-offs. ✅ Advantages of Using OOP Here 🔹 Encapsulation All list operations (insert, delete, display) are wrapped inside the linkedList class, preventing direct manipulation of pointers from main(). 🔹 Abstraction The user of the class doesn’t care how nodes are linked—only what operations are available. 🔹 Reusability & Maintainability The same class can be reused across projects, and changes (like adding search or reverse) stay localized. 🔹 Cleaner main() Business logic stays inside the class, making main() short and readable. ⚠️ Trade-offs / Limitations 🔸 Performance Overhead OOP adds function calls and object management overhead compared to a pure procedural approach—important in low-level or high-performance systems. 🔸 More Complex Debugging Pointer bugs (memory leaks, dangling pointers) become harder to trace when hidden behind class methods. 🔸 Destructor Responsibility Manual memory management in C++ means destructors must be written very carefully—one mistake can cause leaks or crashes. 🔸 Less Flexible for Algorithms For learning algorithms (like reversing or cycle detection), procedural implementations can be simpler and more transparent. 🧠 Key Takeaway 👉 OOP is great for structure, safety, and scalability 👉 Procedural style is sometimes better for learning core pointer logic A strong C++ developer knows when to use OOP—and when not to. #Day29 #CPlusPlus #LinkedList #OOP #DataStructures #MemoryManagement #ProgrammingJourney #DSA #CppDeveloper
To view or add a comment, sign in
-
-
🚀 𝗢𝗢𝗣𝗦 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮 Object-Oriented Programming is built on 4 core principles 👇 1️⃣ 𝗜𝗻𝗵𝗲𝗿𝗶𝘁𝗮𝗻𝗰𝗲 → One class acquires properties of another → Promotes code reusability 2️⃣ 𝗘𝗻𝗰𝗮𝗽𝘀𝘂𝗹𝗮𝘁𝗶𝗼𝗻 → Binding data and methods together → Protects internal state of an object 3️⃣ 𝗣𝗼𝗹𝘆𝗺𝗼𝗿𝗽𝗵𝗶𝘀𝗺 → One interface, multiple implementations → Method overloading & overriding 4️⃣ 𝗔𝗯𝘀𝘁𝗿𝗮𝗰𝘁𝗶𝗼𝗻 → Hiding implementation details → Showing only essential features 📌 These 4 principles work together to make code: ✅ Modular ✅ Reusable ✅ Scalable ✅ Easy to maintain 🚀 𝗢𝗼𝗽𝘀 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 𝟮 – 𝗘𝗻𝗰𝗮𝗽𝘀𝘂𝗹𝗮𝘁𝗶𝗼𝗻 Encapsulation is all about wrapping data and behavior together inside a class. It ensures controlled access and protects the integrity of your objects. Let’s simplify it 👇 🔹 𝗗𝗮𝘁𝗮 𝗛𝗶𝗱𝗶𝗻𝗴 Variables are declared as private to restrict direct access. ➡️ Prevents unauthorized modification. 🔹 𝗚𝗲𝘁𝘁𝗲𝗿 & 𝗦𝗲𝘁𝘁𝗲𝗿 𝗠𝗲𝘁𝗵𝗼𝗱𝘀 Public methods are used to access and update private data. ➡️ Provides controlled access. 🔹 𝗕𝗲𝘁𝘁𝗲𝗿 𝗖𝗼𝗻𝘁𝗿𝗼𝗹 You can add validation logic inside setters. ➡️ Ensures data consistency. 🔹 𝗜𝗺𝗽𝗿𝗼𝘃𝗲𝗱 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆 Internal implementation can change without affecting external code. ➡️ Enhances maintainability. 📌 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Encapsulation protects object integrity by restricting direct access and allowing modification only through well-defined methods. If you're preparing for Java interviews or strengthening your OOP fundamentals, mastering encapsulation is essential 💡 💬 What’s your favorite real-world example to explain encapsulation? #Java #OOP #Encapsulation #JavaDeveloper #Programming #SoftwareEngineering #InterviewPrep #LearningDaily
To view or add a comment, sign in
-
-
🚀 SOLID Design Principles: Simple Python Examples Every Developer Should Know Clean code → Scalable systems → Better architecture What is SOLID? SOLID = 5 principles for writing ✅ Maintainable ✅ Testable ✅ Scalable Object-Oriented code 1. S: Single Responsibility (SRP) One class = One responsibility ❌ Too much responsibility class UserService: def save_user(self): ... def send_email(self): ... ✅ Split responsibilities class UserRepository: ... class EmailService: ... 2. O: Open/Closed (OCP) Extend, don’t modify ❌ Condition-based logic if method == "card": ... ✅ Polymorphism class Payment: def pay(self): pass 3. L: Liskov Substitution (LSP) Child should replace parent safely ❌ Breaking behavior class Penguin(Bird): def fly(self): raise Exception() ✅ Correct abstraction class FlyingBird(Bird): ... 4. I: Interface Segregation (ISP) Don’t force unused methods ❌ Fat interface class Worker: def work(self): ... def eat(self): ... ✅ Small interfaces class Workable: ... class Eatable: ... 5. D: Dependency Inversion (DIP) Depend on abstractions ❌ Tight coupling self.db = MySQLDB() ✅ Loose coupling def __init__(self, db): self.db = db Why SOLID Matters ✔ Cleaner architecture ✔ Easier unit testing ✔ Faster feature changes ✔ Essential for senior & architect roles Final Takeaway 💡 SOLID is not about more code. It’s about writing the right code. #SOLID #Python #CleanCode #SystemDesign #SoftwareArchitecture #Developer #BestPractices
To view or add a comment, sign in
-
-
🚀 SOLID Principles Explained — With Real Backend Examples Ever opened a codebase and thought: 👉 “Why does changing one small feature touch 10 files… and still break tests?” That usually means one thing: SOLID principles were missing. I just published a detailed Medium article breaking down: ✅ What SOLID really means ✅ Each principle in simple language ✅ Real-world backend-style examples (Go / Java / Node) ✅ What goes wrong when you ignore them ✅ How they make systems easier to scale and test If you’re building microservices or large backend systems, this will give you practical clarity — not textbook theory. 📖 Read the full blog below: 👇 Would love to hear from fellow engineers: 💬 Which SOLID principle has helped you the most in production? #SoftwareEngineering #BackendDevelopment #SOLID #CleanCode #SystemDesign #Architecture #Microservices #Programming #GoLang #Java
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