🚀 Day 94 -#100DaysOfCode Today I worked on a problem that looks simple at first but really tests your understanding of indexing and conditions. 💡 Problem Insight: Given an array, we need to calculate the sum of squares of elements whose indices (1-based) divide the length of the array. 🧠 Key Learning: Always be careful with 1-based vs 0-based indexing The condition n % i == 0 ensures we only pick valid positions Accessing elements correctly using nums[i-1] is crucial ⚡ What I Improved Today: Better understanding of index manipulation Writing cleaner loops with proper conditions Avoiding off-by-one errors #Day94 #CodingJourney #Java #DSA #LeetCode #Consistency #ProblemSolving
Java Array Sum of Squares by Index
More Relevant Posts
-
🚀 Day 46/100 Today I worked on an interesting problem: Shuffle String 💡 Problem Understanding: Given a string and an indices array, the task is to rearrange the characters so that each character moves to its specified position, forming a new string. 🧠 Approach: Used a simple mapping idea — place each character directly at its correct index. ✨ Key Learnings: - Mapping-based problems become easy with a clear approach - Direct placement helps keep the solution efficient - Avoiding unnecessary loops improves performance 📈 Learning something new every day and getting better step by step! #Day46 #DSA #CodingJourney #ProblemSolving #Java #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 58 of #100DaysOfCode Solved – Check Balanced String 🔍 What I did: Traversed the string and calculated the sum of digits at even and odd indices separately, then compared both sums to determine if the string is balanced. 💡 Key Learning: Practiced string traversal and indexing Improved understanding of even vs odd index logic Learned how to convert char to integer (c - '0') 🎯 Takeaway: Even simple index-based problems can strengthen your fundamentals and attention to detail. #Day58 #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
LeetCode Day 45 Today I solved the Contains Duplicate problem. Problem Insight: Given an integer array, we need to check whether any element appears more than once. Approach: Sorted the array first Compared adjacent elements If two consecutive elements are equal → duplicate found Key Learning: Sorting helps bring duplicates together, making it easy to detect them with a single pass. Complexity: Time: O(n log n) Space: O(1) Consistency builds confidence — Day 45 done! #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
Day 75/200 – LeetCode Challenge Given a string of digits, the task is to generate all possible valid IP addresses by inserting dots. Sounds simple, but the challenge lies in handling. Try placing dots at every possible position. Validate each segment before moving forward. Prune invalid paths early to save time. Backtracking becomes powerful when combined with early pruning. Instead of exploring all possibilities, we cut off invalid paths immediately, making the solution efficient. Problems like this strengthen recursion + validation thinking. The more you practice, the better you get at spotting patterns. #Day75 #LeetCode #CodingChallenge #Java #200DaysOfCode
To view or add a comment, sign in
-
-
Day: 96/365 📌 LeetCode POTD: Minimum Distance to Type a Word Using Two Fingers Hard Key takeaways/Learnings from this problem: 1. This problem is a great example of DP with state as both fingers’ positions, which feels tricky at first but clicks once you model it right. 2. Key learning: instead of deciding both fingers every time, fix one and optimize the movement of the other to reduce complexity. 3. Precomputing distances between characters makes transitions much faster and keeps the code clean. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
🚀 #60DaysOfLeetCode – Day 32 Today’s problem was about removing all adjacent duplicates in a string. 🔹 Approach Used: Stack To efficiently handle consecutive duplicates, I used a stack-based approach: Traverse the string character by character. If the stack is not empty and the top element matches the current character, pop it (this removes the duplicate pair). Otherwise, push the current character onto the stack. Finally, build the result string from the stack and reverse it to maintain the correct order. 🔹 Key Learning: Using a stack helps simulate the process of removing adjacent duplicates in a single pass, achieving O(n) time complexity and avoiding unnecessary reprocessing. This problem highlights how stacks are powerful for handling sequential patterns and cancellations, especially in string manipulation problems. On to Day 33! 💻🔥 #LeetCode #DSA #Java #CodingChallenge #ProblemSolving #LearningInPublic #60DaysOfCode
To view or add a comment, sign in
-
-
100 Days of Code Day - 24 🔁 Swap Nodes in Pairs – LeetCode Problem Solved a classic Linked List problem today! 💡 👉 Given a linked list, swap every two adjacent nodes without modifying values — only changing the links. ✅ Example: Input: [1,2,3,4] Output: [2,1,4,3] 💭 Approach: Used a dummy node and pointer manipulation to efficiently swap nodes in O(n) time and O(1) space. 📌 Key Learning: Understanding pointer handling is crucial for mastering Linked Lists. #LeetCode #Java #DSA #LinkedList #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 63 of #LeetCode Practice Solved: Count Equal and Divisible Pairs in an Array (Easy) 🔹 Problem Summary: Given an array and an integer k, find the number of pairs (i, j) such that: • nums[i] == nums[j] • (i * j) is divisible by k 🔹 Approach: • Used two nested loops to check all pairs • Compared elements to find equal values • Checked if (i * j) % k == 0 • Counted valid pairs 🔹 Key Learning: Brute-force helps build a strong foundation and improves problem understanding before optimization. 💡 Consistency, patience, and small daily improvements lead to big results over time. #LeetCode #DSA #Java #CodingJourney #Consistency #KeepLearning
To view or add a comment, sign in
-
-
🚀 Day 11 of #100DaysOfCode Solved LeetCode Problem #27 – Remove Element today! 💻 🔹 Approach: Used the Two Pointer Technique One pointer (i) iterates through the array Another pointer (ptr) keeps track of valid elements If nums[i] != val, assign it to nums[ptr] and increment ptr 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) 💡 Key Learning: In-place array modification using two pointers helps optimize space and improves efficiency. 📌 Consistency is the key — one step closer every day! #LeetCode #DSA #Java #CodingJourney #Day11 #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 21 of my #100DaysOfCode Journey Today, I solved the LeetCode question Contains Duplicate II. The task is to check if there are two equal elements in the array such that their index difference is at most k. ✅ Steps: First, iterate through each element in the array For every element, check only the next k elements Compare values within this limited range If a match is found → return true 💻 My Approach: I used a sliding window + brute force approach (without using HashMap/HashSet). Instead of checking the whole array, I optimized it by limiting the inner loop to k distance only. 🌟 Learning Takeaways: Optimizing brute force can avoid TLE Understanding constraints (like k distance) helps reduce complexity Multiple approaches exist — choosing based on space/time is key #DSA #Java #LeetCode #CodingJourney #100DaysOfCode
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