23/30 days✅ Solved LeetCode Problem : #70 – Climbing Stairs The challenge was to determine how many distinct ways one can reach the top of a staircase with n steps, where at each step you can either climb 1 or 2 steps. The logic behind the problem is similar to the Fibonacci sequence, where each state depends on the sum of the previous two states. I implemented the solution in Java, using an iterative approach with three variables to optimize space complexity. Instead of using recursion or an array, the approach updates values in constant space (O(1)) while maintaining linear time complexity (O(n)). Here’s the logic in brief: Initialize a = 0, b = 1, and c = 1. For each step, compute c = a + b, then shift values forward (a = b, b = c). Return c as the total number of distinct ways to reach the top. #LeetCode #Java #DynamicProgramming #ProblemSolving #CodingJourney
Jayashree M’s Post
More Relevant Posts
-
✅Day 50 : Leetcode 1283 - Find the Smallest Divisor Given a Threshold #60DayOfLeetcodeChallenge 🧩 Problem Statement: Given an array of integers nums and an integer threshold, find the smallest positive integer divisor such that the sum of each element divided by the divisor (rounded up to the nearest integer) is less than or equal to the threshold. 💡 My Approach: Binary Search on Divisor Range: The smallest possible divisor is 1. The largest possible divisor is the maximum element in nums. Check Function: For a given divisor, calculate the sum of ceil(nums[i] / divisor) for all elements. If the total sum ≤ threshold → we can try smaller divisors. Otherwise, increase the divisor. Repeat until optimal divisor is found. ⏱️ Time Complexity: O(n * log(max(nums))) Each binary search iteration takes O(n) to compute the sum. #Algorithms #BinarySearch #LeetCode #Java #ProblemSolving #DSA #100DaysOfCode #CodeNewbie
To view or add a comment, sign in
-
-
📌 Day 2/100 – Remove Element (LeetCode 27) 🔹 Problem: Given an integer array nums and a value val, remove all instances of that value in-place and return the new length of the array. The order of elements can be changed. 🔹 Approach: Used the two-pointer technique to efficiently modify the array in-place. One pointer iterates through the array, while the other tracks the position to overwrite non-val elements. Returned the position of the second pointer as the new length. 🔹 Key Learning: Strengthened understanding of in-place array manipulation. Improved logic building for pointer movement and conditional overwriting. Learned how to minimize extra space usage while maintaining readability and clarity. Another small yet powerful step toward mastering array-based problems! 💻 🔥 #100DaysOfCode #LeetCode #Java #ProblemSolving #TwoPointers #DSA #CodingJourney
To view or add a comment, sign in
-
-
🎯 LeetCode Day 41/50 – Pascal’s Triangle Today’s challenge was about generating Pascal’s Triangle — a classic combinatorial structure where each number is the sum of the two numbers directly above it. 🔺 💡 Concepts used: Recursion to build rows step-by-step Dynamic List handling in Java Base case optimization for smaller triangles 🧩 Key insight: Each row can be constructed from the previous one by summing adjacent elements — a beautiful recursive pattern that reflects mathematical simplicity. 🕒 Runtime: 1 ms (Beats 85.89%) ⚡ 💾 Memory: 42.20 MB (Beats 26.63%) ✅ Result: 30/30 test cases passed — Accepted 🎉 #LeetCode #50DaysOfCode #Java #CodingChallenge #ProblemSolving #PascalTriangle
To view or add a comment, sign in
-
-
💡 LeetCode #15 — 3Sum Today I solved LeetCode Problem 15: 3Sum 🔍 Problem Summary: Given an integer array nums, return all unique triplets (a, b, c) such that: a + b + c = 0 The solution must not contain duplicate triplets. Key Idea: Use sorting + two pointers to reduce the time from O(n³) to O(n²). Steps: Sort the array. Fix one number (nums[f]) in each iteration. Use two pointers (i and j) to find pairs whose sum equals -nums[f]. Skip duplicates for both the fixed index and the pointer values. This efficiently finds all unique triplets. #LeetCode #Java #DSA #TwoPointers #ProblemSolving #CodingChallenge #Algorithms
To view or add a comment, sign in
-
-
🌟 Day 94 of 100 Days of Code 🌟 Today’s challenge: Maximum Number of Operations to Move Ones to the End (LeetCode 3228) 💡 🧠 Problem: Given a binary string, you can repeatedly move '1' to the right (until it meets another '1' or the end). The goal is to find the maximum number of such operations possible. ⚙️ Approach: Traverse the string once. Track the count of '1's and increment operations based on '10' patterns. Efficient O(n) solution using simple logic and character comparisons. ✅ Result: ✔️ All test cases passed ⚡ Runtime: 7 ms — Beats 78.52% of Java submissions #100DaysOfCode #Day94 #LeetCode #Java #ProblemSolving #CodingJourney #DataStructures #Algorithms #CodeEveryday
To view or add a comment, sign in
-
-
📌 Day 16/100 - Reverse String (LeetCode 344) 🔹 Problem: Reverse a given string in-place — meaning you must modify the original array of characters without using extra space. 🔹 Approach: Used the two-pointer technique — one starting at the beginning and one at the end of the array. Swap characters at both pointers, then move them closer until they meet. Efficient, clean, and runs in linear time without additional memory allocation. 🔹 Key Learnings: In-place algorithms optimize space complexity significantly. The two-pointer pattern is a versatile tool for many array and string problems. Understanding mutable vs immutable structures in Java is crucial for memory efficiency. Sometimes, the simplest logic beats the most complex one. 🧠 “True efficiency lies in simplicity, not complexity.” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #TwoPointers
To view or add a comment, sign in
-
-
📌 Day 13/100 - Valid Anagram (LeetCode 242) 🔹 Problem: Given two strings s and t, determine whether t is an anagram of s. An anagram is formed by rearranging the letters of one word to create another word — meaning both strings must have the same characters with the same frequency. 🔹 Approach: First, check if both strings are of equal length — if not, they can’t be anagrams. Convert both strings into character arrays. Sort both arrays and compare them using Arrays.equals(). If both sorted arrays are identical, the strings are anagrams. 🔹 Key Learning: Sorting can simplify comparison-based string problems. Always check base conditions (like length) to avoid unnecessary computation. This approach has a time complexity of O(n log n) due to sorting, which is efficient enough for this problem. Every solved challenge is another letter added to the dictionary of progress! 🚀 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
💡 LeetCode #167 — Two Sum II (Input Array Is Sorted) Today I solved LeetCode Problem 167: Two Sum II — Input Array Is Sorted 🎯 Problem Summary: You are given a sorted array and a target. Return the 1-indexed positions of the two numbers that add up to the target. You must use O(1) extra space. Key Idea: Use the two-pointer technique 👈👉 Start with one pointer at the beginning (left) and one at the end (right). If the sum is too large → move right leftward. If the sum is too small → move left rightward. Stop when you find the pair. This works because the array is already sorted. #LeetCode #Java #DSA #TwoPointers #Algorithms #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
LeetCode Question #199 — Binary Tree Right Side View Thrilled to share another Accepted Solution (100% Runtime 🚀) on LeetCode! This problem focuses on Binary Trees — specifically, how to capture the view of a tree from its right side 🌳➡️. I implemented a Modified Pre-Order Traversal (Root → Right → Left) in Java, ensuring that the first node at each level (from the right) gets recorded. 💡 Key Idea: Use recursion with a level tracker — when the current level equals the list size, it means we’re seeing the rightmost node for the first time. Here’s the performance snapshot: ⚙️ Runtime: 0 ms (Beats 100% of Java submissions) 💾 Memory: 42.4 MB Every problem like this sharpens my understanding of tree traversal patterns and depth-first search optimization. #LeetCode #Java #DataStructures #BinaryTree #ProblemSolving #CodingJourney #DSA #100PercentRuntime
To view or add a comment, sign in
-
-
🚀Day 38/100 - Problem of the day :- Ones and Zeros. 🎯 Goal Solve the “Ones and Zeroes” problem using Dynamic Programming by selecting the maximum number of binary strings within the constraints of m zeroes and n ones. 💡 Core Idea Convert each string into its count of zeroes and ones, then use a 2D DP array where dp[i][j] tells the maximum number of strings that can be formed with i zeroes and j ones. Iterate in reverse to avoid overwriting states, updating DP for each string. 📌 Key Takeaway This problem shows how DP shines when choices are constrained by multiple resource limits. Turning strings into (zero, one) pairs and applying knapsack logic simplifies the solution beautifully. 📄 Space Complexity O(m × n) ⏱️Time Complexity O(k × m × n) where k is the number of strings #100DaysChallenge #Java #DataStructure #Day38 #Leetcode #ProblemSolving #CodingJourney
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