Day 20 | Programming Classes at TAP Academy 🔄 Rearrange Arrays💥 💡 The Problem Given an array with positive numbers and -1s: 👉 Move all -1s to the beginning 👉 Keep it efficient (no extra space, no unnecessary loops) 🚨 Where most people go wrong Create a new array ❌ Traverse twice ❌ Focus on output, not efficiency ❌ That works… but ⚡ The Smarter Approach — Two Pointers Use two pointers (i, j) Traverse from the end Place non -1 elements correctly Fill remaining positions with -1 🧠 Core Idea If element is -1 → skip Else → move it to position j Reduce pointers Fill leftover indices with -1 💻 Code public static void rearrange(int[] arr) { int i = arr.length - 1; int j = arr.length - 1; while (i >= 0) { if (arr[i] == -1) { i--; } else { arr[j] = arr[i]; i--; j--; } } while (j >= 0) { arr[j] = -1; j--; } } 🔁 Same Pattern, Different Problem 👉 Move all 0s to the end public static void moveZeros(int[] arr) { int i = 0, j = 0; while (i < arr.length) { if (arr[i] == 0) { i++; } else { arr[j] = arr[i]; i++; j++; } } while (j < arr.length) { arr[j] = 0; j++; } } 🧠 What this really teaches This isn’t just arrays. It’s about: ✔️ Thinking before coding ✔️ Writing optimal logic ✔️ Understanding how data actually moves Also connects to a key concept: 👉 Arrays in Java are passed by reference, so changes reflect directly. #Java #DSA #ProblemSolving #InterviewPrep #Learning #Developers #Programming #Arrays #CoreJava #Upskilling #Coding #DSA #Problem #Thinking #TAPAcademy #Logics #Optimal
Rearrange Arrays Efficiently with Two Pointers in Java
More Relevant Posts
-
Day 24 | Programming Classes at TAP Academy 🚨 Handling Extra Spaces in Strings 💡 1. Trim spaces from start and end only (without using .trim()) Traverse from left -> find first non-space -> start Traverse from right -> find first non-space -> end Loop between start and end ⚡ 2. “Remove extra spaces” is NOT “remove all spaces” Input: " how are you " Expected: "how are you" Not: "howareyou" 🔥 Core logic: Keep all characters Allow only one space between words Condition that matters: if (s.charAt(i) != ' ' || (s.charAt(i) == ' ' && s.charAt(i+1) != ' ')) 👉 That single condition = 80% of the problem solved. 🧠 3. Operators are silent killers || ->stops early (short-circuit) && -> stops early That’s why this doesn’t crash: s.charAt(i+1) Because sometimes Java never even checks it. 🔥 4. “NOT of vowel = consonant” ❌ (Big trap) Most common mistake: if (!(ch == 'a' || ch == 'e' ...)) Looks correct. It’s not. Why? Because: 👉 Character can be: Alphabet Number Special character So NOT vowel ≠ consonant ✅ Correct thinking: Check if alphabet Then check if NOT vowel THEN it’s consonant 🚀 5. Pattern mindset > Code memorization Example: 👉 Print * before every ‘a’ in "banana" Output: b*a n*a n*a Logic: Traverse If 'a' -> add "*a" Else -> normal char 👉 Every string problem = pattern + condition + traversal #Java #Strings #Programming #CoreJava #TAPAcademy #Upskilling #LearnByDoing #CodingMindset #DeveloperMindset #LogicOverSyntax #Learning #ProblemSolving #DSA #Logics #Problems #Learning #SoftwareDevelopment #Coding #CodingJourney #CodingPractice #LogicBuilding #ThinkLikeAProgrammer
To view or add a comment, sign in
-
-
Day 25 | Programming Classes at TAP Academy Strings Subsequences ✨ 🔍 Problem 1: Find the Index of a Character in a String Given a string S and a character K, find the index of K. 💡 Core logic: Traverse the string Compare each character using == Return index immediately when found If not found -> return -1 👉 Sounds basic… but execution exposed gaps. ⚠️ Big Reality Check The logic is literally the same as “index of element in array” — just applied to strings. 🧠 Hidden Trap: Taking Character Input in Java Most common mistake: Trying scanner.nextChar() ❌ (doesn’t exist) ✔️ Correct way: Take input as string Extract first character using .charAt(0) This tiny detail broke a lot of code. 🔁 Problem 2: Last Index of Character Same logic. Just reverse traversal. Start from length - 1 Move backwards Return first match Simple twist. Same foundation. 🔗 Problem 3: Subsequence Check Now things got interesting. 👉 Given two strings S and T, check if T is a subsequence of S. Meaning: All characters of T must appear in S Order must be maintained They don’t need to be continuous Example: S = "hereiamstackerrank" T = "hackerrank" → ✅ YES 💡 Approach Use two pointers: i -> for string S j -> for string T Logic: If characters match -> move both i++, j++ If not -> move only i++ Continue until end Final check: If j == T.length() → YES Else → NO 🧩 Bonus Concept: Loop Understanding Quick reminder that hit hard: while loop -> runs only if condition is true do-while loop -> runs at least once no matter what Understanding this difference = avoiding silent logical bugs. #Programming #Java #DSA #LearningJourney #CodingLife #ProblemSolving #TechGrowth #Software #Development #TAPAcademy #Upskilling #Logics #Strings #DSA #Coding #Problems #Logics #Syntax #CoreJava #Loops #Subsequence #Index #Learning
To view or add a comment, sign in
-
-
🚀 Exciting News for V Programming Enthusiasts! 🚀 I'm thrilled to announce a brand-new module in my Udemy course, Learn V Programming! 🎉 Introducing "Handling JSON using Vlang"—a comprehensive guide to mastering JSON manipulation in Vlang. This module is designed to enhance your skills in working with JSON data, a vital aspect of modern programming. Here's what you'll learn in this module: 1️⃣ Encoding and Decoding JSON Data: Seamlessly convert data to and from JSON formats. 2️⃣ Working with json and json2 Modules: Learn the ins and outs of Vlang's powerful JSON handling libraries. 3️⃣ Decoding JSON Responses from the Web: Handle real-world scenarios by decoding JSON responses from APIs and web services. If you’re eager to level up your V programming skills and gain hands-on experience with JSON, this module is perfect for you. 🎯 Enroll now and start your journey today: https://lnkd.in/dFquAqbC Let’s code the future together! 💻✨ #vlang #vprogramming #learnvprogramming #programming #programminglanguage #technology #newhire #ITprofessional #ITskills
To view or add a comment, sign in
-
Why I Created Coding Made Simple As I progressed in learning to code, I realised how quickly things can start to feel overwhelming — especially when concepts begin to stack on top of each other. Not because the concepts are impossible, but because they’re unfamiliar, and they don’t always click straight away. I’d sometimes catch myself thinking while practising: “This feels a bit high level… I’m not sure I fully get it yet.” And honestly? That’s completely normal. Learning anything new takes time, clarity, and explanations that meet you exactly where you are — not where you’re “supposed” to be. Although things eventually start to make sense — especially with the support around you, whether that’s peers, mentors, or your learning community — those early stages, when you’re absorbing so much at once, can still feel like a lot. If you’ve ever felt that way, you’re not alone. You’re not behind. You’re simply learning. That’s exactly why I created Coding Made Simple. It’s the guide I wish I had earlier — something that: • breaks down programming concepts in plain English • focuses on the why behind the code • includes real‑world, practical examples • helps you build confidence step by step If you’re at the start of your coding journey and things feel a little overwhelming, this was made with you in mind. 👉 Check it out on Payhip: https://lnkd.in/e2iWbz_2 Or on Gumroad: 👉https://lnkd.in/eNCwfmHT Happy coding! #CodingJourney #LearningToCode #ProgrammingBasics #SoftwareDevelopment #BeginnerCoder #CodeNewbie #CodingMadeSimple #WomenWhoCode
To view or add a comment, sign in
-
Day 2 of placement training with Tap Academy focused on strengthening our core programming skills. Today’s session was all about: Understanding loops in Java (for, while, do-while) Building logic through pattern problems Improving problem-solving and coding approach Pattern problems really push you to think differently and sharpen your logic step by step. A solid foundation in loops makes everything in programming much easier moving forward. Appreciate the continuous guidance from our mentor, Poovizhi VP, for making the session interactive and easy to follow. Excited to keep learning and improving every day. #Java #Programming #Coding #Loops #ProblemSolving #TechSkills #LearningJourney #Engineering #PlacementPreparation #TapAcademy #StudentLife #FutureReady
To view or add a comment, sign in
-
-
✨ LEARNING TAP Academy One of the fundamental pillars of Object-Oriented Programming (OOPS) is ABSTRACTION. 🔹 What is Abstraction? Abstraction is the concept of hiding implementation details and showing only the essential features of an object. 🔹 Abstract Class An abstract class is a restricted class that cannot be used to create objects. It acts as a blueprint for other classes. 🔹 Abstract Method An abstract method contains only the method signature (declaration) and no body (implementation). 💡 Key Points to Remember: ✔ An abstract class can inherit from another abstract class ✔ An abstract class can also inherit from a normal class ✔ A normal class can inherit from an abstract class ✔ An abstract class can have both abstract methods and concrete (normal) methods ✔ abstract and final keywords cannot be used together 💻 Example Program (Java): abstract class Animal { abstract void sound(); // abstract method void eat() { // concrete method System.out.println("Animal eats food"); } } class Dog extends Animal { void sound() { System.out.println("Dog barks"); } } public class Main { public static void main(String[] args) { // Animal a = new Animal(); ❌ Not allowed Dog d = new Dog(); d.sound(); d.eat(); } } 📌 Output: Dog barks Animal eats food ✨ Understanding abstraction helps you write cleaner, more secure, and maintainable code by focusing only on what is necessary. #Java #OOPS #Abstraction #Programming #TapAcademy #Learning #Coding
To view or add a comment, sign in
-
-
🚀 Learning Progress: Java OOP – Inheritance Continuing my journey in mastering Object-Oriented Programming in Java, I implemented a program to demonstrate Inheritance. In this program, I created a base class Plane with common behaviors like: Taking off Flying Landing Then, I extended this class into specialized subclasses such as CargoPlane, PassengerPlane, and FighterPlane, where each class adds its own specific functionality like carrying goods, passengers, or weapons. This hands-on implementation helped me understand how: Code reusability is achieved using inheritance Common methods can be written once in the parent class and reused by child classes Subclasses can extend and customize behavior based on requirements It was interesting to see how Java enforces a clear and structured approach to inheritance, making the program more organized and scalable. A special thanks to TAP Academy for teaching these concepts so effortlessly and making learning OOP both clear and practical. Looking forward to exploring more advanced OOP concepts! #Java #OOP #Inheritance #LearningJourney #Programming #SoftwareDevelopment #TAPAcademy
To view or add a comment, sign in
-
I’m happy to share that my Java learning through the W3Schools platform. Today’s learning focused on one of the most important concepts in programming — loops, which help in executing a block of code repeatedly. From the slide, I learned about different types of loops in Java: • while loop – Executes a block of code as long as the given condition is true. • do-while loop – Similar to the while loop, but it executes the code at least once before checking the condition. I also understood how loops help in reducing code repetition and making programs more efficient. Practicing these loops gave me a clear idea of how to control the flow of execution in a program. This session helped me strengthen my understanding of iteration and control flow, which are essential for solving real-world programming problems. #Java #Programming #LearningJourney #SoftwareDevelopment #StudentDeveloper #W3Schools
To view or add a comment, sign in
-
When I started learning programming, I was mainly focused on writing functions and making things work. But after getting introduced to Object-Oriented Programming (OOP), my way of thinking started to change. Instead of only asking "what should the program do?", I began asking "who should be responsible for doing it?" Even with the basics like classes and constructors, I can already see how OOP helps in organizing code and making it easier to understand and maintain. I’m still at the beginning of my journey, but I’m starting to realize that programming is not just about writing code — it’s about thinking in a more structured and logical way. #programming #dart #flutter #learningjourney #mobileApplications
To view or add a comment, sign in
Explore related topics
- Approaches to Array Problem Solving for Coding Interviews
- Java Coding Interview Best Practices
- Tips for Coding Interview Preparation
- Tips for Real-World Problem-Solving in Interviews
- How to Use Arrays in Software Development
- Strategies for Solving Algorithmic Problems
- Common Algorithms for Coding Interviews
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