💻✨ Just revisited one of my favorite Java exercises—building a diamond pattern using nested loops! It’s a simple yet elegant way to practice control flow and logic structuring. For input 3, the output looks like this: * *** ***** *** * This kind of pattern generation sharpens your understanding of loop nesting and space management in console output. If you're learning Java or prepping for interviews, try writing this from scratch—no copy-paste! 😄 🔍 Curious to see how others would optimize or extend this? Drop your version or ideas in the comments! #Java #CodingPractice #PatternPrinting #DeveloperJourney #100DaysOfCode #LinkedInLearning
Java exercise: Building a diamond pattern with nested loops
More Relevant Posts
-
Today I worked on the problem "Convert Sorted List to Binary Search Tree" in Java — a perfect blend of Linked List and Tree logic! 🌳 🔍 Key Concepts Covered: Finding the middle element of a Linked List using the slow & fast pointer approach Recursively constructing a height-balanced BST Strengthening understanding of Divide and Conquer strategies This problem really sharpened my thinking around recursive structures and pointer management — small yet powerful steps toward writing more efficient and elegant Java code. 💻✨ 💬 What’s your favorite data structure to work with — Linked Lists or Trees? #LeetCode #Java #DataStructures #Algorithms #CodingJourney #LearningEveryday #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 4 of My DSA with Java Journey 📘 Problem: Square of a Sorted Array 🧩 Topic: Two Pointers 💻 Language: Java ⚙️ Approach: Two Pointer Technique (O(n)) 🔍 What I Learned: Handling both negative and positive numbers while keeping the array sorted after squaring — optimized using two pointers instead of sorting after squaring. ✨ Key Takeaway: Think in terms of pointers and comparisons, not just brute force — that’s how optimization begins. #Java #DSA #LeetCode #TwoPointers #CodingJourney #100DaysOfCode #PlacementPrep #LearnInPublic #CodingCommunity #JavaDeveloper
To view or add a comment, sign in
-
-
Extract a character from a string To get a character from a string in Java, you can use the charAt() method of the String class. This method takes an index as an argument and returns the character at that position (0-based index). Here's a simple Java program to demonstrate this: Code : public class GetCharacterFromString { public static void main(String[] args) { String str = "Hello, World!"; int index = 7; // Index of the character to retrieve (0-based) // Get the character at the specified index char ch = str.charAt(index); // Print the character System.out.println("Character at index " + index + " is: " + ch); } } Can anyone guess the output ?. #JavaProgramming #JavaCode #Coding #ProgrammingTips #LearnJava #JavaDevelopment #CodeSnippet #SoftwareDevelopment #TechTips #100DaysOfCode
To view or add a comment, sign in
-
Day 28/100 – #100DaysOfCode 🚀 | #Java #LeetCode #DynamicProgramming ✅ Problem Solved: Scramble String 🔀 🧩 Problem Summary: Given two strings s1 and s2, determine whether one is a scrambled version of the other. A string is scrambled by recursively dividing it into two non-empty substrings and swapping them. 💡 Approach Used: Implemented Recursion + Memoization using a HashMap for overlapping subproblems. Used character frequency checks to prune unnecessary recursion calls. Used Java’s BiFunction with inline helper logic for recursion. ⚙️ Time Complexity: O(n⁴) (due to substring operations and recursion) 📦 Space Complexity: O(n²) ✨ Takeaway: Even complex recursive problems can be optimized efficiently with Memoization and early pruning. 🚀 #Java #LeetCode #DynamicProgramming #Recursion #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
🚀Day 98/100 #100DaysOfLeetCode 🧩Problem: Linked List Cycle✅ 👩💻Language: Java 🧠Approach: Used the Floyd’s Cycle Detection Algorithm (Tortoise and Hare Method). Two pointers move through the list — slow moves one step at a time, while fast moves two steps. If there’s a cycle, both pointers will eventually meet; otherwise, the list ends without intersection. 💡Key Takeaways: 🔹Efficiently detects a cycle using O(1) space. 🔹Demonstrates a classic use of the two-pointer technique. 🔹A must-know algorithm for linked list manipulation and interview prep. ⚙️Performance: ⏱️Runtime: 0 ms (Beats 100.00%) 💾Memory: 44.16 MB (Beats 96.16%) #100DaysOfLeetCode #Java #ProblemSolving #LinkedList #DataStructures #LeetCode #CodingJourney #CodingChallenge #FloydAlgorithm
To view or add a comment, sign in
-
-
🚀 Threads & Multithreading in Java – Let’s Make It Simple! Want to understand or brush up on Threads & Multithreading and crack those interviews? 💻✨ I’m diving deep into Java Threads, from basics to advanced concepts, and breaking it down with simple examples. Here’s the roadmap: 📌 Chapter 1: Java Threads – From Basics to Real Concepts https://lnkd.in/d7sWYRpH 📌 Chapter 2: Multithreading, Synchronization, Visibility, ThreadLocal & Inter-Thread Communication https://lnkd.in/d_4wMX5J 📌 Chapter 3: Executor Framework, Thread Pools & CompletableFuture https://lnkd.in/d-XfAZ7g No more confusion over race conditions, deadlocks, or thread safety – we’ll break it down step by step. Whether you’re preparing for interviews or just want to level up your Java skills, this series is for you. 💡 Let’s decode Java threads step by step, together! 💻🚀 #Java #Multithreading #JavaThreads #Coding #InterviewPrep #LearnTogether #ExecutorService #ThreadPool #CompletableFuture
To view or add a comment, sign in
-
-
🚀Day 94/100 #100DaysOfLeetCode 🧩Problem: Reverse Words in a String III✅ 💻Language: Java 🔍Approach: 🔹Split the given string by spaces to separate each word. 🔹For every word, reverse it using a StringBuilder. 🔹Append each reversed word back to the result string, adding spaces between them. 🔹Finally, return the complete reversed word string. 🧠Key Takeaways: 🔹Practiced efficient string manipulation using StringBuilder. 🔹Learned how splitting and reversing operations can be optimized for clarity. 🔹Strengthened understanding of text processing in Java. ⚡Performance: ⏱️Runtime: 4 ms (Beats 86.86%) 💾Memory: 45.49 MB (Beats 47.42%) #100DaysOfLeetCode #Java #CodingJourney #LeetCode #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
Reverse of a string in Java This method is like rewriting a word from the end to the beginning, letter by letter class ReverseString { public static void main(String[] args) { String original = "Hello"; String reversed = ""; for (int i = 0; i < original.length(); i++) { reversed = original.charAt(i) + reversed; } System.out.println("Reversed String: " + reversed); } } #java #Coding
To view or add a comment, sign in
-
Day 16 of my #JavaWithDSAChallenge Today I solved LeetCode Problem 28: Find the Index of the First Occurrence in a String - a simple yet very commonly asked coding interview question. Problem Summary Given two strings haystack and needle, the goal is to return the index of the first occurrence of needle inside haystack. If the substring doesn’t exist, we return -1. This problem helps strengthen: String manipulation Searching techniques Built-in Java utility understanding My Approach Java provides a very handy method: haystack.indexOf(needle) This directly returns the first matched index or -1 if no match exists. So the solution becomes clean, efficient, and readable - perfect for interviews where clarity matters as much as correctness. Code Implementation (Java) class Solution { public int strStr(String haystack, String needle) { // Directly using Java's built-in function return haystack.indexOf(needle); } } Key Takeaways Not all problems need complex algorithms — sometimes, built-ins are optimized and enough. #Day16 #JavaWithDSAChallenge #leetcode #codingchallenge #100DaysOfCode #Java #DSA #SoftwareEngineering #ProblemSolving #WomenInTech #TechJourney #LearningEveryday #InterviewPreparation
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