<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by sainath on Medium]]></title>
        <description><![CDATA[Stories by sainath on Medium]]></description>
        <link>https://medium.com/@lightWonders?source=rss-710814ed49b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*DxgStQ-WEs_NmOQA</url>
            <title>Stories by sainath on Medium</title>
            <link>https://medium.com/@lightWonders?source=rss-710814ed49b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 02:39:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lightWonders/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Top 10 Java Syntax Mistakes Beginners Make and How to Avoid Them]]></title>
            <link>https://medium.com/@lightWonders/top-10-java-syntax-mistakes-beginners-make-and-how-to-avoid-them-22b546909ec6?source=rss-710814ed49b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/22b546909ec6</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[sainath]]></dc:creator>
            <pubDate>Thu, 31 Oct 2024 19:31:56 GMT</pubDate>
            <atom:updated>2024-10-31T19:31:56.103Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kRQE-YzmYfe-O2IojLN37g.jpeg" /></figure><h3>Java is a powerful, widely-used programming language, but its strict syntax can trip up even the most eager beginners. Here’s a guide to some of the most common syntax mistakes new Java developers make, along with tips on how to avoid them. By learning to recognize these errors, you’ll write cleaner code and save yourself hours of debugging!</h3><h3>1. Forgetting the Semicolon</h3><ul><li><strong>The Mistake</strong>: Omitting the semicolon at the end of a statement.</li><li><strong>Why It Happens</strong>: In Java, each statement must end with a semicolon, but beginners often forget this, especially if they’re coming from languages that don’t require semicolons.</li><li><strong>How to Avoid</strong>: Double-check each line for the ; at the end before running your code. This will become second nature with practice.</li></ul><h3>2. Incorrectly Naming Classes and Files</h3><ul><li><strong>The Mistake</strong>: Mismatching the class name with the filename.</li><li><strong>Why It Happens</strong>: In Java, the filename must exactly match the name of the public class it contains, including capitalization.</li><li><strong>How to Avoid</strong>: When creating a new class, ensure the filename matches the class name exactly. For instance, if your class is public class HelloWorld, the file must be named HelloWorld.java.</li></ul><h3>3. Misunderstanding Primitive Types vs. Reference Types</h3><ul><li><strong>The Mistake</strong>: Confusing primitive types (like int, double, boolean) with their wrapper classes (Integer, Double, Boolean).</li><li><strong>Why It Happens</strong>: Primitive types and reference types are used differently in Java, and they aren’t interchangeable.</li><li><strong>How to Avoid</strong>: Remember that primitive types are basic data types with fixed sizes, while wrapper classes are objects that provide additional methods. Use primitives for simple calculations, and wrappers only when you need to store them in collections like ArrayList.</li></ul><h3>4. Misplacing Curly Braces</h3><ul><li><strong>The Mistake</strong>: Misaligning or omitting curly braces, {}, leading to blocks that don’t behave as expected.</li><li><strong>Why It Happens</strong>: Java uses curly braces to define the beginning and end of code blocks, but beginners may forget one or place them incorrectly.</li><li><strong>How to Avoid</strong>: Use an IDE with automatic indentation to keep track of where blocks begin and end. Consistently format your code to make reading and debugging easier.</li></ul><h3>5. Incorrect Use of == for Comparing Strings</h3><ul><li><strong>The Mistake</strong>: Using == instead of .equals() to compare strings.</li><li><strong>Why It Happens</strong>: == checks for reference equality (if two references point to the same object), not the actual string content.</li><li><strong>How to Avoid</strong>: Use .equals() to compare string values, like this: if (str1.equals(str2)). Save == for comparing primitive types.</li></ul><h3>6. Null Pointer Exceptions</h3><ul><li><strong>The Mistake</strong>: Trying to access methods or properties of an object without checking if it’s null.</li><li><strong>Why It Happens</strong>: New developers might not realize an object can be null, and trying to access it leads to a NullPointerException.</li><li><strong>How to Avoid</strong>: Always check if an object is null before accessing its methods or properties. For example: if (object != null) { object.method(); }</li></ul><h3>7. Array Index Out of Bounds</h3><ul><li><strong>The Mistake</strong>: Attempting to access an array element outside its bounds.</li><li><strong>Why It Happens</strong>: Arrays are zero-indexed, so accessing an element outside the valid index range throws an error.</li><li><strong>How to Avoid</strong>: Remember that an array with n elements has valid indices from 0 to n-1. Use array.length to avoid going out of bounds.</li></ul><h3>8. Misusing the main Method</h3><ul><li><strong>The Mistake</strong>: Misspelling or changing the signature of the main method.</li><li><strong>Why It Happens</strong>: The main method in Java has a specific format: public static void main(String[] args). If you modify this, Java won’t recognize it as the entry point.</li><li><strong>How to Avoid</strong>: Always type public static void main(String[] args) exactly. Let your IDE autofill it to ensure accuracy.</li></ul><h3>9. Not Importing Required Packages</h3><ul><li><strong>The Mistake</strong>: Forgetting to import essential packages like java.util for collections.</li><li><strong>Why It Happens</strong>: Java does not automatically import most packages, so you need to import them manually to use their classes.</li><li><strong>How to Avoid</strong>: If you see a “cannot find symbol” error, check if you’ve imported the necessary packages at the top of your file (e.g., import java.util.ArrayList;).</li></ul><h3>10. Not Handling Exceptions Properly</h3><ul><li><strong>The Mistake</strong>: Ignoring or incorrectly handling exceptions, leading to potential runtime errors.</li><li><strong>Why It Happens</strong>: New programmers might feel unsure about Java’s try-catch syntax and thus avoid using it.</li><li><strong>How to Avoid</strong>: Wrap risky code (like file handling or network requests) in a try-catch block. For example:</li></ul><pre>try {    <br> // code that might throw an exception }<br> catch (Exception e)<br> {     <br>System.out.println(&quot;An error occurred: &quot; + e.getMessage()); <br>}</pre><h3>Wrapping Up</h3><p>Syntax mistakes are part of the learning process for any programming language, and Java is no exception. By becoming familiar with these common issues, you’ll write more effective code and spend less time debugging. Keep practicing, and soon these mistakes will be a thing of the past!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22b546909ec6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 10 Most Important Techniques for Coding Interviews]]></title>
            <link>https://medium.com/@lightWonders/the-10-most-important-techniques-for-coding-interviews-65e757387eb1?source=rss-710814ed49b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/65e757387eb1</guid>
            <dc:creator><![CDATA[sainath]]></dc:creator>
            <pubDate>Mon, 28 Oct 2024 18:32:09 GMT</pubDate>
            <atom:updated>2024-10-28T18:32:09.652Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*25-vEhBvvvBh7Bk9IL6NOQ.jpeg" /></figure><p>“I want to start this blog with a famous quote: <em>‘Focus on the vital few: 20% of efforts often drive 80% of results.’</em>”</p><p>In coding interviews, mastering a set of core techniques can make tackling complex problems easier and more efficient. While data structures like arrays, linked lists, and trees are essential, having a solid grasp of techniques like two-pointers, sliding windows, and dynamic programming can set you apart. Here are ten key techniques you should focus on for success in coding interviews:</p><h3>1. Two Pointers Technique</h3><p>The two-pointers technique is widely used for array and string problems, especially when dealing with sorted arrays or specific search conditions. Here, two pointers traverse the data structure from different directions to find pairs, subarrays, or specific elements efficiently.</p><ul><li><strong>When to use</strong>: Problems involving pairs, subarrays, or duplicates in sorted arrays.</li><li><strong>Example problems</strong>: Find if an array has two numbers that add up to a target (two-sum), remove duplicates from a sorted array.</li></ul><h3>2. Sliding Window Technique</h3><p>The sliding window technique is great for problems involving contiguous subarrays or substrings. A window (range of elements) “slides” over the data structure to find a target condition without re-evaluating the entire array repeatedly.</p><ul><li><strong>When to use</strong>: Problems dealing with subarrays or substrings, especially for maximum, minimum, or specific sums.</li><li><strong>Example problems</strong>: Maximum sum of a subarray of a given size, smallest subarray with a sum greater than a given value.</li></ul><h3>3. Binary Search</h3><p>Binary search is a powerful technique to efficiently locate a target element in a sorted array or search space. By repeatedly dividing the search space in half, binary search achieves logarithmic time complexity.</p><ul><li><strong>When to use</strong>: When searching for a target value in sorted data or when the solution space can be halved based on some condition.</li><li><strong>Example problems</strong>: Find the square root of a number, search in rotated sorted arrays.</li></ul><h3>4. Hashing</h3><p>Using hash tables (or dictionaries) allows you to store and retrieve elements in constant time. Hashing is invaluable for problems that need efficient lookups, like finding duplicates or tracking elements in arrays.</p><ul><li><strong>When to use</strong>: When you need quick lookups or to keep track of elements already seen.</li><li><strong>Example problems</strong>: Two-sum with hash maps, checking for anagrams.</li></ul><h3>5. Dynamic Programming (DP)</h3><p>Dynamic programming breaks problems into smaller subproblems and stores the results to avoid redundant calculations. It’s crucial for solving optimization problems, where you need to maximize or minimize a result under given constraints.</p><ul><li><strong>When to use</strong>: When the problem has overlapping subproblems and optimal substructure properties.</li><li><strong>Example problems</strong>: Fibonacci series, longest common subsequence, 0/1 knapsack.</li></ul><h3>6. Greedy Technique</h3><p>The greedy technique involves making locally optimal choices at each step to find a global optimum. Greedy algorithms are simple and fast but don’t always work for every problem, so it’s important to confirm that the greedy approach will yield the correct solution.</p><ul><li><strong>When to use</strong>: Problems that require maximizing or minimizing values, where local choices lead to global solutions.</li><li><strong>Example problems</strong>: Activity selection problem, minimum number of coins for change.</li></ul><h3>7. Backtracking</h3><p>Backtracking involves exploring all possible solutions and “backtracking” when reaching an invalid state. It’s essential for problems that require generating all possible combinations or permutations.</p><ul><li><strong>When to use</strong>: Problems requiring exhaustive search for solutions, such as permutations and combinations.</li><li><strong>Example problems</strong>: Solving Sudoku, generating subsets, and N-Queens problem.</li></ul><h3>8. Depth-First Search (DFS) and Breadth-First Search (BFS)</h3><p>DFS and BFS are fundamental graph traversal techniques. They are crucial for problems involving tree and graph structures, such as connectivity, pathfinding, and detecting cycles.</p><ul><li><strong>When to use</strong>: Problems involving traversal of trees or graphs, especially when you need to explore all nodes or find shortest paths.</li><li><strong>Example problems</strong>: Pathfinding in a grid (like in a maze), finding connected components in a graph.</li></ul><h3>9. Union-Find (Disjoint Set Union)</h3><p>The Union-Find technique helps in handling dynamic connectivity, where you need to determine whether two elements belong to the same subset or to merge two subsets. This is often used in graph problems involving connected components and cycles.</p><ul><li><strong>When to use</strong>: Problems involving merging groups or checking connectivity in dynamic systems.</li><li><strong>Example problems</strong>: Detecting cycles in an undirected graph, Kruskal’s algorithm for minimum spanning trees.</li></ul><h3>10. Heap / Priority Queue</h3><p>A heap (min-heap or max-heap) allows you to efficiently retrieve the minimum or maximum element, making it invaluable for problems that involve priority, like finding the top k elements.</p><ul><li><strong>When to use</strong>: When you need frequent retrieval of the smallest or largest element, especially in real-time data streams.</li><li><strong>Example problems</strong>: Find the k largest elements in an array, merge k sorted lists.</li></ul><h3>Conclusion</h3><p>Mastering these techniques not only helps in cracking interviews but also equips you with a strong toolkit to approach a wide range of algorithmic problems. Practice implementing each technique in various scenarios, and remember that the ability to identify which technique to apply is as important as knowing the technique itself.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65e757387eb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 10 Most Important Concepts for Coding Interviews: Algorithms and Data Structures]]></title>
            <link>https://medium.com/@lightWonders/the-10-most-important-concepts-for-coding-interviews-algorithms-and-data-structures-a04ffd8b45dc?source=rss-710814ed49b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a04ffd8b45dc</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[sainath]]></dc:creator>
            <pubDate>Sun, 27 Oct 2024 12:42:07 GMT</pubDate>
            <atom:updated>2024-10-27T12:42:07.828Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*6Lh81YwJcM7ejiOGSieunw.jpeg" /></figure><p>Preparing for coding interviews can be intimidating, but mastering key algorithms and data structures (DSA) can make a big difference. Understanding these essential concepts will boost your problem-solving skills and help you navigate challenging interview questions. Let’s dive into the 10 most important topics you should know before your next interview!</p><h3>1. Arrays and Strings</h3><p><strong>Why It’s Important:</strong> Arrays and strings are the foundation of many coding problems. They’re used to store and manipulate data, and mastering them gives you a strong foundation for more complex structures.</p><ul><li><strong>Key Concepts:</strong> Array traversal, sliding windows, two-pointer techniques, sorting, and searching.</li><li><strong>Common Problems:</strong> Finding duplicates, reversing arrays, rotating arrays, string matching, and manipulating substrings.</li></ul><p><strong>Example:</strong> “Given an array of integers, find the maximum sum of a contiguous subarray” (Kadane’s Algorithm).</p><h3>2. Linked Lists</h3><p><strong>Why It’s Important:</strong> Linked lists are a flexible data structure used in many applications, from memory management to complex data structures.</p><ul><li><strong>Key Concepts:</strong> Single and doubly linked lists, node manipulation, slow/fast pointers, and reversing linked lists.</li><li><strong>Common Problems:</strong> Detecting cycles, finding the middle of a list, reversing sections, and merging two sorted lists.</li></ul><p><strong>Example:</strong> “Reverse a linked list” — this is a classic question that tests understanding of node manipulation.</p><h3>3. Stacks and Queues</h3><p><strong>Why It’s Important:</strong> Stacks and queues are fundamental for tasks involving Last-In-First-Out (LIFO) and First-In-First-Out (FIFO) principles. They’re widely used in recursive problems and to implement algorithms like breadth-first search (BFS).</p><ul><li><strong>Key Concepts:</strong> Push and pop operations, queue handling, and understanding stack vs. queue behavior.</li><li><strong>Common Problems:</strong> Implementing a stack or queue, balanced parentheses, evaluating expressions, and finding the next greater element.</li></ul><p><strong>Example:</strong> “Use a stack to check if a string of parentheses is balanced.”</p><h3>4. Hashing</h3><p><strong>Why It’s Important:</strong> Hashing enables fast data retrieval and is essential in designing algorithms with O(1) access time. Hash tables/dictionaries are also widely used in real-world applications.</p><ul><li><strong>Key Concepts:</strong> Hash functions, hash collisions, hash maps, and sets.</li><li><strong>Common Problems:</strong> Finding duplicates in an array, checking if two strings are anagrams, and implementing LRU caches.</li></ul><p><strong>Example:</strong> “Design a data structure to keep track of unique elements and allow constant-time insertion, deletion, and access.”</p><h3>5. Binary Trees and Binary Search Trees (BST)</h3><p><strong>Why It’s Important:</strong> Trees are hierarchical structures that represent real-world systems like file directories or organizational structures. Binary trees and BSTs are particularly common in interviews for efficient data organization and retrieval.</p><ul><li><strong>Key Concepts:</strong> Tree traversal (inorder, preorder, postorder), recursion, and properties of BST.</li><li><strong>Common Problems:</strong> Inverting a binary tree, finding the height of a tree, and lowest common ancestor in a binary tree.</li></ul><p><strong>Example:</strong> “Given a binary tree, return the level order traversal of its nodes’ values.”</p><h3>6. Heaps and Priority Queues</h3><p><strong>Why It’s Important:</strong> Heaps are specialized tree-based data structures that are the foundation for priority queues. They are widely used in scheduling and resource allocation problems.</p><ul><li><strong>Key Concepts:</strong> Min-heaps, max-heaps, heapify operations, and insertion/removal in a heap.</li><li><strong>Common Problems:</strong> Finding the k largest elements in an array, implementing a priority queue, and finding the median in a data stream.</li></ul><p><strong>Example:</strong> “Find the k largest elements in an array using a min-heap.”</p><h3>7. Graph Algorithms</h3><p><strong>Why It’s Important:</strong> Graphs are essential for representing networks, and they form the basis for many complex problems. Knowing graph algorithms is key to understanding network flows, social networks, and more.</p><ul><li><strong>Key Concepts:</strong> Graph representation (adjacency list/matrix), BFS, DFS, shortest path, and topological sorting.</li><li><strong>Common Problems:</strong> Detecting cycles in a graph, shortest path in a weighted graph, and checking for bipartite graphs.</li></ul><p><strong>Example:</strong> “Implement a function to check if a graph is a valid tree.”</p><h3>8. Sorting and Searching Algorithms</h3><p><strong>Why It’s Important:</strong> Sorting and searching are at the core of efficient data manipulation. Sorting helps in organizing data, while searching quickly locates needed information within a collection.</p><ul><li><strong>Key Concepts:</strong> Binary search, quicksort, mergesort, and understanding time complexity of each sorting algorithm.</li><li><strong>Common Problems:</strong> Merging two sorted arrays, searching in a rotated sorted array, and sorting custom objects based on attributes.</li></ul><p><strong>Example:</strong> “Given a sorted array, implement binary search to find an element.”</p><h3>9. Dynamic Programming (DP)</h3><p><strong>Why It’s Important:</strong> Dynamic programming is a powerful technique used to solve complex problems by breaking them down into simpler subproblems. Many interview problems can be solved optimally using DP.</p><ul><li><strong>Key Concepts:</strong> Memoization, tabulation, overlapping subproblems, and optimal substructure.</li><li><strong>Common Problems:</strong> Fibonacci sequence, knapsack problem, longest increasing subsequence, and coin change problem.</li></ul><p><strong>Example:</strong> “Given an array of numbers, find the longest increasing subsequence.”</p><h3>10. Bit Manipulation</h3><p><strong>Why It’s Important:</strong> Bit manipulation is a technique often used in optimization problems, especially in system-level programming, graphics, and cryptography. Bitwise operations can lead to efficient solutions.</p><ul><li><strong>Key Concepts:</strong> Bitwise AND, OR, XOR, shifts, and bit masks.</li><li><strong>Common Problems:</strong> Finding the single number in an array where every element appears twice, counting set bits, and checking power of two.</li></ul><p><strong>Example:</strong> “Given an integer, write a function to count the number of 1 bits in its binary representation.”</p><h3>Conclusion</h3><p>Mastering these 10 core DSA concepts will set you up for success in coding interviews. Not only will you be able to solve a wide variety of problems, but you’ll also develop a deeper understanding of how to approach and optimize your solutions. Remember, practice is key — so dive into these topics, work through sample problems, and take your coding interview skills to the next level!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a04ffd8b45dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Problem-Solving in DSA with the STAR Technique ]]></title>
            <link>https://medium.com/@lightWonders/mastering-problem-solving-in-dsa-with-the-star-technique-d40fe311273f?source=rss-710814ed49b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d40fe311273f</guid>
            <dc:creator><![CDATA[sainath]]></dc:creator>
            <pubDate>Mon, 21 Oct 2024 05:02:14 GMT</pubDate>
            <atom:updated>2024-10-21T05:02:14.516Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KsjAVj_8G9DDQTOLEIIVgg.jpeg" /></figure><p>DSA (Data Structures and Algorithms) is like the <strong>roti-sabzi</strong> for every Indian developer — a staple, especially when you’re prepping for those do-or-die coding interviews or writing efficient code. But let’s be honest — when you’re under pressure, explaining your thought process can feel like you’re suddenly speaking in Sanskrit!</p><p>That’s where the <strong>STAR</strong> technique comes to the rescue. Normally used in behavioral interviews, STAR (Situation, Task, Action, Result) can be a game-changer for DSA problems too. It’s like adding a pinch of <strong>masala</strong> to your explanation — it makes your answer much tastier and memorable for the interviewer!</p><p>Let’s break it down:</p><h3>What is the STAR Technique?</h3><p>STAR stands for:</p><ul><li><strong>S</strong>ituation</li><li><strong>T</strong>ask</li><li><strong>A</strong>ction</li><li><strong>R</strong>esult</li></ul><p>This framework helps you explain not just <em>what</em> you did to solve a problem, but <em>how</em> you approached it, step by step. When you can explain your thought process clearly and logically, interviewers will see that you’re not just a coder, but a problem solver. 🔍</p><h3>Applying STAR to DSA</h3><p>Let’s take an example. You’ve been asked a common DSA interview question:</p><p><strong>Problem: “Find the first non-repeating character in a string.”</strong></p><p>Without STAR, you might dive right into code, which might solve the problem, but won’t do justice to your approach. With STAR, you can give a complete answer that shows your structured thinking.</p><h3>Step 1: Situation</h3><p>First, describe the problem clearly. Restating the problem not only shows you’ve understood it, but also buys you some time to think.</p><blockquote><em>“Okay, so we’re given a string, and we need to find the first character that doesn’t repeat. For example, in the string ‘hello’, the first non-repeating character is ‘h’. And if all characters repeat, we return something like ‘None’.”</em></blockquote><h3>Step 2: Task</h3><p>Next, clarify what you need to achieve and the requirements.</p><blockquote><em>“I need to write a function that efficiently finds the first non-repeating character in a string. Ideally, I’d want this function to work in </em><strong><em>O(n)</em></strong><em> time where </em><strong><em>n</em></strong><em> is the length of the string, because we don’t want to revisit characters more than necessary.”</em></blockquote><h3>Step 3: Action</h3><p>This is where you explain the plan — your <strong>approach</strong> to solving the problem. In this step, it’s important to mention the data structure or algorithm you’ll be using, how you’ll traverse the input, and any edge cases you plan to handle.</p><blockquote><em>“I’ll use a </em><strong><em>hash map (or a dictionary)</em></strong><em> to keep track of the frequency of each character. I’ll first make one pass through the string to store the count of each character. Then, I’ll make a second pass through the string to check which character has a count of one. This gives us the first non-repeating character. Using a hash map allows me to efficiently store and look up counts in constant time.”</em></blockquote><p>You can also mention edge cases:</p><blockquote><em>“Edge cases might include an empty string or a string where all characters repeat, so I’ll make sure to handle those as well.”</em></blockquote><h3>Step 4: Result</h3><p>Finally, explain the outcome or result, and how your approach solves the problem efficiently. If you’re in an interview, this is where you run through the code and summarize your solution.</p><blockquote><em>“With this approach, I’m able to find the first non-repeating character in </em><strong><em>O(n)</em></strong><em> time, because I only need to traverse the string twice and hash map operations are O(1). In the case where no characters are unique, the function will return ‘None’.”</em></blockquote><h3>Code Implementation (Action + Result)</h3><pre>public class FirstNonRepeatingCharacter {<br>    public static char findFirstNonRepeatingChar(String s) {<br>        HashMap&lt;Character, Integer&gt; charCountMap = new HashMap&lt;&gt;();</pre><pre>        // First pass: Count the occurrences of each character<br>        for (char c : s.toCharArray()) {<br>            charCountMap.put(c, charCountMap.getOrDefault(c, 0) + 1);<br>        }</pre><pre>        // Second pass: Find the first character with count 1<br>        for (char c : s.toCharArray()) {<br>            if (charCountMap.get(c) == 1) {<br>                return c;<br>            }<br>        }</pre><pre>        // If no non-repeating character is found<br>        return &#39;_&#39;; // Or return &#39;None&#39; or another indicator<br>    }</pre><pre>    public static void main(String[] args) {<br>        String input = &quot;hello&quot;;<br>        System.out.println(&quot;First non-repeating character: &quot; + findFirstNonRepeatingChar(input));<br>    }<br>}</pre><h3>Conclusion 🏁</h3><p>Using the <strong>STAR</strong> technique, you don’t just throw code at the problem; you tell a story. You show the interviewer that you can break down complex problems, think critically about the approach, and explain the process in a way that’s easy to understand. Plus, it gives you a framework to stay calm and organized when the pressure is on!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d40fe311273f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Difference Between == and equals() in Java]]></title>
            <link>https://medium.com/@lightWonders/understanding-the-difference-between-and-equals-in-java-fb24b915381e?source=rss-710814ed49b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb24b915381e</guid>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[sainath]]></dc:creator>
            <pubDate>Fri, 18 Oct 2024 19:43:07 GMT</pubDate>
            <atom:updated>2024-10-21T10:14:26.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="java" src="https://cdn-images-1.medium.com/max/299/1*npxsbogjugBvwS9IVAo1WA.jpeg" /></figure><p><strong>Hello, fellow Java enthusiasts!</strong> Today, we’re diving into a topic that often leaves many developers scratching their heads: the difference between == and equals(). Whether you’re a beginner just starting or a seasoned pro, understanding this difference is crucial for writing effective Java code. So, grab your coffee, and let’s unravel this mystery !</p><h3>The Basics: What Are == and equals()?</h3><p>Before we get into the nitty-gritty, let’s clarify what each of these actually does:</p><ul><li><strong>== Operator</strong>: This is a reference comparison operator. When you use == to compare two objects, it checks whether both references point to the same object in memory. Think of it as a way of asking, “Are we looking at the same dish on the table?”</li><li><strong>equals() Method</strong>: This is a method defined in the Object class, which many classes override to provide a way of comparing the actual contents (or values) of the objects. When you use equals(), you’re asking, “Do these two dishes contain the same ingredients, even if they are served in different bowls?”</li></ul><h3>A Simple Example to Illustrate</h3><p>Let’s consider a scenario with a class called Person:</p><pre>class Person {<br>    String name;<br>    <br>    Person(String name) {<br>        this.name = name;<br>    }<br>    <br>    @Override<br>    public boolean equals(Object obj) {<br>        if (this == obj) return true; // Check if both references point to the same object<br>        if (!(obj instanceof Person)) return false; // Check if obj is an instance of Person<br>        Person other = (Person) obj; // Cast the Object to Person<br>        return this.name.equals(other.name); // Compare the names<br>    }<br>}</pre><p>Now, let’s create two Person objects:</p><pre>Person person1 = new Person(&quot;John&quot;);<br>Person person2 = new Person(&quot;John&quot;);<br>Person person3 = person1;</pre><h3>Comparing with ==</h3><p>When we use == to compare person1 and person2:</p><pre>System.out.println(person1 == person2); // Output: false</pre><p>Here, == returns false because person1 and person2 are two different objects in memory, even though they contain the same name.</p><h3>Comparing with equals()</h3><p>Now, if we compare person1 and person2 using equals():</p><pre>System.out.println(person1.equals(person2)); // Output: true</pre><p>In this case, equals() returns true because we’ve overridden it to check the content of the name field, and both names are the same.</p><h3>What About person1 and person3?</h3><p>Now, what happens when we compare person1 and person3?</p><pre>System.out.println(person1 == person3); // Output: true<br>System.out.println(person1.equals(person3)); // Output: true</pre><p>Both comparisons return true because person3 is just another reference pointing to the same object as person1.</p><h3>Key Takeaways</h3><ol><li><strong>Use </strong><strong>== for Reference Comparison</strong>: Use == when you want to check if two references point to the same object in memory.</li><li><strong>Use </strong><strong>equals() for Value Comparison</strong>: Use equals() when you want to compare the actual content of the objects. Just remember to override it appropriately in your classes!</li><li><strong>Don’t Forget About Null</strong>: Always be cautious when using equals(). It’s a good practice to check if the object being compared is null to avoid a NullPointerException.</li><li><strong>Consistency Matters</strong>: If you override equals(), you should also consider overriding hashCode() to maintain the general contract for the hashCode method, especially if you plan to use your objects in collections like HashMap or HashSet.</li></ol><h3>Conclusion</h3><p>And there you have it! The next time you’re comparing objects in Java, remember the fundamental differences between == and equals(). Understanding these concepts not only helps in writing better code but also saves you from potential bugs that can arise from incorrect comparisons.</p><p>If you found this post helpful or have your own stories about == and equals(), feel free to share in the comments below! Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb24b915381e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DSA — day1: time complexity]]></title>
            <link>https://medium.com/@lightWonders/dsa-day1-time-complexity-a07b0f03f27c?source=rss-710814ed49b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a07b0f03f27c</guid>
            <category><![CDATA[time-complexity]]></category>
            <category><![CDATA[dsa-training]]></category>
            <dc:creator><![CDATA[sainath]]></dc:creator>
            <pubDate>Thu, 23 May 2024 10:33:15 GMT</pubDate>
            <atom:updated>2024-05-23T10:33:15.321Z</atom:updated>
            <content:encoded><![CDATA[<h3>DSA — day1: time complexity</h3><p><strong>What is time Complexity?</strong></p><p>It is easy to code a solution, but in order for the code to efficient it is important for an algorithm to take less time. It is how much time the algorithm will use for some input .The time complexity of an algorithm estimates how much time the algorithm will use for some input. The idea is to represent the efficiency as a function whose parameter is the size of the input. By calculating the time complexity, we can find out whether the algorithm is fast enough without implementing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*b6TisvmPxnd_2MU8DN1o6Q.jpeg" /></figure><p><strong>Calculation Rules</strong></p><p>It is generally represented as big O(...) dots represents some function</p><p>Common reason why algorithms are slow mainly because of loops</p><p>more loops means more slower</p><pre>for(int i =0 ;i &lt; n; i++){<br>//some logic <br>}</pre><p>the Above loops executes for n times so time complexity is O(n). Same if there are two loops like below time complexity is O(n²)</p><pre>for(int i =0 ;i &lt; n; i++)    {<br>       for(int j=0; j&lt; n; j++)       {<br>          //some logic<br>          }<br>}</pre><blockquote>it is not necessarily the number of times the code executes but the rather the order of magnitude means the below code executes for 3 times the n but still the time complexity is O(n) only.</blockquote><pre>for(int i =0 ;i &lt; 3n; i++){<br>//some logic <br>}</pre><p><strong>Suppose if code contains multiple loops then what is the time complexity ?</strong></p><pre>void function() {<br><br>for(int i =0 ;i &lt; n; i++){<br>//some logic <br>}<br><br><br>for(int i =0 ;i &lt; n; i++)    {<br>       for(int j=0; j&lt; n; j++) {<br>          //some logic<br>   }<br>}<br><br>for(int i =0 ;i &lt; n; i++){<br>      //some logic <br>}<br>}</pre><p>In the above snippet there are 3 loops in same function but time complexity is highest of all the loops which is O(n²)</p><p>There are many different time complexities which we can talk about in later in the series will discuss about recurrsion,estimating efficiency of different time complexities,Complexity classes and few example.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a07b0f03f27c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>