Functions vs Methods in Programming Function: standalone lines of code 👩💻 to perform certain task independently without an associated object. You can directly call ☎️ a function, pass arguments if required and it operates on the data. Method: is a function that is associated to an object or a class in object oriented programming (OOP). Methods are called on objevt using dot notation: object.method() -> the method have access to the data associated with the instance of the object invoked during the runtime🏃♂️ Key 🔐 Differences: 🎯Function are independent and can be called by their name anywhere. 🎯Methods are always associated with an object and are called using objects. 🎯Methods are specific and internal to objects, however functions are general-purpose. picture: https://lnkd.in/d9C5Rs6s
Satya Dash’s Post
More Relevant Posts
-
Generics in Object oriented programming offers several benefits. To name a few: Type safety - Detects errors at compile time instead of runtime No Casting - no need for manual type casting Code reuse: One generic class/method works for any data type Readability: makes data relationships clearer Performance: no runtime overhead
To view or add a comment, sign in
-
Day 8: Exploring Maps and Dictionaries in Programming Today, I worked on a classic problem involving Key-Value pair mappings using a Map/Dictionary data structure. The task was to create a Phone Book Application, where each friend’s name is mapped to their phone number. Then, based on user queries, the program returns either the contact details or “Not found” if the entry doesn’t exist. Here’s what I learned today: How Maps/Dictionaries efficiently store and retrieve data using keys. The importance of hashing for constant-time lookups. How to handle dynamic input and unknown query counts. 🧠 Key Takeaway: Using maps makes searching and data retrieval extremely efficient compared to linear searches. It’s one of the most useful data structures in real-world applications like phone directories, login systems, and caching mechanisms. 📘 Sample Output: sam=99912222 Not found harry=12299933 Every day brings a new concept and deeper understanding of data structures and logic building. On to the next challenge! #Day8 #100DaysOfCode #LearningJourney #Programming #ProblemSolving #DataStructures #CodingPractice #Java #Python #CPlusPlus #Developer checkout solution: https://lnkd.in/dfnzN4qw
To view or add a comment, sign in
-
-
🚀 Day 111 of #160DaysOfCode ✅ Topic: Dynamic Programming — Longest String Chain 💡 Platform: GeeksforGeeks (Problem: Longest String Chain) 🧠 Concept Learned: Today I solved the Longest String Chain problem using Dynamic Programming. The goal was to find the longest sequence of words where each word can be formed by adding exactly one letter to the previous word, without changing the order of characters. 📘 Approach Used: Sort all words by length (shorter first). Use a dictionary (dp) to store the longest chain ending at each word. For each word, generate all possible predecessors by removing one character at a time. If the predecessor exists in dp, update: dp[word] = max(dp[word], dp[pred] + 1) Keep track of the maximum chain length in res. 🧩 Example: Input: ["a", "b", "ba", "bca", "bda", "bdca"] Output: 4 Explanation: The longest chain is a → ba → bda → bdca ✅ Result: All test cases passed (1114 / 1114) 🎯 Understood how sorting + dynamic programming + string manipulation can be combined to solve complex sequence problems efficiently.
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 105 — Climbing Stairs (Dynamic Programming Evolution) Today’s problem — “Climbing Stairs” — is one of the classic Dynamic Programming questions that beautifully illustrates how thinking in terms of subproblems and state optimization can simplify even real-life-like scenarios. ✅ My Approaches: 1️⃣ Memoization (Top-Down) Started by solving recursively and storing already computed results in a dp array to avoid recomputation. 2️⃣ Tabulation (Bottom-Up) Converted the recursive approach into an iterative one, filling the dp array step by step — making it more efficient and intuitive. 3️⃣ Space Optimization Reduced the space from O(n) to O(1) by keeping track of only the last two states instead of the entire array. 📌 Key Insight Today: Dynamic Programming is not just about solving problems - it’s about identifying patterns of reuse and refining your logic with each iteration until it’s both elegant and optimal. 📊 Time Complexity: O(n) 📊 Space Complexity: O(1) (for the final optimized version) #LeetCode #DynamicProgramming #ClimbingStairs #DSA #Java #ProblemSolving #LearningInPublic #DailyCoding #Day105 #CodeEvolution
To view or add a comment, sign in
-
-
💡 Understanding Encapsulation in Object-Oriented Programming Encapsulation means binding data and methods into a single unit — one of the core principles of OOP. In simple terms, it’s about keeping the data (variables) safe from outside interference and misuse. We achieve this by creating private variables and accessing them from another class through getters and setters. This not only helps in data protection but also improves code readability, flexibility, and maintainability. Here’s a quick example 👇 public class Student { private String name; // private variable // getter public String getName() { return name; } // setter public void setName(String name) { this.name = name; } } Thanks Suresh Bishnoi Sir for your valuable support and guidance.
To view or add a comment, sign in
-
474. Ones and Zeroes 474. Ones and Zeroes Difficulty: Medium Topics: Array, String, Dynamic Programming You are given an array of binary strings strs and two integers m and n. Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset. A set x is a subset of a set y if all elements of x are also elements of y. Example 1: Input: strs = ["10","0001","111001","1","0"], m = 5, n = 3 Output: 4 Explanation: The largest subset with at most 5 0's and 3 1's is {"10", "0001", "1", "0"}, so the answer is 4. Other valid but smaller subsets include {"0001", "1"} and {"10", "1", "0"}. {"111001"} is an invalid subset because it contains 4 1's, greater than the maximum of 3. Example 2: Input: strs = ["10","0","1"], m = 1, n = 1 Output: 2 Explanation: The largest subset is {"0", "1"}, so the answer is 2. Constraints: 1 <= strs.length <= 600 1 <= strs[i].length <= 100 strs[i] consists only of digits '0' and '1'. 1 <= m, n <= 100 Solution: We need to find the largest subset of bin https://lnkd.in/gcWprruN
To view or add a comment, sign in
-
🎯 LeetCode 198 – House Robber | Dynamic Programming Today I revisited one of the most popular DP questions on LeetCode: House Robber. At first glance, it looks like a simple array problem — but it actually introduces one of the most important DP patterns: 👉 “Take or Skip” optimization using previous states. 🔍 Problem Insight You are given an array where each element represents the money in a house. The catch? You cannot rob two adjacent houses, or the alarm goes off. So for every house, we make a decision: ✔️ Rob this house → add its money + best answer from non-adjacent house ✔️ Skip this house → carry forward the best previous result This leads to the core DP transition: curr = max(curr, prev + nums[i]) 🧠 Why I Loved This Problem No need for a DP array Can be solved using only two variables Shows the power of optimizing space Very common interview pattern Helps understand Fibonacci-like transitions ✔️ My Java Solution (O(n) time, O(1) space) int prev = 0, curr = 0; for (int n : nums) { int temp = curr; curr = Math.max(curr, prev + n); prev = temp; } return curr; 🚀 Key Takeaways Many DP problems are just “previous state management”. Space optimization often turns complex-looking problems into simple ones. Always look for patterns like: pick / not pick take / skip include / exclude Happy to have solved and understood this one deeply — moving on to the next DP challenge! 💪🔥 #LeetCode #DynamicProgramming #JavaProgramming #CodingJourney #ProblemSolving #DSA #TechLearning #100DaysOfCode
To view or add a comment, sign in
-
More from this author
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