🚀 Day 85 of #100DaysOfCode Today I practiced a simple yet useful array prefix minimum problem. 🔹 Problem Given an array cost, return a new array where each element represents the minimum cost encountered from the start up to that index. 🔹 Approach I used a running minimum technique: Maintain a variable min to track the smallest value seen so far. Traverse the array. Update min using Math.min(min, cost[i]). Store the current minimum in the result array. 🔹 Time Complexity ⏱ O(n) – Single pass through the array. 🔹 Space Complexity 📦 O(n) – For storing the result array. 🔹 Key Learning This is a classic prefix computation pattern where we keep track of information while traversing the array. #DSA #Java #Programming #CodingJourney #100DaysOfCode #SoftwareEngineering
Array Prefix Minimum Problem Solution in Java
More Relevant Posts
-
🚀 Day - 24/100 : 📌 Problem : Binary Number with Alternating Bits 🔗 Problem Link : https://lnkd.in/gCDJXjEK 💡 Approach The goal is to check whether adjacent bits in the binary representation are different (i.e., 101010... pattern). Extract the last bit of the number using n & 1. Right shift the number using n >> 1 to move to the next bit. Again extract the next bit using n & 1. Compare the two bits: If they are equal, the number does not have alternating bits → return false. Continue this process until all bits are checked. If no two adjacent bits are the same, return true. #100DaysOfLeetCode #LeetCode #DSAWithKunal #Algorithms #Java #BitManipulation #CodingPractice #ProblemSolving #DeveloperJourney #Programming
To view or add a comment, sign in
-
-
🚀 Day 59 of #100DaysOfCode 📌 Solved: Pascal’s Triangle (LeetCode 118) Today’s problem was all about patterns and building logic step by step. 🔍 Problem Summary: Given an integer numRows, generate the first numRows of Pascal’s Triangle. 💡 Approach: Start with the first row [1] Each row is built using the previous row First and last elements are always 1 Middle elements = sum of two elements from the previous row 🧠 Key Learning: Understanding how previous computations help build the next result is a powerful concept (Dynamic Programming basics). 📈 Complexity: Time: O(n²) Space: O(n²) ✨ Takeaway: Simple problems often hide powerful concepts. Pascal’s Triangle is a great intro to dynamic programming patterns. 🔥 Follow my journey as I solve DSA daily! #DSA #LeetCode #Python #CodingJourney #100DaysOfCode #Programming #Developers
To view or add a comment, sign in
-
-
Day 25 of Programming Today, I focused on solving problems related to index finding and subsequences — two important concepts that sharpen problem-solving and string manipulation skills. 💡 What I learned: How to find the index of a specific character (k) in a string Understanding first occurrence vs last occurrence Exploring subsequences and how they differ from substrings Generating all possible subsequences using recursion ✨ Key Concepts: Indexing helps in efficient searching within strings A subsequence maintains order but doesn’t require continuity Recursive thinking makes complex problems easier to break down 🧠 Problems I solved: Find the first and last index of a character in a string Count how many times a character appears Check if one string is a subsequence of another Generate all subsequences of a given string Find the longest subsequence under given conditions #Programming #CodingJourney #ProblemSolving #Java #Learning
To view or add a comment, sign in
-
-
Day 12 of Consistency 🚀 Today I focused on understanding Time and Space Complexity, which is a fundamental concept in Data Structures and Algorithms. Learned how to analyze the efficiency of an algorithm and why optimizing code is important as input size grows. Understanding complexity helps in writing better and more efficient solutions. Step by step improving my problem-solving mindset. 💻📚 #Day12 #DSA #TimeComplexity #Java #Programming #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
My Learning Journey – Arrays in Java Today, I explored one of the most important concepts in programming – Arrays 💻 🔹 What I learned: ✔️ What is an array and why we use it ✔️ How to declare and initialize arrays ✔️ Accessing elements using index ✔️ Traversing arrays using loops ✔️ Basic programs using arrays 💡 Key takeaway: Arrays help us store multiple values in a single variable, making code more efficient and organized. 📌 Example: int[] numbers = {10, 20, 30, 40}; This small concept is the foundation for advanced topics like Data Structures and Algorithms. 🔥 Step by step, improving every day! #Java #Arrays #CodingJourney #Learning #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
Day 20 of Programming – Rearranging Programs Today I practiced array rearrangement problems, which are very useful for improving logic building and problem-solving skills. Rearranging elements in an array helps in understanding index manipulation, swapping techniques, and efficient iteration. 🔹 What I learned today: ✅ Rearranging elements based on conditions ✅ Using loops and swapping techniques ✅ Improving array manipulation skills ✅ Writing optimized solutions 🔹 Practice Problems I Worked On: • Rearrange array in ascending and descending order • Rearrange array so positive and negative numbers alternate • Move all zeros to the end of the array • Rearrange elements so that even numbers come before odd numbers • Reverse an array using swapping technique #Programming #Java #Arrays #ProblemSolving #CodingJourney #Developer #LearningToCode
To view or add a comment, sign in
-
-
Understanding Data Structures and Object-Oriented Programming is essential for every Computer Science student. To help with that, I created two full playlists covering these topics step by step. 📊 23 lectures ⏱️ 13+ hours of content 💻 Real explanations and examples Playlists: Data Structure: https://lnkd.in/gMmXdBN4 OOP1 (JAVA) : https://lnkd.in/gnpDnjEE If you're learning these topics, feel free to check them out. Feedback and suggestions are always welcome! #ComputerScience #DataStructures #OOP #ACS
To view or add a comment, sign in
-
🚀 Day 7 of #100DaysOfDSA 🔍 Problem: Valid Anagram (LeetCode 242) Today I solved a classic string problem — checking whether two strings are anagrams. 💡 Key Idea: Instead of sorting (O(n log n)), I used a frequency count approach (O(n)). 👉 Logic: Create an array of size 26 (for a–z) Traverse both strings together Increase count for s, decrease for t If all values become 0 → strings are anagrams ✅ 🧠 Why it works: Same characters with same frequency cancel each other out. ⏱️ Complexity: Time: O(n) Space: O(1) : Always think about optimizing from brute force (O(n²)) to optimal (O(n)). #DSA #Java #Coding #LeetCode #Programming #SoftwareEngineering 🍁 Saidhanya Sree
To view or add a comment, sign in
-
-
🚀 Day 47 of DSA Problem: Longest Palindromic Substring A palindrome reads the same forward and backward. The challenge was to find the longest such substring inside a given string. 💡 Key Idea: Expand around each character (center) and check both odd and even length palindromes. ⏱ Time Complexity: O(n²) 💾 Space Complexity: O(1) This problem reinforced how choosing the right approach can drastically reduce complexity compared to brute force solutions. Consistent practice is sharpening my problem-solving skills step by step. 💪 #DSA #Java #CodingPractice #LeetCode #Programming #ProblemSolving
To view or add a comment, sign in
-
-
Day 31 - Examination methods in Deque 1) getFirst( ) : Retrieves, but what doesn't remove the first element. 2) getLast( ) : Retrieves, but does not remove the last element 3) peekFirst( ) : Retrieves, but does not remove the first element or return if empty null if empty. 4) peekLast( ) : Retrieves, but does not remove the last element or returns nullif empty. ● Stack methods: 1) push( ) : Adds an element at the first. 2) pop ( ) : Removes and returns the first element. #Java #Programming #coding #learning #Corejava EchoBrains
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