Solved "Drawing Book" Problem Using Java 📖💻 | HackerRank Challenge Solved the Drawing Book (Page Count) problem from HackerRank using Java! This problem is a great example of optimization and logical thinking, where instead of simulating page turns, we calculate the minimum turns mathematically. 🔍 Key Concepts Used: Mathematical Optimization Integer Division Problem-Solving Approach 📌 Logic Summary: Count page turns from the front → p / 2 Count page turns from the back → (n / 2) - (p / 2) Return the minimum of both values 💡 This approach ensures O(1) time complexity, making it efficient and clean. Always improving problem-solving skills one challenge at a time 🚀 #Java #HackerRank #CodingChallenge #ProblemSolving #DSA
Solved Drawing Book Problem with Java on HackerRank
More Relevant Posts
-
💻 Today I practiced a simple but important Java problem reading input until End of File (EOF). The task is to take input line by line and print each line along with its line number. Since we don’t know how many lines the user will enter, we use hasNextLine() inside a loop to keep reading until the input ends. I used a counter starting from 1, read each line using nextLine(), and printed it with the line number. Then I incremented the counter for the next line. This problem looks basic, but it’s very useful in coding platforms like HackerRank where input is not fixed. It also helps in understanding how input streams work in Java. Small problems like this really help in building strong fundamentals. #Java #CodingPractice #InterviewPreparation
To view or add a comment, sign in
-
-
🚀 Exploring Method Overloading with Varargs in Java Today, I worked on an interesting Java problem that helped me strengthen my understanding of Compile-Time Polymorphism and Varargs (Variable Arguments). 🔹 Problem Statement: Design a VarargsCalculator class with overloaded methods to calculate the sum of: Multiple integers Multiple double values 🔹 Key Concepts Used: ✔ Method Overloading ✔ Varargs (int..., double...) ✔ Switch-case for dynamic method selection ✔ For-each loop for efficient iteration 🔹 Learning Outcome: This problem clearly demonstrates how Java allows the same method name to handle different types and number of inputs, depending on the parameters passed. It also shows how varargs simplify handling multiple inputs without explicitly creating arrays. 💡 Key Insight: Varargs in Java internally behave like arrays, making code more flexible and readable. 🔹 Sample Output: Sum of integers: 10 Sum of doubles: 7.0 📌 Practicing such problems is helping me improve my problem-solving skills and deepen my understanding of core Java concepts. #Java #CoreJava #MethodOverloading #Varargs #Programming #Coding #100DaysOfCode #DeveloperJourney #JavaDeveloper #LearningInPublic
To view or add a comment, sign in
-
-
Exploring one of the most powerful concepts in Java — Polymorphism, and I achieved it using Inheritance with a simple Plane program. In Java, polymorphism allows a single object to take multiple forms. Using inheritance and method overriding, I implemented a Plane example where different types of planes (like Cargo Plane and Passenger Plane) show different behaviors even though they share a common parent class. It was really interesting to see how a parent class reference can call different implementations at runtime — making the program dynamic and flexible. A big thank you to TAP Academy for teaching this concept so clearly and effortlessly. The real-time examples, like the Plane program, made it much easier to understand how inheritance and polymorphism work together. Excited to apply these concepts in real-world projects and keep growing 🚀 #Java #OOP #Polymorphism #Inheritance #CodingJourney #Learning #SoftwareDevelopment #TAPAcademy
To view or add a comment, sign in
-
Multithreading in Java finally clicked for me when I stopped memorizing it… and started visualizing it. 🧠 Here’s the simplest way to understand it: Imagine your application is doing only ONE task at a time. ➡️ Slow ➡️ Blocking ➡️ Poor performance Now introduce multithreading 👇 Multiple tasks run simultaneously: ✔ One thread handles API requests ✔ One processes data ✔ One writes logs Result? Faster and more efficient applications 🚀 But here’s what I learned the hard way: Multithreading is powerful… but dangerous if not handled properly. Common issues I faced: Race conditions Deadlocks Unexpected bugs What helped me: ✔ Proper synchronization ✔ Understanding thread lifecycle ✔ Using ExecutorService instead of manual threads Lesson: Multithreading is not just about speed — it’s about control and correctness. 💬 Have you faced any tricky bugs with multithreading? #Java #Multithreading #BackendDevelopment #SoftwareEngineering #Coding
To view or add a comment, sign in
-
Access modifiers in Java confused me more than inheritance at first. Not because they are complex — but because I didn’t understand where they actually matter. This diagram helped me connect the dots 👇 Here’s what finally made sense: • public → no restrictions • private → only inside the class • default → package-level access • protected → the tricky one → works like default → BUT also accessible through inheritance (even outside the package) Access modifiers are not just about visibility — they define how safely and cleanly your code interacts across packages. That’s where Java moves from syntax → design. Grateful to TAP Academy and Harshit T sir for breaking this down clearly Which modifier took you the longest to understand? #Java #OOP #AccessModifiers #SoftwareDevelopment #LearningJourney
To view or add a comment, sign in
-
-
Solved Simple Array Sum using LinkedList in Java 8 💻📊 Today I worked on the Simple Array Sum problem and implemented it using LinkedList in Java 8. 💡 What I learned: How to convert a List into a LinkedList Traversing elements efficiently using loops Using Java 8 Streams for cleaner and shorter code ⚙️ Approach: Converted input list into a LinkedList Iterated through elements and calculated sum Also explored stream().mapToInt().sum() for optimized solution 📌 Key Takeaway: Even simple problems help strengthen core concepts like data structures and improve coding efficiency. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) 👨💻 Consistent practice is helping me improve my problem-solving skills step by step. #Java #Java8 #LinkedList #Coding #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Exploring Java Collection Framework Today’s session was all about understanding the powerful Java Collection Framework and how it helps in managing and organizing data efficiently. Dived deep into core concepts like interfaces and classes in collections, and explored the three main interfaces: List, Set, and Map. Gained clarity on how these structures differ and where to use them in real-world applications. Focused on the ArrayList class—its properties like dynamic resizing, ordered storage, and index-based access—making it one of the most commonly used collection classes in Java. Also understood the hierarchy of ArrayList, how it is part of the List interface, and how it inherits behavior from abstract classes like AbstractList and AbstractCollection. 📚 A strong foundation in collections is essential for writing efficient and scalable Java applications. TAP Academy #Java #CollectionsFramework #ArrayList #Programming #LearningJourney #FullStackDevelopment
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 31 Today I solved a Medium-level Linked List problem that strengthened my understanding of Two Pointers + Reversal Technique — a powerful combination for interviews 📌 LeetCode Problem Solved: Q.2130. Maximum Twin Sum of a Linked List 💭 Problem Summary: In an even-length linked list, each node has a "twin" from the opposite end. The goal is to find the maximum sum of such twin pairs. 🧠 Approach (Optimal): Instead of using extra space, I used an efficient approach: ✔️ Found the middle using slow & fast pointers ✔️ Reversed the second half of the list ✔️ Compared both halves to calculate twin sums ⚡ Key Learning: Reversing part of a linked list can help reduce space complexity from O(n) → O(1), which is crucial for optimization 🚀 ⏱️ Complexity: Time: O(n) Space: O(1) 🔥 Takeaway: This problem shows how combining simple techniques like two pointers + reversal can solve complex problems efficiently. Consistency is the key — showing up every day #Day31 #LeetCode #Java #LinkedList #DSA #CodingJourney #SoftwareEngineering #InterviewPrep #100DaysOfCode #CDAC #AndroidDeveloper
To view or add a comment, sign in
-
-
💻 Day 23 – Strings in Java Today I explored Strings in Java, one of the most fundamental and important concepts. I learned about different types of string handling: 🔹 String – Immutable (cannot be changed) 🔹 StringBuilder – Mutable and faster 🔹 StringBuffer – Mutable and thread-safe Understanding immutability was a key highlight today, as it plays an important role in memory management and performance. 💡 Key takeaway: Choosing the right type of string handling improves both performance and efficiency in Java applications. Continuing to strengthen my core Java concepts step by step 🚀 #Java #Strings #Programming #LearningInPublic #CodingJourney #Day23
To view or add a comment, sign in
-
-
🔥 Title Solved "Library Fine" Problem Using Java 📚💻 📄 Description I recently worked on the Library Fine problem, a great exercise to strengthen conditional logic and real-world problem-solving. 🔍 Problem Summary: Calculate the fine for returning a library book late based on: Days late Months late Years late 💡 Approach: Compare return date with due date Apply fine rules based on hierarchy (year → month → day) Ensure minimum penalty logic is followed ✨ Key Learning: Breaking down conditions step-by-step helps avoid logical errors and improves clarity in coding. ⚡ Implemented in Java with simple and efficient conditional checks. 🏷️ Tags #Java #DSA #Coding #ProblemSolving #HackerRank
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