Implement Circular Queue (LinkedList Version) class CircularQueue { int[] arr; int front, rear, size, capacity; CircularQueue(int cap) { capacity = cap; arr = new int[cap]; front = 0; rear = -1; size = 0; } boolean isEmpty() { return size == 0; } boolean isFull() { return size == capacity; } void enqueue(int x) { if (isFull()) { System.out.println("Overflow"); return; } rear = (rear + 1) % capacity; arr[rear] = x; size++; } int dequeue() { if (isEmpty()) { System.out.println("Underflow"); return -1; } int val = arr[front]; front = (front + 1) % capacity; size--; return val; } } #DSA #DataStructuresAndAlgorithms #Coding #Programmer #LeetCode #CodeEveryday #JavaDSA #CodingPractice #ProblemSolving #CP #CompetitiveProgramming #DailyCoding #TechJourney #CodingCommunity #DeveloperLife #100DaysOfCode #CodeWithMe #LearnToCode #GeekForGeeks #CodingMotivation
Implementing a Circular Queue in Java
More Relevant Posts
-
🚀 LeetCode Daily Challenge 🔗 Problem: https://lnkd.in/diBESK6A 💡 My thought process: The solution checks every possible k × k submatrix in the grid to determine whether it forms a magic square. For a given starting position (row, col) and size k, it first validates that all row sums within the submatrix are equal by computing each row’s sum and comparing it against a reference value. It then verifies column consistency by ensuring every column sum matches the same reference row sum. Once row and column validation succeed, the algorithm computes both diagonals of the submatrix. The main diagonal is traversed from the top-left to the bottom-right of the submatrix, while the anti-diagonal is calculated using an offset-based index to correctly map the bottom-left to top-right traversal. The submatrix is considered a valid magic square only if both diagonal sums match each other and equal the row and column sums. 👉 My Solution: https://lnkd.in/dWn-uGVD If you found this breakdown helpful, feel free to ⭐ the repo or connect with me on LinkedIn 🙂🚀 #️⃣ #leetcode #cpp #dsa #coding #problemsolving #engineering #BDRM #BackendDevWithRahulMaheswari
To view or add a comment, sign in
-
-
The Requirement: Write an algorithm with O(log n) complexity. My Choice: nums.indexOf(target) The Result: Beats 100% runtime. 🤷♂️ Sometimes, the best engineering decision is just choosing the simplest tool for the job. 🚀 #LeetCode #SoftwareEngineering #WorkSmarter #TypeScript #Coding
To view or add a comment, sign in
-
-
The one concept that separates "Coders" from "Engineers".. In a world of high-level frameworks and automated memory management, understanding Pointers can feel like a lost art. But if you want to write truly efficient code—or understand what’s actually happening under the hood in languages like C, Go, or Rust—you have to master the "Address." Most people get stuck when they see & and * appearing together. It’s the ultimate test of logic and mental mapping. Challenge for the Dev Community: Take a look at the code snippet in the image. What is the final value that gets printed? Is it the original value, the updated value, or does the syntax itself cause a crash? Drop your answer (A, B, or C) in the comments! No spoilers in the first line of your comment—let’s see who can get it right on the first try! #SoftwareEngineering #CodingChallenge #Programming #WebDevelopment #Pointers #TechCommunity
To view or add a comment, sign in
-
-
Stop writing mid code. 💀 If you’re still using nested loops for every subarray problem, your runtime is literally crying. We’re moving from O(N^2) stress to O(N) energy with the Two Pointers glow-up. ⚡️ The TL;DR: •Two Pointers: Moving different directions (main character energy). •Sliding Window: For those continuous segments (no gatekeeping). Don't let your complexity be "too much." Check the slides to level up. 🧠 Practice challenge in the last slide! 📌 https://lnkd.in/gE4YJu4J #Coding #SoftwareEngineer #TwoPointers #LeetCode #GlowUp #ProgrammingTips #TechTok
To view or add a comment, sign in
-
DDD: Identify Value Objects ✨📦 Join Mike North to learn how domain-driven design turns messy business rules into clean code by modeling entities, value objects, and aggregates that reflect real-world systems. https://lnkd.in/g5CKeBJv #Fullstack #Backend #WebDev #Programming #Coding #LearnToCode #TypeScript
To view or add a comment, sign in
-
Day 13 Problem Statement: You’re given an array squares where each element is: [some x‑coordinate, some y‑coordinate, side length l] Each triple describes an axis‑aligned square on the 2D plane. The goal is to find the lowest possible y‑value of a horizontal line such that: The total area above the line equals The total area below the line Important rule: Overlapping areas are counted multiple times — i.e., if two squares overlap, the overlapped region contributes to the total for each square individually. Approach : The problem is to find a horizontal line that splits all squares into equal areas above and below. To solve it: Calculate the total area of all squares. Use binary search on y-coordinate to find the line. For each candidate y, sum the area below the line for all squares (full square if below, 0 if above, partial if intersecting). Move the line up or down depending on whether the area below is less or more than half the total. Stop when the areas are balanced — that y is the answer. #HappyCoding #LeetCode #Coding #ProblemSolving #Programming #Java #SoftwareEngineering #DSA #DataStructures #Algorithms #CompetitiveProgramming #CodeNewbie #TechLearning #DailyCodingChallenge #BinarySearch #LearnToCode #DeveloperCommunity
To view or add a comment, sign in
-
🔥 LeetCode Daily | Hard Problem Cracked (1458: Max Dot Product of Two Subsequences) 🔥 Another day, another reminder that real problem-solving begins where shortcuts fail. Today’s challenge wasn’t about syntax or speed — it was about decision-making under constraints. With negative numbers in play, greedy approaches collapse fast. The only way forward? Clean, well-structured Dynamic Programming. 🧠 What made this problem interesting: • Choosing take vs skip at every index • Handling negative values without breaking the logic • Ensuring subsequences remain non-empty (the real twist) ⚙️ Approach: Dynamic Programming to track the best possible dot product at each state while preserving order and maximizing value. 📊 Complexity: • Time: O(n × m) • Space: O(n × m) 💡 Lesson learned: Hard problems don’t test how fast you code. They test how clearly you think when the obvious approach fails. Consistency + fundamentals = inevitable progress. On to the next challenge. 🚀 #LeetCode #LeetCodeDaily #HardProblems #DynamicProgramming #DP #DataStructures #Algorithms #DSA #ProblemSolving #CodingInterview #InterviewPreparation #CompetitiveProgramming #Java #JavaDeveloper #SoftwareEngineering #ComputerScience #TechCareers #DeveloperJourney #100DaysOfCode #DailyCoding #ConsistencyWins
To view or add a comment, sign in
-
-
Proud to present our Compiler Construction project on Intermediate Code Generation (ICG) using Three Address Code (TAC). Through this project, we explored how high-level conditional statements such as if and if–else are translated into intermediate representations using labels, jumps, and backpatching techniques. It significantly improved our understanding of control flow representation, execution paths, and the internal working of compilers in a machine-independent way. I am truly grateful to our respected teacher Zobia Zafar for the guidance and insightful feedback. Special thanks to my teammates Ali Ashiq and Syed Taha Nasir for their dedication and teamwork, which made this project a valuable learning experience. #CompilerConstruction #CompilerDesign #IntermediateCodeGeneration #ThreeAddressCode #Coding #ComputerScience #ConditionalExpressions
To view or add a comment, sign in
-
🚀 LeetCode Daily Challenge 🔗 Problem: https://lnkd.in/dfbaS-gp 💡 My thought process: Looking at the constraints, it’s clear that this problem needs either sorting or binary search. The goal is to minimize the maximum pair sum. The key idea is to control how large any individual pair can get. A good strategy is to sort the array first. Once sorted, pairing the smallest element with the largest one helps balance the sums. If the smallest number were paired with anything other than the largest, the largest would then have to be paired with a larger number, which would increase the maximum pair sum even more. By consistently pairing the smallest remaining element with the largest remaining one, we make sure that no single pair becomes too large. This method spreads the values evenly across pairs and keeps the maximum pair sum as small as possible. 👉 My Solution: https://lnkd.in/dsTD-CFh If you found this breakdown helpful, feel free to ⭐ the repo or connect with me on LinkedIn 🙂🚀 #️⃣ #leetcode #cpp #dsa #coding #problemsolving #engineering #BDRM #BackendDevWithRahulMaheswari
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Challenge 🔗 Problem: https://lnkd.in/dvQUTQac 💡 My thought process: This solution calculates the minimum value of an array, allowing each element to be modified individually using bits. Each number in a list of input is checked to see if it’s odd or even. Even numbers can’t form a valid output, hence they are assigned -1. For odd numbers, the answer looks at bit positions from least significant to most significant to identify the first unset bit (0). Once obtained, it toggles the lowest bit below it (j-1) by performing an XOR operation, ensuring that the obtained number is the least integer that fulfills the specific condition. This algorithm requires a time complexity of O(n * 32) and additional space of O(n) for the size of the input list n. 👉 My Solution: https://lnkd.in/duUgT7Ag If you found this breakdown helpful, feel free to ⭐ the repo or connect with me on LinkedIn 🙂🚀 #️⃣ #leetcode #cpp #dsa #coding #problemsolving #engineering #BDRM #BackendDevWithRahulMaheswari
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