💡 (6th Nov 2025) Today I Learned: Functions & Methods (Part 3) Today’s session took functions beyond basics — applying them to real coding problems and understanding how scope works inside programs. Here’s what I explored 👇 1️⃣ Primes in a Range — Using loops and conditionals to print all primes between two numbers. 2️⃣ Binary to Decimal Conversion — Applying mathematical logic and functions to transform binary inputs. 3️⃣ Code: Binary to Decimal — Reinforcing function calls and arithmetic operations. 4️⃣ Decimal to Binary Conversion — Reversing the logic using division and remainders. 5️⃣ Code: Decimal to Binary — Practical exercise to solidify logic understanding. 6️⃣ Method Scope — Understanding how variables inside methods are accessible only within them. 7️⃣ Block Scope — How variables declared within a block { } exist only inside it. 🧩 Key Takeaway: Functions + Scope = Predictable & Maintainable Code. Knowing where your variables “live” in memory is just as important as writing efficient logic. #CodingJourney #Java #DSA #Functions #Programming #Scope #ApnaCollege #LearningInPublic #DeveloperGrowth
"Exploring Functions and Scope in Coding"
More Relevant Posts
-
📌 Day 153 of Coding - Maximum Frequency of an Element After Operations I (LeetCode - Medium) 🎯 Goal: Given an integer array nums, an integer range k, and a number of operations, determine the maximum possible frequency of any number after performing up to numOperations modifications - where each operation can change a number by at most k. 💡Approach & Debugging: Found the maximum value in the array and created a frequency prefix array. For each possible target value i, calculated the total numbers within the [i - k, i + k] range. The frequency of i could be increased using available operations on nearby elements. Kept track of the best achievable frequency. ✔️ Time Complexity: O(N + M) - where M is the value range up to max(nums) + k. ✔️ Space Complexity: O(M) 🧠Key Takeaways: Prefix sums + frequency arrays are powerful for range-based computations. Always optimize loops around range-based frequency calculations. #Day153 #LeetCode #Arrays #PrefixSum #Frequency #Java #ProblemSolving #DSA #CodingChallenge #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
📌 Day 154 of Coding - Check If Digits Are Equal in String After Operations I (LeetCode - Medium) 🎯 Goal: Given a numeric string s, repeatedly replace it with a new string formed by taking the sum (mod 10) of every pair of adjacent digits, until only two characters remain. Return whether the final two digits are equal. 💡Approach & Debugging: Used a simple iterative simulation approach. For each iteration, formed a new string res by summing adjacent digits modulo 10. Replaced s with res and continued until the string length dropped to 2. Finally, compared both digits for equality. ✔️ Time Complexity: O(N*N) - since the string shrinks gradually each iteration. ✔️ Space Complexity: O(N) - temporary strings. 🧠 Key Takeaways: Some problems test simulation and string manipulation more than algorithms. Always track how input size evolves after each iteration. #Day154 #LeetCode #StringManipulation #Java #ProblemSolving #DSA #CodingChallenge #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
📌 Day 155 of Coding - Next Greater Numerically Balanced Number (LeetCode - Medium) 🎯 Goal: Find the smallest integer greater than n such that the count of each digit d in the number is exactly d (for digits 1-7). 💡Approach & Debugging: Used backtracking to generate all “beautiful” numbers following the digit count rule. A helper function generate() recursively built numbers by trying digits 1-7, ensuring that no digit appeared more times than its own value. Checked each generated number using isBeautiful(). After generation, sorted the list and returned the first number greater than n. ✔️ Time Complexity: Exponential (backtracking-based generation, but limited by small constraints). ✔️ Space Complexity: O(1) auxiliary + O(M) list for generated numbers. 🧠 Key Takeaways: Precomputation and pruning (like limiting to 1224444) help keep recursion efficient. Problems mixing digit frequency logic and recursion sharpen number theory intuition. #Day155 #LeetCode #Backtracking #Recursion #Java #ProblemSolving #DSA #CodingChallenge #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
📌 Day 24/100 - Maximum Points You Can Obtain from Cards (LeetCode 1423) 🔹 Problem: You’re given an array of card points where each card has some value. You can take exactly k cards — but only from the beginning or end of the row. The goal is to maximize your total score. 🔹 Approach: This problem is a perfect case for the sliding window technique. Start by taking the sum of the first k cards (left side). Then, gradually move one card from the left side to the right side — each time removing one card from the start and adding one from the end. Track the maximum sum at each step. ✅ This gives an O(k) time solution — efficient and clean! 🔹 Key Learning: Use sliding window when you need to balance two ends dynamically. Prefix sums aren’t always needed — direct window manipulation works wonders. Optimization often lies in reducing repeated work, not complex math. A simple yet powerful logic: “Take, replace, compare — repeat!” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #SlidingWindow #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 68 of #100DaysOfChallenge Today's problem: 3461. Check If Digits Are Equal in String After Operations I (LeetCode - Easy) This problem was a fun blend of pattern observation and modular arithmetic — a great reminder that even simple-looking questions can strengthen your logical flow and coding discipline on LeetCode. 🧩 Problem Overview: We’re given a string of digits, and in each step, we repeatedly calculate the sum of every pair of consecutive digits modulo 10, until only two digits remain. Finally, we check whether those two digits are equal. 💡 My Approach: Used a straightforward simulation approach — repeatedly computing new strings of digits using modular arithmetic until only two digits were left. It’s simple, direct, and performs efficiently for short strings. ⚙️ Language: Java ⚡ Runtime: 8 ms (Beats 72.03%) 💾 Memory: 44.67 MB (Beats 69.77%) ✅ Result: Accepted — 706 / 706 test cases passed Every daily problem adds another layer of precision and confidence. Consistency isn’t just about coding every day — it’s about learning something new with every attempt. 🌱 On to the next challenge 💪 #100DaysOfCode #LeetCode #ProblemSolving #Java #CodingChallenge #Programming #DeveloperJourney #LearningEveryday #TechMindset #Consistency
To view or add a comment, sign in
-
-
✅ Day 74 of LeetCode Medium/Hard Edition Today’s challenge was “Minimum Falling Path Sum II” — a dynamic programming problem that blends recursion, memoization, and row-wise optimization ⚡💡 📦 Problem: You're given an n × n integer matrix. A falling path selects exactly one element from each row, and the restriction is: No two consecutive elements may be chosen from the same column. Return the minimum possible sum of such a falling path. 🔗 Problem Link: https://lnkd.in/gbKyfbqs ✅ My Submission: https://lnkd.in/gtg_qzW8 💡 Thought Process: This problem extends the classic minimum falling path by enforcing a non-zero shift, meaning the chosen column must change at every row. To solve this efficiently, we can use Dynamic Programming with memoization, where: dp[r][c] represents the minimum falling path sum starting from grid[r][c]. From each cell, we explore all columns in the next row except the same one. Memoization prevents recomputing overlapping subproblems. A further optimization uses the idea of tracking: the minimum and second minimum values from the previous row So when transitioning: If the current column ≠ min-index → pick the global minimum Else → pick the second minimum This eliminates the O(n³) brute force and reduces complexity to O(n²). 🎯 Base Cases: The last row directly contributes its cell value: dp[n-1][c] = grid[n-1][c] Transition occurs upward row by row. Memoized states avoid repeated work. ⚙️ Complexity: ⏱ Time: O(n²) with optimized DP 💾 Space: O(n²) with memo / O(n) with rolling array 🧩 Key Learnings: Strengthened understanding of state transitions with constraints. Practiced converting a brute DFS idea into an efficient DP + memo solution. Learned how tracking min & second-min values avoids nested loops. Solidified recursion-to-DP thinking for grid-based problems. #LeetCodeMediumHardEdition #100DaysChallenge #DynamicProgramming #Java #DSA #ProblemSolving #LearnEveryday
To view or add a comment, sign in
-
-
🌟 Day 85 of My #100DaysOfCode Challenge 🧩 Problem: LeetCode 119 – Pascal’s Triangle II 🧠 Understanding the Problem We need to return the rowIndexth (0-indexed) row of Pascal’s Triangle. Each number is formed by adding the two numbers directly above it from the previous row. 📘 Example: Input: rowIndex = 3 Output: [1, 3, 3, 1] ⚙️ Approach Start with [1] as the first row. For each new row, update the list from right to left (so we don’t overwrite values that we still need). Append 1 at the end of each iteration to complete the row. 🕒 Complexity Time Complexity: O(n²) Space Complexity: O(n) ✅ (optimized — we use only one list) 💡 Key Learning This problem emphasizes in-place updates — a technique often used to optimize space in dynamic programming problems. ✨ Takeaway Building Pascal’s Triangle row by row mirrors how small consistent steps lead to structured growth — just like progress in coding! 🚀 💬 “Each layer of learning strengthens the next — one row at a time.” 💛 #Day85 #LeetCode #Java #DSA #DynamicProgramming #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
📌 Day 159 of Coding - Make Array Elements Equal to Zero (LeetCode - Easy) 🎯 Goal: Given an integer array nums, find the number of valid starting positions and directions such that by repeatedly decrementing and reversing direction (based on the rules), all elements eventually become 0. 💡Approach & Debugging: First computed total sum using Arrays.stream(nums).sum(). Maintained two prefix sums : left and right. For each index i where nums[i] == 0: Incremented left and decremented right progressively. Checked whether the left and right sums balance according to the movement rules. Counted valid selections when the balance was perfect or off by just one. ✔️ Time Complexity: O(N) - single pass through the array. ✔️ Space Complexity: O(1) - constant extra space. #Day159 #LeetCode #Simulation #Arrays #PrefixSum #Java #ProblemSolving #DSA #CodingChallenge #100DaysOfCode #Algorithms #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
🚀 Day 414 of #500DaysOfCode 🔢 LeetCode 2536: Increment Submatrices by One (Medium) Today I worked on an interesting matrix manipulation problem that teaches an important optimization idea — 2D Difference Arrays. 🧠 Problem Summary We are given an n x n matrix initialized with zeros and a list of queries. Each query represents a submatrix, and we need to increment every element inside that submatrix by 1. A brute-force solution would update each cell for every query, which becomes inefficient when the matrix and number of queries grow. ⚡ Key Insight Instead of updating all cells directly, we use a 2D prefix / difference matrix technique: Update only the corners of each submatrix Convert the difference matrix into the final matrix using prefix sums Achieve O(n² + q) performance instead of O(q · n²) A neat trick that’s extremely useful for range update problems! ✅ Takeaways Difference arrays are not just for 1D — they scale beautifully to 2D Matrix prefix sums simplify many complex update operations Thinking in terms of range operations often leads to faster algorithms 💻 Tech Used Java 2D prefix sum optimization Matrix manipulation Another day, another concept mastered. On to the next challenge! 💪🔥 #coding #leetcode #java #programming #dsa #matrix #problemsolving #500DaysOfCode #Day414
To view or add a comment, sign in
-
Explore related topics
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