Day 19 -What I Learned In a Day(JAVA) Today I practiced Type Casting and Dynamic Input (User Input) in Java Type Casting: I solved problems based on: ✔ Widening Casting (automatic conversion) ✔ Narrowing Casting (manual conversion) ✔ Handling data loss ✔ Applying casting in expressions Practicing problems helped me understand the concept clearly. Dynamic Read (User Input in Java): I learned the 3 important steps to use dynamic input: 1️⃣ Import Scanner class 2️⃣ Create Scanner object 3️⃣ Use input methods Input Methods I Practiced: ✔ nextInt() → for integer ✔ nextDouble() → for decimal numbers ✔ next() → for single word ✔ nextLine() → for full sentence ✔ next().charAt(0) → for character input ✔ nextFloat() → for float values ✔ nextLong() → for long values Practiced 👇 #Java #CoreJava #TypeCasting #LearningJourney #Consistency
More Relevant Posts
-
Day 41 - Find Pivot Index Solved using a prefix sum approach. First computed the total sum of the array, then traversed once while maintaining a running left sum. For each index, the right sum is calculated using total - left - nums[i]. If both sums match, that index is the pivot. Time Complexity: O(n) #Day41 #LeetCode #Java #PrefixSum #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Problem || Minimum Changes To Make Alternating Binary String (1758)🚀 Binary String. 🔹 Problem Summary: Given a binary string s containing only 0 and 1, we need to find the minimum number of changes required to make the string alternating (no two adjacent characters should be the same). Example of valid alternating strings: 0101, 1010 🔹 Key Idea: An alternating string can only have two possible patterns: 1️⃣ Starting with 0 → 010101... 2️⃣ Starting with 1 → 101010... So the approach is: Count mismatches if the string follows pattern 0101... Count mismatches if the string follows pattern 1010... The minimum of the two counts is the answer Time Complexity:O(n) Space Complexity:O(1) #LeetCode #DSA #Java #ProblemSolving #CodingPractice
To view or add a comment, sign in
-
-
Day 21/100: String Compression & Memory 📦 Today I tackled String Compression in Java (e.g., "aaabb" -> "a3b2"). The Goal: Compress a string by counting repeated characters. Example:"aaabbc" becomes "a3b2c1". If the compressed string isn't actually shorter, return the original. Key Learning: StringBuilder vs. String In Java, strings are immutable. If you add to a string in a loop, Java creates a new object every single time. To fix this, I used **StringBuilder**, which is much faster and memory-efficient for building long strings. The Strategy: 1️⃣ Iterate through the string once. 2️⃣ Keep a running count of identical consecutive characters. 3️⃣ Append the character and count to the builder. Simple logic, big performance difference. 🚀 #100DaysOfCode #Java #DSA #Strings #Optimization #Unit2 #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 39 of #100DaysOfCode Solved 80. Remove Duplicates from Sorted Array II on LeetCode 🔢 🧠 Key Insight: The array is already sorted, and we need to ensure that each element appears at most twice, modifying the array in-place. ⚙️ Approach: 🔹Maintain a pointer i representing the position to place the next valid element 🔹Start iterating from index 2 🔹For each element nums[j], compare it with nums[i] 🔹If they are different, place the element at nums[i + 2] and move the pointer forward This ensures that no element appears more than twice while maintaining the sorted order. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #Arrays #TwoPointers #Java #ProblemSolving #InterviewPrep #LearningInPublic
To view or add a comment, sign in
-
-
Day 36 — LeetCode Progress (Java) Problem: Merge Sorted Array Required: Merge nums2 into nums1 so that nums1 becomes a single sorted array. Idea: Fill the zero positions in nums1 with elements from nums2, then sort the entire array. Approach: Initialize index pointer for nums2. Traverse nums1. Whenever a zero is found and elements remain in nums2, replace it with nums2 element. After inserting all elements, sort nums1. Time Complexity: O((m + n) log(m + n)) Space Complexity: O(1) Note: This solution works but is not the optimal approach. A more efficient method can reduce the time complexity to linear time by avoiding the final sort. #LeetCode #DSA #Java #Arrays #Sorting #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 DSA Consistency – Day 54 Solved “Check if Binary String Has at Most One Segment of Ones” on LeetCode. The task is to determine whether a binary string contains at most one contiguous block of 1s. Example: 1100111 → ❌ False (two segments of 1s) 111000 → ✅ True (only one segment) 🔹 Approach 1: Traverse the String Idea: While traversing the string, once we encounter a 0, no 1 should appear afterward. If 1 appears again, it means a second segment of ones has started. 🔹 Approach 2: String Pattern Check A binary string with only one segment of 1s should never contain "01" followed by another 1. So, we simply check for the pattern "01". Both the approaches have same complexities: Time Complexity: O(n) Space Complexity: O(1) #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 51 — LeetCode Progress (Java) Problem: Range Sum Query 2D – Immutable Required: Given a 2D matrix, efficiently return the sum of elements inside a rectangular region defined by (row1, col1) to (row2, col2). Idea: Extend the concept of prefix sums to 2D to handle area-based queries efficiently. Approach: Create a 2D prefix sum matrix sumMat of size (rows + 1) x (cols + 1). Build it using: sumMat[r+1][c+1] = matrix[r][c] + sumMat[r][c+1] + sumMat[r+1][c] - sumMat[r][c] Each cell stores the sum of the rectangle from (0,0) to (r,c). For each query sumRegion(row1, col1, row2, col2): sum = sumMat[row2+1][col2+1] - sumMat[row1][col2+1] - sumMat[row2+1][col1] + sumMat[row1][col1] Time Complexity: Preprocessing: O(n × m) Query: O(1) Space Complexity: O(n × m) #LeetCode #DSA #Java #PrefixSum #2DPrefixSum #Algorithms #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🧠 Day 168 — Alternating Binary String 🔁⚡ Today solved a clean string pattern problem: Minimum Changes to Make Alternating Binary String. 📌 Problem Goal Given a binary string, determine the minimum number of flips needed to make it alternating. Valid alternating patterns can only be: 010101... 101010... So the trick is simply to check both possibilities. 🔹 Approach ✔️ Traverse the string once ✔️ Count mismatches assuming pattern 0101... ✔️ Count mismatches assuming pattern 1010... ✔️ Return the minimum of the two counts 🧠 Key Learning ✔️ Many string problems reduce to pattern validation ✔️ Always check all possible valid patterns ✔️ Simple logic + observation can replace complex algorithms Sometimes the easiest problems still sharpen thinking. 🚀 Momentum Status: Consistency intact. Small problems, clear logic, steady progress. On to Day 169. #DSA #Strings #LeetCode #ProblemSolving #CodingJourney #Java #ConsistencyWins
To view or add a comment, sign in
-
-
Day 31/75 — Sum of Two Integers (Without + or -) Today's problem was about performing addition using bit manipulation. Key idea: • XOR (^) gives sum without carry • AND (&) + left shift gives carry Algorithm: while (b != 0): carry = (a & b) << 1 a = a ^ b b = carry Repeat until carry becomes zero. Time Complexity: O(1) Space Complexity: O(1) This problem gave a deeper understanding of how addition works at the binary level. 31/75 🚀 #Day31 #DSA #BitManipulation #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
🚀 Day 18/100 – Find the Difference of Two Arrays. Today I solved the problem Find the Difference of Two Arrays. 🔹 Problem: Given two integer arrays nums1 and nums2, return a list of two lists: Elements present in nums1 but not in nums2 Elements present in nums2 but not in nums1 Example: Input: nums1 = [1,2,3] nums2 = [2,4,6] Output: [[1,3], [4,6]]. 🧠 Approach: 1️⃣ First convert both arrays into HashSet to remove duplicates and allow fast lookup. 2️⃣ Traverse set1 If an element is not present in set2, add it to result list a. 3️⃣ Traverse set2 If an element is not present in set1, add it to result list b. 4️⃣ Return both lists as result. HashSet helps because checking presence takes O(1) time. ⏱ Time Complexity Creating sets → O(n + m) Checking elements → O(n + m) ✅ Overall Time Complexity: O(n + m) ✅ Space Complexity: O(n + m). ✨ What I Learned: How to use HashSet to remove duplicate elements from arrays. How HashSet provides O(1) lookup time, making comparisons faster. How to find unique elements between two arrays efficiently. Improved understanding of Set operations and array traversal in Java. #Day18 #100DaysOfCode #LeetCode #Java #DSA #Consistency
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